public NakedObject invoke() { return action.execute(target, parameters); }
outer: for (int i = 0; i < availableActions.length; i++) { final NakedObjectAction action = availableActions[i]; if (action.getActions().length > 0) { final NakedObjectAction a = getAction(action.getActions(), type, actionName, parameters); if (a != null) { return a; if (!action.getType().equals(type)) { continue outer; if (actionName != null && !actionName.equals(action.getId())) { continue outer; if (action.getParameters().length != parameters.length) { continue outer; if (!parameters[j].isOfType(action.getParameters()[j].getSpecification())) { continue outer;
private Consent canDropOntoObject(final NakedObject target, final NakedObject source) { final NakedObjectAction action = dropAction(source, target); if (action != null) { final Consent parameterSetValid = action.isProposedArgumentSetValid(target, new NakedObject[] { source }); parameterSetValid.setDescription("Execute '" + action.getName() + "' with " + source.titleString()); return parameterSetValid; } else { return setFieldOfMatchingType(target, source); } }
public boolean collectParameters() { // TODO use new promptForParameters method instead of all this final int expectedNoParameters = action.isContributed() ? 1 : 0; return action.getParameterCount() == expectedNoParameters; } }
private NakedObjectAction getAction2( final NakedObjectAction[] availableActions, final NakedObjectActionType type, final String nameParmsIdentityString) { if (nameParmsIdentityString == null) { return null; } outer: for (int i = 0; i < availableActions.length; i++) { final NakedObjectAction action = availableActions[i]; if (action.getActions().length > 0) { // deal with action set final NakedObjectAction a = getAction2(action.getActions(), type, nameParmsIdentityString); if (a != null) { return a; } } else { // regular action if (!sameActionTypeOrNotSpecified(type, action)) { continue outer; } if (!nameParmsIdentityString.equals(action.getIdentifier().toNameParmsIdentityString())) { continue outer; } return action; } } return null; }
for (int j = 0; j < actions.length; j++) { final NakedObjectAction action = actions[j]; final String name = action.getName(); Component menuItem = null; if (action.getActions().length > 0) { final Component[] components = createMenu(name, target, action.getActions(), context, targetObjectId); menuItem = context.getComponentFactory().createSubmenu(name, components); } else { if (!action.isVisible(NakedObjectsContext.getAuthenticationSession(), target).isAllowed()) { continue; if (action.getType() == NakedObjectActionConstants.USER) { } else if (action.getType() == NakedObjectActionConstants.EXPLORATION) { if (SessionAccess.inExplorationMode()) { } else if (action.getType() == NakedObjectActionConstants.DEBUG) { if (action.getParameterCount() == 0) { collectParameters = false; } else if (action.getParameterCount() == 1 && action.isContributed() && target.getSpecification().isOfType(action.getParameters()[0].getSpecification())) { collectParameters = false; } else { collectParameters = true; final Consent consent = action.isUsable(NakedObjectsContext.getAuthenticationSession(), target); final String consentReason = consent.getReason();
private static void actionDetails(final DebugString debug, final NakedObjectAction a, final int indent, final int count) { debug.appendln((count + 1) + "." + a.getId() + " (" + a.getClass().getName() + ")"); debug.indent(); final int newIndent = indent + 4; try { final NakedObjectAction[] debActions = a.getActions(); if (debActions.length > 0) { for (int i = 0; i < debActions.length; i++) { if (a.getDescription() != null && !a.getDescription().equals("")) { debug.appendln("Description", a.getDescription()); debug.appendln("ID", a.getId()); debug.appendln(a.debugData()); debug.appendln("Target", a.getTarget()); debug.appendln("On type", a.getOnType()); final Class<? extends Facet>[] facets = a.getFacetTypes(); if (facets.length > 0) { debug.appendln("Facets"); debug.indent(); for (int j = 0; j < facets.length; j++) { debug.appendln(a.getFacet(facets[j]).toString()); final NakedObjectSpecification returnType = a.getReturnType(); debug.appendln("Returns", returnType == null ? "VOID" : returnType.toString()); final NakedObjectActionParameter[] parameters = a.getParameters(); if (parameters.length == 0) {
protected MethodTask(final Context context, final NakedObject target, final NakedObjectAction action) { super(context, action.getName(), action.getDescription(), target, action.getParameterCount()); this.action = action; final NakedObjectActionParameter[] parameters = action.getParameters(); final int len = parameters.length; final NakedObject[] defaultParameterValues = action.getDefaults(target); if (action.isContributed()) { initialState[i] = target; } else {
final boolean isContributedMethod = action.isContributed(); if (action.getParameterCount() == 0) { executeImmediately = true; } else if (action.getParameterCount() == 1 && isContributedMethod && target.getSpecification().isOfType(action.getParameters()[0].getSpecification())) { executeImmediately = true; final NakedObject result = action.execute(target, parameters); final MessageBroker broker = NakedObjectsContext.getMessageBroker(); final List<String> messages = broker.getMessages();
private Object handleActionMethod( final Object[] args, final AuthenticationSession session, final NakedObject targetAdapter, final NakedObjectAction noa, final String memberName) { final Object[] underlyingArgs = new Object[args.length]; int i = 0; for (final Object arg : args) { underlyingArgs[i++] = underlying(arg); } final NakedObject[] argAdapters = new NakedObject[underlyingArgs.length]; int j = 0; for (final Object underlyingArg : underlyingArgs) { argAdapters[j++] = underlyingArg!=null?getRuntimeContext().adapterFor(underlyingArg):null; } final InteractionResult interactionResult = noa.isProposedArgumentSetValid(targetAdapter, argAdapters).getInteractionResult(); notifyListenersAndVetoIfRequired(interactionResult); if (getExecutionMode() == ExecutionMode.EXECUTE) { final NakedObject actionReturnNO = noa.execute(targetAdapter, argAdapters); return NakedObjectUtils.unwrap(actionReturnNO); } objectChangedIfRequired(targetAdapter); return null; }
private static void menuOptions(final NakedObjectAction[] actions, final NakedObject target, final UserActionSet menuOptionSet) { for (int i = 0; i < actions.length; i++) { UserAction option = null; if (actions[i].getActions().length > 0) { option = new UserActionSet(actions[i].getName(), menuOptionSet); menuOptions(actions[i].getActions(), target, (UserActionSet) option); } else { final int noOfParameters = actions[i].getParameterCount(); if (noOfParameters == 0) { option = ImmediateObjectOption.createOption(actions[i], target); } else if (actions[i].isContributed() && noOfParameters == 1 && target != null && target.getSpecification().isOfType(actions[i].getParameters()[0].getSpecification())) { option = ImmediateObjectOption.createServiceOption(actions[i], target); } else { option = DialoggedObjectOption.createOption(actions[i], target); } } if (option != null) { menuOptionSet.add(option); } } } }
final NakedObject resultAdapter = action.execute(targetAdapter, parameters); if (action.getParameters()[i].getSpecification().isObject() && parameterData[i] instanceof ObjectData) { persistedParameterData[i] = encoderDecoder.encodeMadePersistentGraph((ObjectData) parameterData[i], parameters[i]);
public static ActionHelper createInstance(final NakedObject target, final NakedObjectAction action) { final int numberParameters = action.getParameterCount(); final NakedObject[] parameters = new NakedObject[numberParameters]; final NakedObjectActionParameter[] parameterSpecs = action.getParameters(); NakedObject[] defaultValues; NakedObject[][] options; defaultValues = action.getDefaults(target); options = action.getChoices(target);
private boolean matchesParameterOf(final NakedObjectAction serviceAction) { final NakedObjectActionParameter[] params = serviceAction.getParameters(); for (int k = 0; k < params.length; k++) { if ( isOfType(params[k].getSpecification())) { return true; } } return false; }
getAuthenticationSession(), NakedObjectActionConstants.USER, nakedObjectAction.getIdentifier().toNameParmsIdentityString(), targetReference, parameterObjectData); final NakedObjectActionParameter[] parameters2 = nakedObjectAction.getParameters(); for (int i = 0; i < parameterAdapters.length; i++) { if (parameters2[i].getSpecification().isObject()) {
@Before public void setUp() throws Exception { BasicConfigurator.configure(); LogManager.getRootLogger().setLevel(Level.OFF); system = new TestProxySystem(); system.init(); mockNakedObjectAction = mockery.mock(NakedObjectAction.class); mockEncoder = mockery.mock(ObjectEncoder.class); mockDistribution = mockery.mock(ServerFacade.class); mockActionInvocationFacet = mockery.mock(ActionInvocationFacet.class); mockFacetHolder = mockery.mock(FacetHolder.class); identifier = Identifier.classIdentifier(""); target = system.createTransientTestObject(); mockery.checking(new Expectations() { { one(mockActionInvocationFacet).getFacetHolder(); will(returnValue(mockFacetHolder)); allowing(mockNakedObjectAction).getIdentifier(); will(returnValue((identifier))); allowing(mockNakedObjectAction).execute(with(equalTo(target)), with(any(NakedObject[].class))); will(returnValue(null)); } }); proxy = new ActionInvocationFacetWrapProxy(mockActionInvocationFacet, mockDistribution, mockEncoder, mockNakedObjectAction); }
public static ImmediateObjectOption createServiceOption(final NakedObjectAction action, final NakedObject object) { Assert.assertTrue("Only suitable for 1 param methods", action.getParameterCount() == 1); if (!action.isVisible(NakedObjectsContext.getAuthenticationSession(), object).isAllowed()) { return null; } final ImmediateObjectOption option = new ImmediateObjectOption(action, object); return option; }
public Consent disabled() { // REVIEW this is no good as it lumps all the parameters together; I need to know which parameter is // disabled! return action.isProposedArgumentSetValid(target, parameters); }
@Override public NakedObjectActionType getType() { return action.getType(); }