use of org.apache.tapestry5.plastic.PlasticClass in project tapestry-5 by apache.
the class OperationWorker method transform.
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(Operation.class)) {
Operation annotation = method.getAnnotation(Operation.class);
method.addAdvice(advisor.createAdvice(annotation.value()));
}
}
use of org.apache.tapestry5.plastic.PlasticClass in project tapestry-5 by apache.
the class CachedWorker method createFactory.
private MethodResultCacheFactory createFactory(PlasticClass plasticClass, final String watch, PlasticMethod method) {
// will suffice.
if (watch.equals("")) {
return nonWatchFactory;
}
// Because of the watch, its necessary to create a factory for instances of this component and method.
final FieldHandle bindingFieldHandle = plasticClass.introduceField(Binding.class, "cache$watchBinding$" + method.getDescription().methodName).getHandle();
// Each component instance will get its own Binding instance. That handles both different locales,
// and reuse of a component (with a cached method) within a page or across pages. However, the binding can't be initialized
// until the page loads.
plasticClass.introduceInterface(PageLifecycleListener.class);
plasticClass.introduceMethod(TransformConstants.CONTAINING_PAGE_DID_LOAD_DESCRIPTION).addAdvice(new MethodAdvice() {
public void advise(MethodInvocation invocation) {
ComponentResources resources = invocation.getInstanceContext().get(ComponentResources.class);
Binding binding = bindingSource.newBinding("@Cached watch", resources, BindingConstants.PROP, watch);
bindingFieldHandle.set(invocation.getInstance(), binding);
invocation.proceed();
}
});
return new MethodResultCacheFactory() {
public MethodResultCache create(Object instance) {
Binding binding = (Binding) bindingFieldHandle.get(instance);
return new WatchedBindingMethodResultCache(binding);
}
};
}
use of org.apache.tapestry5.plastic.PlasticClass in project tapestry-5 by apache.
the class ParameterWorker method convertFieldIntoParameter.
private void convertFieldIntoParameter(PlasticClass plasticClass, MutableComponentModel model, PlasticField field) {
Parameter annotation = field.getAnnotation(Parameter.class);
String fieldType = field.getTypeName();
String parameterName = getParameterName(field.getName(), annotation.name());
field.claim(annotation);
model.addParameter(parameterName, annotation.required(), annotation.allowNull(), annotation.defaultPrefix(), annotation.cache());
MethodHandle defaultMethodHandle = findDefaultMethodHandle(plasticClass, parameterName);
ComputedValue<FieldConduit<Object>> computedParameterConduit = createComputedParameterConduit(parameterName, fieldType, annotation, defaultMethodHandle);
field.setComputedConduit(computedParameterConduit);
}
use of org.apache.tapestry5.plastic.PlasticClass in project tapestry-5 by apache.
the class RenderCommandWorker method transform.
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
if (!support.isRootTransformation()) {
return;
}
plasticClass.introduceInterface(RenderCommand.class);
PlasticField resourcesField = plasticClass.introduceField(InternalComponentResources.class, "resources").injectFromInstanceContext();
plasticClass.introduceMethod(RENDER_DESCRIPTION).delegateTo(resourcesField);
plasticClass.introduceMethod(TransformConstants.POST_RENDER_CLEANUP_DESCRIPTION).delegateTo(resourcesField);
}
use of org.apache.tapestry5.plastic.PlasticClass in project tapestry-5 by apache.
the class ImportWorker method decorateMethod.
private void decorateMethod(PlasticClass componentClass, MutableComponentModel model, PlasticMethod method) {
Import annotation = method.getAnnotation(Import.class);
decorateMethod(componentClass, model, method, annotation);
}
Aggregations