Search in sources :

Example 26 with Service

use of org.apache.tapestry5.annotations.Service in project glassfish-hk2 by eclipse-ee4j.

the class PerLocatorUtilities method getAutoAnalyzerName.

/**
 * Gets the analyzer name from the Service annotation
 *
 * @param c The class to get the analyzer name from
 * @return The name of the analyzer (null for default)
 */
public String getAutoAnalyzerName(Class<?> c) {
    String retVal = threadLocalAutoAnalyzerNameCache.get().get(c);
    if (retVal != null)
        return retVal;
    Service s = c.getAnnotation(Service.class);
    if (s == null)
        return null;
    retVal = s.analyzer();
    threadLocalAutoAnalyzerNameCache.get().put(c, retVal);
    return retVal;
}
Also used : Service(org.jvnet.hk2.annotations.Service)

Example 27 with Service

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

the class AjaxComponentEventRequestHandler method handle.

public void handle(ComponentEventRequestParameters parameters) throws IOException {
    Page activePage = cache.get(parameters.getActivePageName());
    final Holder<Boolean> resultProcessorInvoked = Holder.create();
    resultProcessorInvoked.put(false);
    ComponentEventResultProcessor interceptor = new ComponentEventResultProcessor() {

        public void processResultValue(Object value) throws IOException {
            resultProcessorInvoked.put(true);
            resultProcessor.processResultValue(value);
        }
    };
    // If we end up doing a partial render, the page render queue service needs to know the
    // page that will be rendered (for logging purposes, if nothing else).
    queue.setRenderingPage(activePage);
    request.setAttribute(InternalConstants.PAGE_NAME_ATTRIBUTE_NAME, parameters.getActivePageName());
    if (pageActivator.activatePage(activePage.getRootElement().getComponentResources(), parameters.getPageActivationContext(), interceptor))
        return;
    Page containerPage = cache.get(parameters.getContainingPageName());
    ComponentPageElement element = containerPage.getComponentElementByNestedId(parameters.getNestedComponentId());
    // In many cases, the triggered element is a Form that needs to be able to
    // pass its event handler return values to the correct result processor.
    // This is certainly the case for forms.
    TrackableComponentEventCallback callback = new ComponentResultProcessorWrapper(interceptor);
    environment.push(ComponentEventResultProcessor.class, interceptor);
    environment.push(TrackableComponentEventCallback.class, callback);
    boolean handled = element.triggerContextEvent(parameters.getEventType(), parameters.getEventContext(), callback);
    if (!handled)
        throw new TapestryException(String.format("Request event '%s' (on component %s) was not handled; you must provide a matching event handler method in the component or in one of its containers.", parameters.getEventType(), element.getCompleteId()), element, null);
    environment.pop(TrackableComponentEventCallback.class);
    environment.pop(ComponentEventResultProcessor.class);
    // If the result processor was passed a value, then it will already have rendered. Otherwise it was not passed a value,
    // but it's still possible that we still want to do a partial page render ... if filters were added to the render queue.
    // In that event, run the partial page render now and return.
    boolean wasInvoked = resultProcessorInvoked.get();
    if ((!wasInvoked) && queue.isPartialRenderInitialized()) {
        partialRenderer.renderPartialPageMarkup();
        return;
    }
    if (wasInvoked) {
        return;
    }
    // Send an empty JSON reply if no value was returned from the component event handler method.
    // This is the typical behavior when an Ajax component event handler returns null. It still
    // will go through a pipeline that will add information related to partial page rendering.
    resultProcessor.processResultValue(new JSONObject());
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentEventResultProcessor(org.apache.tapestry5.services.ComponentEventResultProcessor) JSONObject(org.apache.tapestry5.json.JSONObject) TrackableComponentEventCallback(org.apache.tapestry5.TrackableComponentEventCallback) Page(org.apache.tapestry5.internal.structure.Page) JSONObject(org.apache.tapestry5.json.JSONObject) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 28 with Service

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

the class TapestryHttpModule method contributeHttpServletRequestHandler.

/**
 * <dl>
 * <dt>StoreIntoGlobals</dt>
 * <dd>Stores the request and response into {@link org.apache.tapestry5.http.services.RequestGlobals} at the start of the
 * pipeline</dd>
 * <dt>IgnoredPaths</dt>
 * <dd>Identifies requests that are known (via the IgnoredPathsFilter service's configuration) to be mapped to other
 * applications</dd>
 * <dt>GZip</dt>
 * <dd>Handles GZIP compression of response streams (if supported by client)</dd>
 * </dl>
 */
public void contributeHttpServletRequestHandler(OrderedConfiguration<HttpServletRequestFilter> configuration, @Symbol(TapestryHttpSymbolConstants.GZIP_COMPRESSION_ENABLED) boolean gzipCompressionEnabled, @Autobuild GZipFilter gzipFilter) {
    HttpServletRequestFilter storeIntoGlobals = new HttpServletRequestFilter() {

        public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler handler) throws IOException {
            requestGlobals.storeServletRequestResponse(request, response);
            return handler.service(request, response);
        }
    };
    configuration.add("StoreIntoGlobals", storeIntoGlobals, "before:*");
    configuration.add("GZIP", gzipCompressionEnabled ? gzipFilter : null);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequestHandler(org.apache.tapestry5.http.services.HttpServletRequestHandler) HttpServletRequestFilter(org.apache.tapestry5.http.services.HttpServletRequestFilter)

Example 29 with Service

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

the class AdvisorStackBuilder method createObject.

@Override
public Object createObject() {
    Object service = delegate.createObject();
    List<ServiceAdvisor> advisors = registry.findAdvisorsForService(serviceDef);
    if (advisors.isEmpty())
        return service;
    final AspectInterceptorBuilder builder = aspectDecorator.createBuilder(serviceDef.getServiceInterface(), service, serviceDef, String.format("<AspectProxy for %s(%s)>", serviceDef.getServiceId(), serviceDef.getServiceInterface().getName()));
    for (final ServiceAdvisor advisor : advisors) {
        registry.run("Invoking " + advisor, new Runnable() {

            @Override
            public void run() {
                advisor.advise(builder);
            }
        });
    }
    return builder.build();
}
Also used : AspectInterceptorBuilder(org.apache.tapestry5.ioc.services.AspectInterceptorBuilder) ServiceAdvisor(org.apache.tapestry5.ioc.ServiceAdvisor)

Example 30 with Service

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

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