Search in sources :

Example 1 with Operation

use of org.apache.tapestry5.ioc.annotations.Operation 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 2 with Operation

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

the class TapestryModule method provideTransformWorkers.

/**
 * Adds a number of standard component class transform workers:
 * <dl>
 * <dt>Parameter</dt>
 * <dd>Identifies parameters based on the {@link org.apache.tapestry5.annotations.Parameter} annotation</dd>
 * <dt>BindParameter</dt>
 * <dd>Support for the {@link BindParameter} annotation</dd>
 * <dt>Property</dt>
 * <dd>Generates accessor methods if {@link org.apache.tapestry5.annotations.Property} annotation is present</dd>
 * <dt>Import</dt>
 * <dd>Supports the {@link Import} annotation</dd>
 * <dt>UnclaimedField</dt>
 * <dd>Manages unclaimed fields, storing their value in a {@link PerThreadValue}</dd>
 * <dt>OnEvent</dt>
 * <dd>Handle the @OnEvent annotation, and related naming convention</dd>
 * <dt>RenderCommand</dt>
 * <dd>Ensures all components also implement {@link org.apache.tapestry5.runtime.RenderCommand}</dd>
 * <dt>SupportsInformalParameters</dt>
 * <dd>Checks for the annotation</dd>
 * <dt>RenderPhase</dt>
 * <dd>Link in render phase methods</dd>
 * <dt>Retain</dt>
 * <dd>Allows fields to retain their values between requests</dd>
 * <dt>Meta</dt>
 * <dd>Checks for meta data annotations and adds it to the component model</dd>
 * <dt>PageActivationContext</dt> <dd>Support for {@link PageActivationContext} annotation</dd>
 * <dt>DiscardAfter</dt> <dd>Support for {@link DiscardAfter} method annotation </dd>
 * <dt>MixinAfter</dt> <dd>Support for the {@link MixinAfter} mixin class annotation</dd>
 * <dt>PageReset</dt>
 * <dd>Checks for the {@link PageReset} annotation</dd>
 * <dt>Mixin</dt>
 * <dd>Adds a mixin as part of a component's implementation</dd>
 * <dt>Cached</dt>
 * <dd>Checks for the {@link org.apache.tapestry5.annotations.Cached} annotation</dd>
 * <dt>ActivationRequestParameter</dt>
 * <dd>Support for the {@link ActivationRequestParameter} annotation</dd>
 * <dt>PageLoaded, PageAttached, PageDetached</dt>
 * <dd>Support for annotations {@link PageLoaded}, {@link PageAttached}, {@link PageDetached}</dd>
 * <dt>InjectService</dt>
 * <dd>Handles the {@link org.apache.tapestry5.ioc.annotations.InjectService} annotation</dd>
 * <dt>Component</dt>
 * <dd>Defines embedded components based on the {@link org.apache.tapestry5.annotations.Component} annotation</dd>
 * <dt>Environment</dt>
 * <dd>Allows fields to contain values extracted from the {@link org.apache.tapestry5.services.Environment} service</dd>
 * <dt>ApplicationState</dt>
 * <dd>Converts fields that reference application state objects</dd>
 * <dt>Persist</dt>
 * <dd>Allows fields to store their their value persistently between requests via {@link Persist}</dd>
 * <dt>SessionAttribute</dt>
 * <dd>Support for the {@link SessionAttribute}</dd>
 * <dt>Log</dt>
 * <dd>Checks for the {@link org.apache.tapestry5.annotations.Log} annotation</dd>
 * <dt>HeartbeatDeferred
 * <dd>Support for the {@link HeartbeatDeferred} annotation, which defers method invocation to the end of the {@link Heartbeat}
 * <dt>Inject</dt>
 * <dd>Used with the {@link org.apache.tapestry5.ioc.annotations.Inject} annotation, when a value is supplied</dd>
 * <dt>Operation</dt> <dd>Support for the {@link Operation} method annotation</dd>
 * </dl>
 */
