Search in sources :

Example 26 with Parameter

use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.

the class DefaultModuleDefImpl method grind.

private void grind(Set<Method> remainingMethods, boolean modulePreventsServiceDecoration) {
    Method[] methods = moduleClass.getMethods();
    Comparator<Method> c = new Comparator<Method>() {

        // By name, ascending, then by parameter count, descending.
        @Override
        public int compare(Method o1, Method o2) {
            int result = o1.getName().compareTo(o2.getName());
            if (result == 0)
                result = o2.getParameterTypes().length - o1.getParameterTypes().length;
            return result;
        }
    };
    Arrays.sort(methods, c);
    for (Method m : methods) {
        String name = m.getName();
        if (name.startsWith(BUILD_METHOD_NAME_PREFIX)) {
            addServiceDef(m, modulePreventsServiceDecoration);
            remainingMethods.remove(m);
            continue;
        }
        if (name.startsWith(DECORATE_METHOD_NAME_PREFIX) || m.isAnnotationPresent(Decorate.class)) {
            addDecoratorDef(m);
            remainingMethods.remove(m);
            continue;
        }
        if (name.startsWith(CONTRIBUTE_METHOD_NAME_PREFIX) || m.isAnnotationPresent(Contribute.class)) {
            addContributionDef(m);
            remainingMethods.remove(m);
            continue;
        }
        if (name.startsWith(ADVISE_METHOD_NAME_PREFIX) || m.isAnnotationPresent(Advise.class)) {
            addAdvisorDef(m);
            remainingMethods.remove(m);
            continue;
        }
        if (m.isAnnotationPresent(Startup.class)) {
            addStartupDef(m);
            remainingMethods.remove(m);
            continue;
        }
    }
}
Also used : Contribute(org.apache.tapestry5.ioc.annotations.Contribute) Method(java.lang.reflect.Method) Decorate(org.apache.tapestry5.ioc.annotations.Decorate) Advise(org.apache.tapestry5.ioc.annotations.Advise) Comparator(java.util.Comparator)

Example 27 with Parameter

use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.

the class DefaultModuleDefImpl method addAdvisorDef.

private void addAdvisorDef(Method method) {
    Advise annotation = method.getAnnotation(Advise.class);
    Class serviceInterface = annotation == null ? null : annotation.serviceInterface();
    // TODO: methods just named "decorate"
    String advisorId = annotation == null ? stripMethodPrefix(method, ADVISE_METHOD_NAME_PREFIX) : extractId(serviceInterface, annotation.id());
    // TODO: Check for duplicates
    Class returnType = method.getReturnType();
    if (!returnType.equals(void.class))
        throw new RuntimeException(String.format("Advise method %s does not return void.", toString(method)));
    boolean found = false;
    for (Class pt : method.getParameterTypes()) {
        if (pt.equals(MethodAdviceReceiver.class)) {
            found = true;
            break;
        }
    }
    if (!found)
        throw new RuntimeException(String.format("Advise method %s must take a parameter of type %s.", toString(method), MethodAdviceReceiver.class.getName()));
    Set<Class> markers = extractMarkers(method, Advise.class);
    AdvisorDef def = new AdvisorDefImpl(method, extractPatterns(advisorId, method), extractConstraints(method), proxyFactory, advisorId, serviceInterface, markers);
    advisorDefs.put(advisorId, def);
}
Also used : MethodAdviceReceiver(org.apache.tapestry5.ioc.MethodAdviceReceiver) Advise(org.apache.tapestry5.ioc.annotations.Advise) AdvisorDef(org.apache.tapestry5.ioc.AdvisorDef)

Example 28 with Parameter

use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.

the class SaxTemplateParser method classicParameter.

/**
 * Handler for Tapestry 5.0's "classic" &lt;t:parameter&gt; element. This
 * turns into a {@link org.apache.tapestry5.internal.parser.ParameterToken}
 * and the body and end element are provided normally.
 */
private void classicParameter(TemplateParserState state) {
    String parameterName = getSingleParameter("name");
    if (InternalUtils.isBlank(parameterName))
        throw new TapestryException("The name attribute of the <parameter> element must be specified.", getLocation(), null);
    ensureParameterWithinComponent(state);
    tokenAccumulator.add(new ParameterToken(parameterName, getLocation()));
    processBody(state.insideComponent(false));
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 29 with Parameter

use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.

the class SaxTemplateParser method parameterElement.

/**
 * Tapestry 5.1 uses a special namespace (usually mapped to "p:") and the
 * name becomes the parameter element.
 */
private void parameterElement(TemplateParserState state) {
    ensureParameterWithinComponent(state);
    if (tokenStream.getAttributeCount() > 0)
        throw new TapestryException("A block parameter element does not allow any additional attributes. The element name defines the parameter name.", getLocation(), null);
    tokenAccumulator.add(new ParameterToken(tokenStream.getLocalName(), getLocation()));
    processBody(state.insideComponent(false));
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 30 with Parameter

use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.

the class RequestSecurityManagerImpl method checkForInsecureComponentEventRequest.

public boolean checkForInsecureComponentEventRequest(ComponentEventRequestParameters parameters) throws IOException {
    if (!needsRedirect(parameters.getActivePageName())) {
        return false;
    }
    // Page is secure but request is not, so redirect.
    // We can safely ignore the forForm parameter since secure form requests are always done from
    // an already secured page
    Link link = componentEventLinkEncoder.createComponentEventLink(parameters, false);
    response.sendRedirect(link);
    return true;
}
Also used : Link(org.apache.tapestry5.http.Link)

Aggregations

TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)12 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)6 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)6 RequestParameter (org.apache.tapestry5.annotations.RequestParameter)5 JSONObject (org.apache.tapestry5.json.JSONObject)5 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)5 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)4 Test (org.testng.annotations.Test)4 Binding (org.apache.tapestry5.Binding)3 ComponentResources (org.apache.tapestry5.ComponentResources)3 ActivationContextParameter (org.apache.tapestry5.annotations.ActivationContextParameter)3 Location (org.apache.tapestry5.commons.Location)3 Resource (org.apache.tapestry5.commons.Resource)3 AvailableValues (org.apache.tapestry5.commons.util.AvailableValues)3 LiteralBinding (org.apache.tapestry5.internal.bindings.LiteralBinding)3 Logger (org.slf4j.Logger)3 Method (java.lang.reflect.Method)2 Parameter (java.lang.reflect.Parameter)2 EventContext (org.apache.tapestry5.EventContext)2 ValueEncoder (org.apache.tapestry5.ValueEncoder)2