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;
}
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());
}
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);
}
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();
}
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);
}
Aggregations