@Contribute(ComponentClassTransformWorker2.class)
@Primary
public static void provideTransformWorkers(OrderedConfiguration<ComponentClassTransformWorker2> configuration, MetaWorker metaWorker, ComponentClassResolver resolver) {
    configuration.add("Property", new PropertyWorker());
    // Order this one pretty early:
    configuration.addInstance("Operation", OperationWorker.class);
    configuration.add("RenderCommand", new RenderCommandWorker());
    configuration.addInstance("OnEvent", OnEventWorker.class);
    configuration.add("MixinAfter", new MixinAfterWorker());
    // These must come after Property, since they actually delete fields
    // that may still have the annotation
    configuration.addInstance("ApplicationState", ApplicationStateWorker.class);
    configuration.addInstance("Environment", EnvironmentalWorker.class);
    configuration.add("Component", new ComponentWorker(resolver));
    configuration.add("Mixin", new MixinWorker(resolver));
    configuration.addInstance("InjectPage", InjectPageWorker.class);
    configuration.addInstance("InjectComponent", InjectComponentWorker.class);
    configuration.addInstance("InjectContainer", InjectContainerWorker.class);
    // Default values for parameters are often some form of injection, so
    // make sure that Parameter fields are processed after injections.
    configuration.addInstance("Parameter", ParameterWorker.class);
    // bind parameter should always go after parameter to make sure all
    // parameters have been properly setup.
    configuration.addInstance("BindParameter", BindParameterWorker.class);
    configuration.add("SupportsInformalParameters", new SupportsInformalParametersWorker());
    configuration.addInstance("RenderPhase", RenderPhaseMethodWorker.class);
    // Import advises methods, usually render phase methods, so it must come after RenderPhase.
    configuration.addInstance("Import", ImportWorker.class);
    configuration.add("Meta", metaWorker.getWorker());
    configuration.add("Retain", new RetainWorker());
    configuration.add("PageActivationContext", new PageActivationContextWorker());
    configuration.addInstance("ActivationRequestParameter", ActivationRequestParameterWorker.class);
    configuration.addInstance("Cached", CachedWorker.class);
    configuration.addInstance("DiscardAfter", DiscardAfterWorker.class);
    add(configuration, PageLoaded.class, TransformConstants.CONTAINING_PAGE_DID_LOAD_DESCRIPTION);
    add(configuration, PageAttached.class, TransformConstants.CONTAINING_PAGE_DID_ATTACH_DESCRIPTION);
    add(configuration, PageDetached.class, TransformConstants.CONTAINING_PAGE_DID_DETACH_DESCRIPTION);
    configuration.addInstance("PageReset", PageResetAnnotationWorker.class);
    configuration.addInstance("InjectService", InjectServiceWorker.class);
    configuration.addInstance("Inject", InjectWorker.class);
    configuration.addInstance("Persist", PersistWorker.class);
    configuration.addInstance("SessionAttribute", SessionAttributeWorker.class);
    configuration.addInstance("Log", LogWorker.class);
    configuration.addInstance("HeartbeatDeferred", HeartbeatDeferredWorker.class);
    // This one is always last. Any additional private fields that aren't
    // annotated will
    // be converted to clear out at the end of the request.
    configuration.addInstance("UnclaimedField", UnclaimedFieldWorker.class, "after:*");
}
Also used : PageActivationContextWorker(org.apache.tapestry5.internal.transform.PageActivationContextWorker) PropertyWorker(org.apache.tapestry5.internal.transform.PropertyWorker) MixinWorker(org.apache.tapestry5.internal.transform.MixinWorker) RetainWorker(org.apache.tapestry5.internal.transform.RetainWorker) ComponentWorker(org.apache.tapestry5.internal.transform.ComponentWorker) InjectComponentWorker(org.apache.tapestry5.internal.transform.InjectComponentWorker) RenderCommandWorker(org.apache.tapestry5.internal.transform.RenderCommandWorker) SupportsInformalParametersWorker(org.apache.tapestry5.internal.transform.SupportsInformalParametersWorker) MixinAfterWorker(org.apache.tapestry5.internal.transform.MixinAfterWorker) Primary(org.apache.tapestry5.ioc.annotations.Primary) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 3 with Operation

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

the class OperationAdvisorImpl method addOperationAdvice.

@Override
public void addOperationAdvice(MethodAdviceReceiver receiver) {
    for (Method m : receiver.getInterface().getMethods()) {
        Operation annotation = receiver.getMethodAnnotation(m, Operation.class);
        if (annotation != null) {
            String value = annotation.value();
            receiver.adviseMethod(m, createAdvice(value));
        }
    }
}
Also used : Method(java.lang.reflect.Method) Operation(org.apache.tapestry5.ioc.annotations.Operation)

Example 4 with Operation

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

the class DeferredResponseRenderer method invokeQueuedRenderer.

private void invokeQueuedRenderer() throws IOException {
    while (true) {
        IOOperation responseRenderer = (IOOperation) request.getAttribute(TapestryConstants.RESPONSE_RENDERER);
        if (responseRenderer == null) {
            break;
        }
        // There's a particular case where an operation puts a different operation into the attribute;
        // we'll handle that on the next pass.
        request.setAttribute(TapestryConstants.RESPONSE_RENDERER, null);
        tracker.perform("Executing deferred response renderer.", responseRenderer);
    }
}
Also used : IOOperation(org.apache.tapestry5.ioc.IOOperation)

