use of org.apache.tapestry5.ioc.annotations.Contribute in project tapestry-5 by apache.
the class JSONModule method provideCoercions.
/**
* <ul>
* <li>{@link String} to {@link org.apache.tapestry5.json.JSONObject}</li>
* <li>{@link String} to {@link org.apache.tapestry5.json.JSONArray}</li>
* </ul>
* @param configuration the configuration to provide the type coercer to
*/
@Contribute(TypeCoercer.class)
public static void provideCoercions(MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration) {
CoercionTuple<String, JSONObject> stringToJsonObject = CoercionTuple.create(String.class, JSONObject.class, new StringToJSONObject());
configuration.add(stringToJsonObject.getKey(), stringToJsonObject);
CoercionTuple<String, JSONArray> stringToJsonArray = CoercionTuple.create(String.class, JSONArray.class, new StringToJSONArray());
configuration.add(stringToJsonArray.getKey(), stringToJsonArray);
}
use of org.apache.tapestry5.ioc.annotations.Contribute in project tapestry-5 by apache.
the class AssetsModule method provideBuiltinAssetDispatchers.
/**
* Contributes an handler for each mapped classpath alias, as well handlers for context assets
* and stack assets (combined {@link org.apache.tapestry5.services.javascript.JavaScriptStack} files).
*/
@Contribute(Dispatcher.class)
@AssetRequestDispatcher
public static void provideBuiltinAssetDispatchers(MappedConfiguration<String, AssetRequestHandler> configuration, @ContextProvider AssetFactory contextAssetFactory, @Autobuild StackAssetRequestHandler stackAssetRequestHandler, ClasspathAssetAliasManager classpathAssetAliasManager, ResourceStreamer streamer, AssetSource assetSource, ClasspathAssetProtectionRule classpathAssetProtectionRule) {
Map<String, String> mappings = classpathAssetAliasManager.getMappings();
for (String folder : mappings.keySet()) {
String path = mappings.get(folder);
configuration.add(folder, new ClasspathAssetRequestHandler(streamer, assetSource, path, classpathAssetProtectionRule));
}
configuration.add(RequestConstants.CONTEXT_FOLDER, new ContextAssetRequestHandler(streamer, contextAssetFactory.getRootResource()));
configuration.add(RequestConstants.STACK_FOLDER, stackAssetRequestHandler);
}
use of org.apache.tapestry5.ioc.annotations.Contribute in project tapestry-5 by apache.
the class AssetsModule method configureStandardAssetFactories.
@Contribute(AssetSource.class)
public void configureStandardAssetFactories(MappedConfiguration<String, AssetFactory> configuration, @ContextProvider AssetFactory contextAssetFactory, @ClasspathProvider AssetFactory classpathAssetFactory) {
configuration.add(AssetConstants.CONTEXT, contextAssetFactory);
configuration.add(AssetConstants.CLASSPATH, classpathAssetFactory);
configuration.add(AssetConstants.HTTP, new ExternalUrlAssetFactory(AssetConstants.HTTP));
configuration.add(AssetConstants.HTTPS, new ExternalUrlAssetFactory(AssetConstants.HTTPS));
configuration.add(AssetConstants.FTP, new ExternalUrlAssetFactory(AssetConstants.FTP));
configuration.add(AssetConstants.PROTOCOL_RELATIVE, new ExternalUrlAssetFactory(AssetConstants.PROTOCOL_RELATIVE));
}
use of org.apache.tapestry5.ioc.annotations.Contribute in project tapestry-5 by apache.
the class JpaModule method provideApplicationStateContributions.
@Contribute(ApplicationStateManager.class)
public static void provideApplicationStateContributions(final MappedConfiguration<Class, ApplicationStateContribution> configuration, final EntityManagerSource entityManagerSource, @Symbol(JpaSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED) final boolean entitySessionStatePersistenceStrategyEnabled) {
if (!entitySessionStatePersistenceStrategyEnabled)
return;
for (final PersistenceUnitInfo info : entityManagerSource.getPersistenceUnitInfos()) {
final EntityManagerFactory emf = entityManagerSource.getEntityManagerFactory(info.getPersistenceUnitName());
final Metamodel metamodel = emf.getMetamodel();
for (EntityType<?> entity : metamodel.getEntities()) {
configuration.add(entity.getJavaType(), new ApplicationStateContribution(JpaPersistenceConstants.ENTITY));
}
}
}
use of org.apache.tapestry5.ioc.annotations.Contribute in project tapestry-5 by apache.
the class JpaModule method provideValueEncoders.
@Contribute(ValueEncoderSource.class)
public static void provideValueEncoders(final MappedConfiguration<Class, ValueEncoderFactory> configuration, @Symbol(JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERS) final boolean provideEncoders, final EntityManagerSource entityManagerSource, final EntityManagerManager entityManagerManager, final TypeCoercer typeCoercer, final PropertyAccess propertyAccess, final LoggerSource loggerSource) {
if (!provideEncoders)
return;
for (final PersistenceUnitInfo info : entityManagerSource.getPersistenceUnitInfos()) {
final EntityManagerFactory emf = entityManagerSource.getEntityManagerFactory(info.getPersistenceUnitName());
final Metamodel metamodel = emf.getMetamodel();
for (final EntityType<?> entity : metamodel.getEntities()) {
final Class<?> javaType = entity.getJavaType();
final ValueEncoderFactory factory = new ValueEncoderFactory() {
@Override
public ValueEncoder create(final Class type) {
return new JpaValueEncoder(entity, entityManagerManager, info.getPersistenceUnitName(), propertyAccess, typeCoercer, loggerSource.getLogger(javaType));
}
};
configuration.add(javaType, factory);
}
}
}
Aggregations