use of org.apache.tapestry5.ioc.annotations.Contribute 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:*");
}
use of org.apache.tapestry5.ioc.annotations.Contribute in project tapestry-5 by apache.
the class AssetsModule method setupGlobalMessageCatalog.
/**
* Contributes:
* <dl>
* <dt>ClientLocalization</dt>
* <dd>A virtual resource of formatting symbols for decimal numbers</dd>
* <dt>Core</dt>
* <dd>Built in messages used by Tapestry's default validators and components</dd>
* <dt>AppCatalog</dt>
* <dd>The Resource defined by {@link SymbolConstants#APPLICATION_CATALOG}</dd>
* <dt>
* </dl>
*
* @since 5.2.0
*/
@Contribute(ComponentMessagesSource.class)
public static void setupGlobalMessageCatalog(AssetSource assetSource, @Symbol(SymbolConstants.APPLICATION_CATALOG) Resource applicationCatalog, OrderedConfiguration<Resource> configuration) {
configuration.add("ClientLocalization", new ClientLocalizationMessageResource());
configuration.add("Core", assetSource.resourceForPath("org/apache/tapestry5/core.properties"));
configuration.add("AppCatalog", applicationCatalog);
}
use of org.apache.tapestry5.ioc.annotations.Contribute in project tapestry-5 by apache.
the class TapestryIOCModule method setupStandardSymbolProviders.
/**
* <dl>
* <dt>SystemProperties</dt>
* <dd>Exposes JVM System properties as symbols (currently case-sensitive)</dd>
* <dt>EnvironmentVariables</dt>
* <dd>Exposes environment variables as symbols (adding a "env." prefix)</dd>
* <dt>ApplicationDefaults</dt>
* <dd>Values contributed to @{@link SymbolProvider} @{@link ApplicationDefaults}</dd>
* <dt>FactoryDefaults</dt>
* <dd>Values contributed to @{@link SymbolProvider} @{@link FactoryDefaults}</dd>
* </dl>
*/
@Contribute(SymbolSource.class)
public static void setupStandardSymbolProviders(OrderedConfiguration<SymbolProvider> configuration, @ApplicationDefaults SymbolProvider applicationDefaults, @FactoryDefaults SymbolProvider factoryDefaults) {
configuration.add("SystemProperties", new SystemPropertiesSymbolProvider(), "before:*");
configuration.add("EnvironmentVariables", new SystemEnvSymbolProvider());
configuration.add("ApplicationDefaults", applicationDefaults);
configuration.add("FactoryDefaults", factoryDefaults);
}
use of org.apache.tapestry5.ioc.annotations.Contribute 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());
}
use of org.apache.tapestry5.ioc.annotations.Contribute in project tapestry-5 by apache.
the class DefaultModuleDefImpl method addContributionDef.
private void addContributionDef(Method method) {
Contribute annotation = method.getAnnotation(Contribute.class);
Class serviceInterface = annotation == null ? null : annotation.value();
String serviceId = annotation != null ? null : stripMethodPrefix(method, CONTRIBUTE_METHOD_NAME_PREFIX);
Class returnType = method.getReturnType();
if (!returnType.equals(void.class))
logger.warn(IOCMessages.contributionWrongReturnType(method));
ConfigurationType type = null;
for (Class parameterType : method.getParameterTypes()) {
ConfigurationType thisParameter = PARAMETER_TYPE_TO_CONFIGURATION_TYPE.get(parameterType);
if (thisParameter != null) {
if (type != null)
throw new RuntimeException(IOCMessages.tooManyContributionParameters(method));
type = thisParameter;
}
}
if (type == null)
throw new RuntimeException(IOCMessages.noContributionParameter(method));
Set<Class> markers = extractMarkers(method, Contribute.class, Optional.class);
boolean optional = method.getAnnotation(Optional.class) != null;
ContributionDef3 def = new ContributionDefImpl(serviceId, method, optional, proxyFactory, serviceInterface, markers);
contributionDefs.add(def);
}
Aggregations