Search in sources :

Example 6 with PlasticClass

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()));
    }
}
Also used : PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod) Operation(org.apache.tapestry5.ioc.annotations.Operation)

Example 7 with PlasticClass

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);
        }
    };
}
Also used : Binding(org.apache.tapestry5.Binding) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 8 with PlasticClass

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);
}
Also used : Parameter(org.apache.tapestry5.annotations.Parameter)

Example 9 with PlasticClass

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);
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) PlasticField(org.apache.tapestry5.plastic.PlasticField)

Example 10 with PlasticClass

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);
}
Also used : Import(org.apache.tapestry5.annotations.Import)

Aggregations

PlasticField (org.apache.tapestry5.plastic.PlasticField)13 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)11 InstructionBuilder (org.apache.tapestry5.plastic.InstructionBuilder)5 InstructionBuilderCallback (org.apache.tapestry5.plastic.InstructionBuilderCallback)5 PlasticMethod (org.apache.tapestry5.plastic.PlasticMethod)5 Method (java.lang.reflect.Method)4 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)4 PlasticClassTransformer (org.apache.tapestry5.plastic.PlasticClassTransformer)3 Test (org.testng.annotations.Test)3 PersistenceContext (javax.persistence.PersistenceContext)2 SneakyThrows (lombok.SneakyThrows)2 ComponentResources (org.apache.tapestry5.ComponentResources)2 Import (org.apache.tapestry5.annotations.Import)2 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)2 InstanceContext (org.apache.tapestry5.plastic.InstanceContext)2 MethodAdvice (org.apache.tapestry5.plastic.MethodAdvice)2 IFn (clojure.lang.IFn)1 Symbol (clojure.lang.Symbol)1 SessionTracker (com.flowlogix.web.mixins.SessionTracker)1 AJAX (com.flowlogix.web.services.annotations.AJAX)1