Example 5 with Operation

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

the class ModuleImpl method create.

/**
 * Creates the service and updates the cache of created services.
 *
 * @param eagerLoadProxies a list into which any eager loaded proxies should be added
 */
private Object create(final ServiceDef3 def, final Collection<EagerLoadServiceProxy> eagerLoadProxies) {
    final String serviceId = def.getServiceId();
    final Logger logger = registry.getServiceLogger(serviceId);
    final Class serviceInterface = def.getServiceInterface();
    final boolean canBeProxied = canBeProxiedPredicate.test(serviceInterface);
    String description = String.format("Creating %s service %s", canBeProxied ? "proxy for" : "non-proxied instance of", serviceId);
    if (logger.isDebugEnabled())
        logger.debug(description);
    final Module module = this;
    Invokable operation = new Invokable() {

        @Override
        public Object invoke() {
            try {
                ServiceBuilderResources resources = new ServiceResourcesImpl(registry, module, def, proxyFactory, logger);
                // Build up a stack of operations that will be needed to realize the service
                // (by the proxy, at a later date).
                ObjectCreator creator = def.createServiceCreator(resources);
                // For non-proxyable services, we immediately create the service implementation
                // and return it. There's no interface to proxy, which throws out the possibility of
                // deferred instantiation, service lifecycles, and decorators.
                ServiceLifecycle2 lifecycle = registry.getServiceLifecycle(def.getServiceScope());
                if (!canBeProxied) {
                    if (lifecycle.requiresProxy())
                        throw new IllegalArgumentException(String.format("Service scope '%s' requires a proxy, but the service does not have a service interface (necessary to create a proxy). Provide a service interface or select a different service scope.", def.getServiceScope()));
                    return creator.createObject();
                }
                creator = new OperationTrackingObjectCreator(registry, String.format("Instantiating service %s implementation via %s", serviceId, creator), creator);
                creator = new LifecycleWrappedServiceCreator(lifecycle, resources, creator);
                // Marked services (or services inside marked modules) are not decorated.
                // TapestryIOCModule prevents decoration of its services. Note that all decorators will decorate
                // around the aspect interceptor, which wraps around the core service implementation.
                boolean allowDecoration = !def.isPreventDecoration();
                if (allowDecoration) {
                    creator = new AdvisorStackBuilder(def, creator, getAspectDecorator(), registry);
                    creator = new InterceptorStackBuilder(def, creator, registry);
                }
                // Add a wrapper that checks for recursion.
                creator = new RecursiveServiceCreationCheckWrapper(def, creator, logger);
                creator = new OperationTrackingObjectCreator(registry, "Realizing service " + serviceId, creator);
                JustInTimeObjectCreator delegate = new JustInTimeObjectCreator(tracker, creator, serviceId);
                Object proxy = createProxy(resources, delegate, def.isPreventDecoration());
                registry.addRegistryShutdownListener(delegate);
                if (def.isEagerLoad() && eagerLoadProxies != null)
                    eagerLoadProxies.add(delegate);
                tracker.setStatus(serviceId, Status.VIRTUAL);
                return proxy;
            } catch (Exception ex) {
                ex.printStackTrace();
                throw new RuntimeException(IOCMessages.errorBuildingService(serviceId, def, ex), ex);
            }
        }
    };
    return registry.invoke(description, operation);
}
Also used : JustInTimeObjectCreator(org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator) Logger(org.slf4j.Logger) ServiceBuilderResources(org.apache.tapestry5.ioc.ServiceBuilderResources) InvocationTargetException(java.lang.reflect.InvocationTargetException) ObjectStreamException(java.io.ObjectStreamException) JustInTimeObjectCreator(org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator) ServiceLifecycle2(org.apache.tapestry5.ioc.ServiceLifecycle2) Invokable(org.apache.tapestry5.ioc.Invokable)

Aggregations

Invokable (org.apache.tapestry5.ioc.Invokable)2 Operation (org.apache.tapestry5.ioc.annotations.Operation)2 ObjectStreamException (java.io.ObjectStreamException)1 Array (java.lang.reflect.Array)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 ComponentResources (org.apache.tapestry5.ComponentResources)1 EventContext (org.apache.tapestry5.EventContext)1 ValueEncoder (org.apache.tapestry5.ValueEncoder)1 DisableStrictChecks (org.apache.tapestry5.annotations.DisableStrictChecks)1 OnEvent (org.apache.tapestry5.annotations.OnEvent)1 PublishEvent (org.apache.tapestry5.annotations.PublishEvent)1 RequestBody (org.apache.tapestry5.annotations.RequestBody)1 RequestParameter (org.apache.tapestry5.annotations.RequestParameter)1