Search in sources :

Example 16 with Symbol

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

the class JavaScriptModule method setupCoreJavaScriptStack.

/**
 * The core JavaScriptStack has a number of entries:
 * <dl>
 * <dt>requirejs</dt> <dd>The RequireJS AMD JavaScript library</dd>
 * <dt>scriptaculous.js, effects.js</dt> <dd>Optional JavaScript libraries in compatibility mode (see {@link Trait#SCRIPTACULOUS})</dd>
 * <dt>t53-compatibility.js</dt> <dd>Optional JavaScript library (see {@link Trait#INITIALIZERS})</dd>
 * <dt>underscore-library, underscore-module</dt>
 * <dt>The Underscore JavaScript library, and the shim that allows underscore to be injected</dt>
 * <dt>t5/core/init</dt> <dd>Optional module related to t53-compatibility.js</dd>
 * <dt>jquery-library</dt> <dd>The jQuery library</dd>
 * <dt>jquery-noconflict</dt> <dd>Switches jQuery to no-conflict mode (only present when the infrastructure is "prototype").</dd>
 * <dt>jquery</dt> <dd>A module shim that allows jQuery to be injected (and also switches jQuery to no-conflict mode)</dd>
 * <dt>bootstrap.css, tapestry.css, exception-frame.css, tapestry-console.css, tree.css</dt>
 * <dd>CSS files</dd>
 * <dt>t5/core/[...]</dt>
 * <dd>Additional JavaScript modules</dd>
 * <dt>jquery</dt>
 * <dd>Added if the infrastructure provider is "jquery".</dd>
 * </dl>
 *
 * User modules may replace or extend this list.
 */
