use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.
the class PageLoaderImpl method parameter.
private void parameter(AssemblerContext context) {
final ParameterToken token = context.next(ParameterToken.class);
context.add(new PageAssemblyAction() {
public void execute(PageAssembly pageAssembly) {
String parameterName = token.name;
ComponentPageElement element = pageAssembly.createdElement.peek();
Location location = token.getLocation();
BlockImpl block = new BlockImpl(location, interner.format("Parameter %s of %s", parameterName, element.getCompleteId()));
Binding binding = new LiteralBinding(location, "block parameter " + parameterName, block);
EmbeddedComponentAssembler embeddedAssembler = pageAssembly.embeddedAssembler.peek();
ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
if (binder == null) {
throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", element.getCompleteId(), parameterName), location, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
}
binder.bind(pageAssembly.createdElement.peek(), binding);
pageAssembly.bodyElement.push(block);
}
});
consumeToEndElementAndPopBodyElement(context);
}
use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.
the class ReloadTests method beforeStartup.
@BeforeTest(groups = { "beforeStartup" })
public void beforeStartup(XmlTest xmlTest) throws Exception {
String uid = Long.toHexString(System.currentTimeMillis());
webappDir = new File(System.getProperty("java.io.tmpdir"), uid);
webinfDir = new File(webappDir, "WEB-INF");
classesDir = new File(webinfDir, "classes");
pagesDir = new File(classesDir, PACKAGE.replace('.', '/'));
pagesDir.mkdirs();
copy("web.xml", webinfDir, "web.xml");
copy("Index.1.tml", webappDir, "Index.tml");
copy("Index.1.properties", pagesDir, "Index.properties");
helper = new ClassCreationHelper(classesDir.getAbsolutePath());
createIndexClass(100);
// overwrite the web-app-folder parameter
xmlTest.addParameter(TapestryTestConstants.WEB_APP_FOLDER_PARAMETER, webappDir.getAbsolutePath());
}
use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.
the class OnEventWorker method implementDispatchMethod.
private void implementDispatchMethod(final PlasticClass plasticClass, final boolean isRoot, final MutableComponentModel model, final Flow<EventHandlerMethod> eventHandlerMethods) {
plasticClass.introduceMethod(TransformConstants.DISPATCH_COMPONENT_EVENT_DESCRIPTION).changeImplementation(new InstructionBuilderCallback() {
public void doBuild(InstructionBuilder builder) {
builder.startVariable("boolean", new LocalVariableCallback() {
public void doBuild(LocalVariable resultVariable, InstructionBuilder builder) {
if (!isRoot) {
// As a subclass, there will be a base class implementation (possibly empty).
builder.loadThis().loadArguments().invokeSpecial(plasticClass.getSuperClassName(), TransformConstants.DISPATCH_COMPONENT_EVENT_DESCRIPTION);
// First store the result of the super() call into the variable.
builder.storeVariable(resultVariable);
builder.loadArgument(0).invoke(Event.class, boolean.class, "isAborted");
builder.when(Condition.NON_ZERO, RETURN_TRUE);
} else {
// No event handler method has yet been invoked.
builder.loadConstant(false).storeVariable(resultVariable);
}
boolean hasRestEndpointEventHandlerMethod = false;
JSONArray restEndpointEventHandlerMethods = null;
for (EventHandlerMethod method : eventHandlerMethods) {
method.buildMatchAndInvocation(builder, resultVariable);
model.addEventHandler(method.eventType);
if (method.handleActivationEventContext) {
model.doHandleActivationEventContext();
}
// We're collecting this info for all components, even considering REST
// events are only triggered in pages, because we can have REST event
// handler methods in base classes too, and we need this info
// for generating complete, correct OpenAPI documentation.
final OnEvent onEvent = method.method.getAnnotation(OnEvent.class);
final String methodName = method.method.getDescription().methodName;
if (isRestEndpointEventHandlerMethod(onEvent, methodName)) {
hasRestEndpointEventHandlerMethod = true;
if (restEndpointEventHandlerMethods == null) {
restEndpointEventHandlerMethods = new JSONArray();
}
JSONObject methodMeta = new JSONObject();
methodMeta.put("name", methodName);
JSONArray parameters = new JSONArray();
for (MethodParameter parameter : method.method.getParameters()) {
parameters.add(parameter.getType());
}
methodMeta.put("parameters", parameters);
restEndpointEventHandlerMethods.add(methodMeta);
}
}
// memory by not setting it to all component models.
if (model.isPage()) {
model.setMeta(InternalConstants.REST_ENDPOINT_EVENT_HANDLER_METHOD_PRESENT, hasRestEndpointEventHandlerMethod ? InternalConstants.TRUE : InternalConstants.FALSE);
}
// methods in components, something that would be ignored anyway.
if (restEndpointEventHandlerMethods != null) {
model.setMeta(InternalConstants.REST_ENDPOINT_EVENT_HANDLER_METHODS, restEndpointEventHandlerMethods.toCompactString());
}
builder.loadVariable(resultVariable).returnResult();
}
});
}
});
}
use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.
the class BindParameterWorker method identifyParameterName.
private String identifyParameterName(ComponentResources resources, String firstGuess, String... otherGuesses) {
ComponentModel model = resources.getContainerResources().getComponentModel();
List<String> guesses = CollectionFactory.newList();
guesses.add(firstGuess);
for (String name : otherGuesses) {
guesses.add(name);
}
for (String name : guesses) {
if (model.isFormalParameter(name))
return name;
if (isPublishedParameter(model, name))
return name;
}
String message = String.format("Containing component %s does not contain a formal parameter or a published parameter %s %s.", model.getComponentClassName(), guesses.size() == 1 ? "matching" : "matching any of", InternalUtils.joinSorted(guesses));
List<String> formalAndPublishedParameters = CollectionFactory.newList(model.getParameterNames());
formalAndPublishedParameters.addAll(getPublishedParameters(model));
throw new UnknownValueException(message, new AvailableValues("Formal and published parameters", formalAndPublishedParameters));
}
use of org.apache.tapestry5.annotations.Parameter in project tapestry-5 by apache.
the class BindParameterWorker method convertFieldIntoContainerBoundParameter.
private void convertFieldIntoContainerBoundParameter(PlasticField field) {
BindParameter annotation = field.getAnnotation(BindParameter.class);
field.claim(annotation);
final String[] possibleNames = annotation.value();
final String fieldTypeName = field.getTypeName();
final String fieldName = field.getName();
ComputedValue<FieldConduit<Object>> computedConduit = new ComputedValue<FieldConduit<Object>>() {
public FieldConduit<Object> get(InstanceContext context) {
ComponentResources resources = context.get(ComponentResources.class);
try {
return createConduit(resources, fieldTypeName, fieldName, possibleNames);
} catch (Exception ex) {
throw new TapestryException(String.format("Failure binding parameter field '%s' of mixin %s (type %s): %s", fieldName, resources.getCompleteId(), resources.getComponentModel().getComponentClassName(), ExceptionUtils.toMessage(ex)), ex);
}
}
};
field.setComputedConduit(computedConduit);
}
Aggregations