Search in sources :

Example 11 with Service

use of org.apache.tapestry5.annotations.Service 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 12 with Service

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

the class TapestryModule method contributeDataTypeAnalyzer.

/**
 * <dl>
 * <dt>Annotation</dt>
 * <dd>Checks for {@link org.apache.tapestry5.beaneditor.DataType} annotation</dd>
 * <dt>Default (ordered last)</dt>
 * <dd>
 * {@link org.apache.tapestry5.commons.internal.services.DefaultDataTypeAnalyzer} service (
 * {@link #contributeDefaultDataTypeAnalyzer(org.apache.tapestry5.commons.MappedConfiguration)} )</dd>
 * </dl>
 */
public static void contributeDataTypeAnalyzer(OrderedConfiguration<DataTypeAnalyzer> configuration, @InjectService("DefaultDataTypeAnalyzer") DataTypeAnalyzer defaultDataTypeAnalyzer) {
    configuration.add("Annotation", new AnnotationDataTypeAnalyzer());
    configuration.add("Default", defaultDataTypeAnalyzer, "after:*");
}
Also used : AnnotationDataTypeAnalyzer(org.apache.tapestry5.commons.internal.services.AnnotationDataTypeAnalyzer)

Example 13 with Service

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

the class TapestryModule method contributeRequestHandler.

/**
 * Continues a number of filters into the RequestHandler service:
 * <dl>
 * <dt>StaticFiles</dt>
 * <dd>Checks to see if the request is for an actual file, if so, returns true to let the servlet container process
 * the request</dd>
 * <dt>CheckForUpdates</dt>
 * <dd>Periodically fires events that checks to see if the file system sources for any cached data has changed (see
 * {@link org.apache.tapestry5.internal.services.CheckForUpdatesFilter}). Starting in 5.3, this filter will be null
 * in production mode (it will only be active in development mode).
 * <dt>ErrorFilter</dt>
 * <dd>Catches request errors and lets the {@link org.apache.tapestry5.services.RequestExceptionHandler} handle them
 * </dd>
 * <dt>StoreIntoGlobals</dt>
 * <dd>Stores the request and response into the {@link org.apache.tapestry5.http.services.RequestGlobals} service (this
 * is repeated at the end of the pipeline, in case any filter substitutes the request or response).
 * <dt>EndOfRequest</dt>
 * <dd>Notifies internal services that the request has ended</dd>
 * </dl>
 */
public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration, Context context, @Symbol(TapestryHttpSymbolConstants.PRODUCTION_MODE) boolean productionMode) {
    RequestFilter staticFilesFilter = new StaticFilesFilter(context);
    RequestFilter storeIntoGlobals = new RequestFilter() {

        public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
            requestGlobals.storeRequestResponse(request, response);
            return handler.service(request, response);
        }
    };
    RequestFilter fireEndOfRequestEvent = new RequestFilter() {

        public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
            try {
                return handler.service(request, response);
            } finally {
                endOfRequestEventHub.fire();
            }
        }
    };
    if (productionMode) {
        configuration.add("CheckForUpdates", null, "before:*");
    } else {
        configuration.addInstance("CheckForUpdates", CheckForUpdatesFilter.class, "before:*");
    }
    configuration.add("StaticFiles", staticFilesFilter);
    configuration.add("StoreIntoGlobals", storeIntoGlobals);
    configuration.add("EndOfRequest", fireEndOfRequestEvent);
    configuration.addInstance("ErrorFilter", RequestErrorFilter.class);
}
Also used : StreamResponse(org.apache.tapestry5.StreamResponse) Response(org.apache.tapestry5.http.services.Response) ComponentEventRequestHandler(org.apache.tapestry5.services.ComponentEventRequestHandler) RequestHandler(org.apache.tapestry5.http.services.RequestHandler) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) PageRenderRequestHandler(org.apache.tapestry5.services.PageRenderRequestHandler) Request(org.apache.tapestry5.http.services.Request) HttpServletRequestFilter(org.apache.tapestry5.http.services.HttpServletRequestFilter) ComponentRequestFilter(org.apache.tapestry5.services.ComponentRequestFilter) PageRenderRequestFilter(org.apache.tapestry5.services.PageRenderRequestFilter) RequestFilter(org.apache.tapestry5.http.services.RequestFilter) ComponentEventRequestFilter(org.apache.tapestry5.services.ComponentEventRequestFilter)

