View Javadoc

1   package org.starobjects.tested.fitnesse.internal.fixtures.perform;
2   
3   import org.nakedobjects.metamodel.adapter.NakedObject;
4   import org.nakedobjects.metamodel.spec.feature.NakedObjectAction;
5   import org.nakedobjects.metamodel.spec.feature.NakedObjectMember;
6   import org.starobjects.tested.fitnesse.internal.fixtures.UsingNakedObjectsViewer.Mode;
7   
8   import fit.Parse;
9   
10  public class GetActionParameterDefault extends PerformAbstractTypeParams {
11  
12      private NakedObject result;
13  
14      public GetActionParameterDefault(final Mode mode) {
15          super("get action parameter default", Type.ACTION, NumParameters.ONE,
16                  mode);
17      }
18  
19      @Override
20      public void doHandle(final PerformContext performContext) {
21  
22          final NakedObject onAdapter = performContext.getOnAdapter();
23          final NakedObjectMember nakedObjectMember = performContext
24                  .getNakedObjectMember();
25          final Parse arg0Cell = performContext.getArg0Binding().getCurrentCell();
26          int requestedParamNum = -1;
27          try {
28              requestedParamNum = Integer.valueOf(arg0Cell.text());
29          } catch (final NumberFormatException ex) {
30              getOwner().throwException(arg0Cell, ex.getMessage());
31          }
32  
33          final NakedObjectAction noa = (NakedObjectAction) nakedObjectMember;
34          final int parameterCount = noa.getParameterCount();
35          if (requestedParamNum < 0 || requestedParamNum > parameterCount - 1) {
36              getOwner().throwException(arg0Cell,
37                      "(must be between 0 and " + (parameterCount - 1) + ")");
38          }
39  
40          final NakedObject[] defaults = noa.getDefaults(onAdapter);
41          result = defaults[requestedParamNum];
42      }
43  
44      public NakedObject getResult() {
45          return result;
46      }
47  
48  }