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;
}
}
}
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);
}
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" <t:parameter> 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));
}
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));
}
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;
}
Aggregations