Example 14 with Service

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

the class TapestryModule method contributeMarkupRenderer.

/**
 * Adds page render filters, each of which provides an {@link org.apache.tapestry5.annotations.Environmental}
 * service. Filters
 * often provide {@link org.apache.tapestry5.annotations.Environmental} services needed by
 * components as they render.
 * <dl>
 * <dt>DocumentLinker</dt>
 * <dd>Provides {@link org.apache.tapestry5.internal.services.DocumentLinker}</dd>
 * <dt>ClientBehaviorSupport (deprecated in 5.4)</dt>
 * <dd>Provides {@link ClientBehaviorSupport}</dd>
 * <dt>Heartbeat</dt>
 * <dd>Provides {@link org.apache.tapestry5.services.Heartbeat}</dd>
 * <dt>ValidationDecorator (deprecated in 5.4)</dt>
 * <dd>Provides {@link org.apache.tapestry5.ValidationDecorator} (via {@link ValidationDecoratorFactory#newInstance(org.apache.tapestry5.MarkupWriter)})</dd>
 * <dt>PageNameMeta (since 5.4)</dt>
 * <dd>Renders a {@code <meta/>} tag describing the active page name (development mode only)</dd>
 * <dt>ImportCoreStack (since 5.4) </dt>
 * <dd>Imports the "core" stack (necessary to get the Bootstrap CSS, if nothing else).</dd>
 * </dl>
 *
 * @see org.apache.tapestry5.SymbolConstants#OMIT_GENERATOR_META
 * @see org.apache.tapestry5.http.TapestryHttpSymbolConstants#PRODUCTION_MODE
 * @see org.apache.tapestry5.SymbolConstants#INCLUDE_CORE_STACK
 * @see org.apache.tapestry5.SymbolConstants#ENABLE_PAGELOADING_MASK
 */
public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration, final ModuleManager moduleManager, @Symbol(SymbolConstants.OMIT_GENERATOR_META) final boolean omitGeneratorMeta, @Symbol(TapestryHttpConstants.TAPESTRY_VERSION) final String tapestryVersion, @Symbol(TapestryHttpSymbolConstants.PRODUCTION_MODE) boolean productionMode, @Symbol(SymbolConstants.INCLUDE_CORE_STACK) final boolean includeCoreStack, @Symbol(SymbolConstants.ENABLE_PAGELOADING_MASK) final boolean enablePageloadingMask, final ValidationDecoratorFactory validationDecoratorFactory) {
    MarkupRendererFilter documentLinker = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            DocumentLinkerImpl linker = new DocumentLinkerImpl(moduleManager, omitGeneratorMeta, enablePageloadingMask, tapestryVersion);
            environment.push(DocumentLinker.class, linker);
            renderer.renderMarkup(writer);
            environment.pop(DocumentLinker.class);
            linker.updateDocument(writer.getDocument());
        }
    };
    MarkupRendererFilter clientBehaviorSupport = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            ClientBehaviorSupportImpl clientBehaviorSupport = new ClientBehaviorSupportImpl();
            environment.push(ClientBehaviorSupport.class, clientBehaviorSupport);
            renderer.renderMarkup(writer);
            environment.pop(ClientBehaviorSupport.class);
        }
    };
    MarkupRendererFilter heartbeat = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            Heartbeat heartbeat = new HeartbeatImpl();
            heartbeat.begin();
            environment.push(Heartbeat.class, heartbeat);
            renderer.renderMarkup(writer);
            environment.pop(Heartbeat.class);
            heartbeat.end();
        }
    };
    MarkupRendererFilter defaultValidationDecorator = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            ValidationDecorator decorator = validationDecoratorFactory.newInstance(writer);
            environment.push(ValidationDecorator.class, decorator);
            renderer.renderMarkup(writer);
            environment.pop(ValidationDecorator.class);
        }
    };
    MarkupRendererFilter importCoreStack = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            renderer.renderMarkup(writer);
            environment.peekRequired(JavaScriptSupport.class).importStack(InternalConstants.CORE_STACK_NAME);
        }
    };
    configuration.add("DocumentLinker", documentLinker);
    configuration.add("ClientBehaviorSupport", clientBehaviorSupport, "after:JavaScriptSupport");
    configuration.add("Heartbeat", heartbeat);
    configuration.add("ValidationDecorator", defaultValidationDecorator);
    if (includeCoreStack) {
        configuration.add("ImportCoreStack", importCoreStack);
    }
    if (productionMode) {
        configuration.add("PageNameMeta", null);
    } else {
        configuration.addInstance("PageNameMeta", PageNameMetaInjector.class);
    }
}
Also used : MarkupRenderer(org.apache.tapestry5.services.MarkupRenderer) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) MarkupRendererFilter(org.apache.tapestry5.services.MarkupRendererFilter) JavaScriptSupport(org.apache.tapestry5.services.javascript.JavaScriptSupport) Heartbeat(org.apache.tapestry5.services.Heartbeat) MarkupWriter(org.apache.tapestry5.MarkupWriter) ValidationDecorator(org.apache.tapestry5.ValidationDecorator)

