public static FacetedMethod createActionFacetedMethod(final Class<?> declaringType, final Method method) { return new FacetedMethod(FeatureType.ACTION, declaringType, method, method.getReturnType(), getParameters(method)); }
@Override public int getParameterCount() { return getFacetedMethod().getParameters().size(); }
@Override public void process(final ProcessMethodContext processMethodContext) { final FacetedMethod facetedMethod = processMethodContext.getFacetHolder(); final List<FacetedMethodParameter> holderList = facetedMethod.getParameters(); attachDefaultFacetForParametersIfDefaultsNumMethodIsFound(processMethodContext, holderList); }
@Override public void process(final ProcessMethodContext processMethodContext) { final FacetedMethod facetedMethod = processMethodContext.getFacetHolder(); final List<FacetedMethodParameter> holderList = facetedMethod.getParameters(); attachMandatoryFacetForParametersIfOptionalMethodIsFound(processMethodContext, holderList); }
@Override public void process(final ProcessMethodContext processMethodContext) { final FacetedMethod facetedMethod = processMethodContext.getFacetHolder(); final List<FacetedMethodParameter> holderList = facetedMethod.getParameters(); attachChoicesFacetForParametersIfChoicesNumMethodIsFound(processMethodContext, holderList); }
@Override public void process(final ProcessMethodContext processMethodContext) { final FacetedMethod facetedMethod = processMethodContext.getFacetHolder(); final List<FacetedMethodParameter> holderList = facetedMethod.getParameters(); attachDescribedAsFacetForParametersIfParameterDescriptionsMethodIsFound(processMethodContext, holderList); }
@Override public void process(final ProcessMethodContext processMethodContext) { final FacetedMethod facetedMethod = processMethodContext.getFacetHolder(); final List<FacetedMethodParameter> holderList = facetedMethod.getParameters(); attachNamedFacetForParametersIfParameterNamesMethodIsFound(processMethodContext, holderList); }
private FacetedMethod createActionFacetedMethod(final Method actionMethod) { if (!isAllParamTypesValid(actionMethod)) { return null; } final FacetedMethod action = FacetedMethod.createActionFacetedMethod(introspectedClass, actionMethod); // process facets on the action & parameters getFacetProcessor().process(introspectedClass, actionMethod, methodRemover, action, FeatureType.ACTION); final List<FacetedMethodParameter> actionParams = action.getParameters(); for (int j = 0; j < actionParams.size(); j++) { getFacetProcessor().processParams(actionMethod, j, actionParams.get(j)); } return action; }
/** * Build lazily by {@link #getParameters()}. * * <p> * Although this is lazily loaded, the method is also <tt>synchronized</tt> * so there shouldn't be any thread race conditions. */ @Override public synchronized List<ObjectActionParameter> getParameters() { if (this.parameters == null) { final int parameterCount = getParameterCount(); final List<ObjectActionParameter> parameters = Lists.newArrayList(); final List<FacetedMethodParameter> paramPeers = getFacetedMethod().getParameters(); for (int i = 0; i < parameterCount; i++) { final TypedHolder paramPeer = paramPeers.get(i); final ObjectSpecification specification = ObjectMemberAbstract.getSpecification(getSpecificationLookup(), paramPeer.getType()); if (specification.isParseable()) { parameters.add(new ObjectActionParameterParseable(i, this, paramPeer)); } else if (specification.isNotCollection()) { parameters.add(new OneToOneActionParameterImpl(i, this, paramPeer)); } else if (specification.isCollection()) { throw new UnknownTypeException("collections not supported as parameters: " + getIdentifier()); } else { throw new UnknownTypeException(specification); } } this.parameters = parameters; } return parameters; }
final Facet facet0 = facetHolderWithParms.getParameters().get(0).getFacet(ActionParameterDefaultsFacet.class); assertNotNull(facet0); assertTrue(facet0 instanceof ActionParameterDefaultsFacetViaMethod); final Facet facet1 = facetHolderWithParms.getParameters().get(1).getFacet(ActionParameterDefaultsFacet.class); assertNotNull(facet1); assertTrue(facet1 instanceof ActionParameterDefaultsFacetViaMethod);
final Facet facet0 = facetHolderWithParms.getParameters().get(0).getFacet(ActionParameterDefaultsFacet.class); assertNotNull(facet0); assertTrue(facet0 instanceof ActionParameterDefaultsFacetViaMethod); final Facet facet1 = facetHolderWithParms.getParameters().get(1).getFacet(ActionParameterDefaultsFacet.class); assertNotNull(facet1); assertTrue(facet1 instanceof ActionParameterDefaultsFacetViaMethod);
final Facet facet0 = facetHolderWithParms.getParameters().get(0).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet0); assertTrue(facet0 instanceof ActionParameterChoicesFacetViaMethod); final Facet facet1 = facetHolderWithParms.getParameters().get(1).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet1); assertTrue(facet1 instanceof ActionParameterChoicesFacetViaMethod);
public void testInstallsParameterAutoCompleteMethodAndRemovesMethod() { final ActionParameterAutoCompleteFacetViaMethodFactory facetFactory = new ActionParameterAutoCompleteFacetViaMethodFactory(); facetFactory.setServicesInjector(mockServicesInjector); // mockSpecificationLoader.setLoadSpecificationStringReturn(voidSpec); allowing_specificationLoader_loadSpecification_any_willReturn(this.voidSpec); class Customer { @SuppressWarnings("unused") public void someAction(final int x, final long y) { } @SuppressWarnings("unused") public List<Integer> autoComplete0SomeAction(String searchArg) { return Collections.emptyList(); } } final Method actionMethod = findMethod(Customer.class, "someAction", new Class[] { int.class, long.class }); final Method autoComplete0Method = findMethod(Customer.class, "autoComplete0SomeAction", new Class[] {String.class}); final FacetedMethod facetHolderWithParms = FacetedMethod.createForAction(Customer.class, actionMethod, mockSpecificationLoader); facetFactory.process(new ProcessMethodContext(Customer.class, null, null, actionMethod, methodRemover, facetHolderWithParms)); final Facet facet0 = facetHolderWithParms.getParameters().get(0).getFacet(ActionParameterAutoCompleteFacet.class); assertNotNull(facet0); assertTrue(facet0 instanceof ActionParameterAutoCompleteFacetViaMethod); final ActionParameterAutoCompleteFacetViaMethod actionAutoCompleteFacetViaMethod0 = (ActionParameterAutoCompleteFacetViaMethod) facet0; assertEquals(autoComplete0Method, actionAutoCompleteFacetViaMethod0.getMethods().get(0)); assertTrue(methodRemover.getRemovedMethodMethodCalls().contains(autoComplete0Method)); }
final Facet facet0 = facetHolderWithParms.getParameters().get(0).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet0); assertTrue(facet0 instanceof ActionParameterChoicesFacetViaMethod); final Facet facet1 = facetHolderWithParms.getParameters().get(1).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet1); assertTrue(facet1 instanceof ActionParameterChoicesFacetViaMethod); final Facet facet2 = facetHolderWithParms.getParameters().get(2).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet2); assertTrue(facet2 instanceof ActionParameterChoicesFacetViaMethod);
returnType = facetedMethod.getType(); final List<FacetedMethodParameter> parameters = facetedMethod.getParameters(); parameterNames = immutableList(Iterables.transform(parameters, FacetedMethodParameter.Functions.GET_NAME)); parameterTypes = immutableList(Iterables.transform(parameters, FacetedMethodParameter.Functions.GET_TYPE));
assertNotNull(facet0); final Facet facet1 = facetHolderWithParms.getParameters().get(0).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet1); assertTrue(facet1 instanceof ActionParameterChoicesFacetViaMethod); assertEquals(choices0Method, actionChoicesFacetViaMethod0.getMethods().get(0)); final Facet facet2 = facetHolderWithParms.getParameters().get(1).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet2); assertTrue(facet2 instanceof ActionParameterChoicesFacetViaMethod);
assertNotNull(facet0); final Facet facet1 = facetHolderWithParms.getParameters().get(0).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet1); assertTrue(facet1 instanceof ActionParameterChoicesFacetViaMethod); assertEquals(choices0Method, actionChoicesFacetViaMethod0.getMethods().get(0)); final Facet facet2 = facetHolderWithParms.getParameters().get(1).getFacet(ActionParameterChoicesFacet.class); assertNotNull(facet2); assertTrue(facet2 instanceof ActionParameterChoicesFacetViaMethod);