@Contribute(JavaScriptStack.class)
@Core
public static void setupCoreJavaScriptStack(OrderedConfiguration<StackExtension> configuration, Compatibility compatibility, @Symbol(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER) String provider) {
    configuration.add("requirejs", StackExtension.library(ROOT + "/require.js"));
    configuration.add("underscore-library", StackExtension.library(ROOT + "/underscore-1.8.3.js"));
    if (provider.equals("prototype")) {
        final String SCRIPTY = "${tapestry.scriptaculous}";
        add(configuration, StackExtensionType.LIBRARY, SCRIPTY + "/prototype.js");
        if (compatibility.enabled(Trait.SCRIPTACULOUS)) {
            add(configuration, StackExtensionType.LIBRARY, SCRIPTY + "/scriptaculous.js", SCRIPTY + "/effects.js");
        }
    }
    if (compatibility.enabled(Trait.INITIALIZERS)) {
        add(configuration, StackExtensionType.LIBRARY, ROOT + "/t53-compatibility.js");
        configuration.add("t5/core/init", new StackExtension(StackExtensionType.MODULE, "t5/core/init"));
    }
    configuration.add("jquery-library", StackExtension.library(ROOT + "/jquery.js"));
    if (provider.equals("prototype")) {
        configuration.add("jquery-noconflict", StackExtension.library(ROOT + "/jquery-noconflict.js"));
    }
    add(configuration, StackExtensionType.MODULE, "jquery");
    add(configuration, StackExtensionType.STYLESHEET, "${" + SymbolConstants.FONT_AWESOME_ROOT + "}/css/font-awesome.css");
    if (compatibility.enabled(Trait.BOOTSTRAP_3) && compatibility.enabled(Trait.BOOTSTRAP_4)) {
        throw new RuntimeException("You cannot have Trait.BOOTSTRAP_3 and Trait.BOOTSTRAP_4 enabled at the same time. Check your contributions to the Compatibility service.");
    }
    if (compatibility.enabled(Trait.BOOTSTRAP_3)) {
        addCoreStylesheets(configuration, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap.css");
    }
    if (compatibility.enabled(Trait.BOOTSTRAP_4)) {
        addCoreStylesheets(configuration, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap.css");
        add(configuration, StackExtensionType.STYLESHEET, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap-grid.css");
    }
    if (!compatibility.enabled(Trait.BOOTSTRAP_3) && !compatibility.enabled(Trait.BOOTSTRAP_4)) {
        configuration.add("defaultcss", StackExtension.stylesheet("${" + SymbolConstants.DEFAULT_STYLESHEET + "}"));
    }
    for (String name : bundledModules) {
        String full = "t5/core/" + name;
        configuration.add(full, StackExtension.module(full));
    }
    configuration.add("underscore-module", StackExtension.module("underscore"));
}
Also used : StackExtension(org.apache.tapestry5.services.javascript.StackExtension) Contribute(org.apache.tapestry5.ioc.annotations.Contribute) Core(org.apache.tapestry5.services.Core)

Example 17 with Symbol

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

the class HibernateModule method contributeValueEncoderSource.

/**
 * Contributes {@link ValueEncoderFactory}s for all registered Hibernate entity classes. Encoding and decoding are
 * based on the id property value of the entity using type coercion. Hence, if the id can be coerced to a String and
 * back then the entity can be coerced.
 */
@SuppressWarnings("unchecked")
public static void contributeValueEncoderSource(MappedConfiguration<Class, ValueEncoderFactory> configuration, @Symbol(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS) boolean provideEncoders, final HibernateSessionSource sessionSource, final Session session, final TypeCoercer typeCoercer, final PropertyAccess propertyAccess, final LoggerSource loggerSource) {
    if (!provideEncoders)
        return;
    Set<EntityType<?>> entities = sessionSource.getSessionFactory().getMetamodel().getEntities();
    for (EntityType<?> entityType : entities) {
        Class<?> entityClass = entityType.getJavaType();
        if (entityClass != null) {
            SingularAttribute<?, ?> id = entityType.getId(entityType.getIdType().getJavaType());
            final String idenfierPropertyName = id.getName();
            ValueEncoderFactory factory = new ValueEncoderFactory() {

                @Override
                public ValueEncoder create(Class type) {
                    return new HibernateEntityValueEncoder(entityClass, idenfierPropertyName, session, propertyAccess, typeCoercer, loggerSource.getLogger(entityClass));
                }
            };
            configuration.add(entityClass, factory);
        }
    }
}
Also used : EntityType(javax.persistence.metamodel.EntityType) HibernateEntityValueEncoder(org.apache.tapestry5.hibernate.web.internal.HibernateEntityValueEncoder) ValueEncoderFactory(org.apache.tapestry5.services.ValueEncoderFactory)

Example 18 with Symbol

use of org.apache.tapestry5.ioc.annotations.Symbol 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));
        }
    }
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) ApplicationStateContribution(org.apache.tapestry5.services.ApplicationStateContribution) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) Metamodel(javax.persistence.metamodel.Metamodel) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 19 with Symbol

use of org.apache.tapestry5.ioc.annotations.Symbol 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);
        }
    }
}
Also used : JpaValueEncoder(org.apache.tapestry5.internal.jpa.JpaValueEncoder) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) Metamodel(javax.persistence.metamodel.Metamodel) ValueEncoderFactory(org.apache.tapestry5.services.ValueEncoderFactory) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

Contribute (org.apache.tapestry5.ioc.annotations.Contribute)7 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 Metamodel (javax.persistence.metamodel.Metamodel)2 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)2 HttpServletRequestFilter (org.apache.tapestry5.http.services.HttpServletRequestFilter)2 ValueEncoderFactory (org.apache.tapestry5.services.ValueEncoderFactory)2 IFn (clojure.lang.IFn)1 Symbol (clojure.lang.Symbol)1 Method (java.lang.reflect.Method)1 Locale (java.util.Locale)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 EntityType (javax.persistence.metamodel.EntityType)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MarkupWriter (org.apache.tapestry5.MarkupWriter)1 StreamResponse (org.apache.tapestry5.StreamResponse)1 ValidationDecorator (org.apache.tapestry5.ValidationDecorator)1 FunctionName (org.apache.tapestry5.clojure.FunctionName)1 Namespace (org.apache.tapestry5.clojure.Namespace)1