Example 15 with Service

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

the class TapestryIOCModule method setupObjectProviders.

/**
 * <dl>
 * <dt>AnnotationBasedContributions</dt>
 * <dd>Empty placeholder used to separate annotation-based ObjectProvider contributions (which come before) from
 * non-annotation based (such as ServiceOverride) which come after.</dd>
 * <dt>Value</dt>
 * <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Value} annotation</dd>
 * <dt>Symbol</dt>
 * <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Symbol} annotations</dd>
 * <dt>Autobuild</dt>
 * <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Autobuild} annotation</dd>
 * <dt>ServiceOverride</dt>
 * <dd>Allows simple service overrides via the {@link org.apache.tapestry5.ioc.services.ServiceOverride} service
 * (and its configuration)
 * </dl>
 */
@Contribute(MasterObjectProvider.class)
public static void setupObjectProviders(OrderedConfiguration<ObjectProvider> configuration, @Local final ServiceOverride serviceOverride) {
    configuration.add("AnnotationBasedContributions", null);
    configuration.addInstance("Value", ValueObjectProvider.class, before("AnnotationBasedContributions").build());
    configuration.addInstance("Symbol", SymbolObjectProvider.class, before("AnnotationBasedContributions").build());
    configuration.add("Autobuild", new AutobuildObjectProvider(), before("AnnotationBasedContributions").build());
    ObjectProvider wrapper = new ObjectProvider() {

        @Override
        public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
            return serviceOverride.getServiceOverrideProvider().provide(objectType, annotationProvider, locator);
        }
    };
    configuration.add("ServiceOverride", wrapper, after("AnnotationBasedContributions").build());
}
Also used : AutobuildObjectProvider(org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider) ValueObjectProvider(org.apache.tapestry5.ioc.internal.services.ValueObjectProvider) MasterObjectProvider(org.apache.tapestry5.ioc.services.MasterObjectProvider) SymbolObjectProvider(org.apache.tapestry5.ioc.internal.services.SymbolObjectProvider) AutobuildObjectProvider(org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider)

Aggregations

Service (org.jvnet.hk2.annotations.Service)11 Test (org.testng.annotations.Test)7 List (java.util.List)4 Config (com.sun.enterprise.config.serverbeans.Config)2 PropertyVetoException (java.beans.PropertyVetoException)2 IOException (java.io.IOException)2 Annotation (java.lang.annotation.Annotation)2 Type (java.lang.reflect.Type)2 HashMap (java.util.HashMap)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2 Inject (javax.inject.Inject)2 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 TapestryIOCModule (org.apache.tapestry5.ioc.modules.TapestryIOCModule)2 AdminCommand (org.glassfish.api.admin.AdminCommand)2 RestEndpoint (org.glassfish.api.admin.RestEndpoint)2 RestEndpoints (org.glassfish.api.admin.RestEndpoints)2 ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)2 DescriptorType (org.glassfish.hk2.api.DescriptorType)2