Search in sources :

Example 41 with Service

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

the class JpaModule method buildEntityManagerManager.

@Scope(ScopeConstants.PERTHREAD)
public static EntityManagerManager buildEntityManagerManager(final EntityManagerSource entityManagerSource, final PerthreadManager perthreadManager, final Logger logger) {
    final EntityManagerManagerImpl service = new EntityManagerManagerImpl(entityManagerSource, logger);
    perthreadManager.addThreadCleanupListener(service);
    return service;
}
Also used : EntityManagerManagerImpl(org.apache.tapestry5.internal.jpa.EntityManagerManagerImpl) Scope(org.apache.tapestry5.ioc.annotations.Scope)

Example 42 with Service

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

the class TranslatorSourceImplTest method name_collision_between_standard_and_alternate_translator.

@Test
public void name_collision_between_standard_and_alternate_translator() {
    Translator t1 = mockTranslator("fred", Integer.class);
    Translator t2 = mockTranslator();
    Map<Class, Translator> configuration = newConfiguration(Integer.class, t1);
    Map<String, Translator> alternates = CollectionFactory.newMap();
    alternates.put("fred", t2);
    replay();
    try {
        new TranslatorSourceImpl(configuration, alternates);
        unreachable();
    } catch (RuntimeException ex) {
        assertEquals(ex.getMessage(), "Translator 'fred' contributed to the TranslatorAlternatesSource service has the same name as a standard Translator contributed to the TranslatorSource service.");
    }
    verify();
}
Also used : Translator(org.apache.tapestry5.Translator) BeforeClass(org.testng.annotations.BeforeClass) Test(org.testng.annotations.Test)

Example 43 with Service

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

the class MongodbModule method contributeTypeCoercer.

/**
 * Contribute coercions for {@link WriteConcern} and {@link ReadPreference} to have them from
 * {@link org.apache.tapestry5.ioc.annotations.Symbol}
 *
 * @param configuration lets help the {@link org.apache.tapestry5.commons.services.TypeCoercer} service
 */
public static void contributeTypeCoercer(MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration) {
    CoercionTuple stringToWriteConcern = new CoercionTuple(String.class, WriteConcern.class, new Coercion<String, WriteConcern>() {

        public WriteConcern coerce(String input) {
            if (input.equalsIgnoreCase("FSYNC_SAFE")) {
                return WriteConcern.FSYNC_SAFE;
            } else if (input.equalsIgnoreCase("JOURNAL_SAFE")) {
                return WriteConcern.JOURNAL_SAFE;
            } else if (input.equalsIgnoreCase("MAJORITY")) {
                return WriteConcern.MAJORITY;
            } else if (input.equalsIgnoreCase("NONE")) {
                return WriteConcern.NONE;
            } else if (input.equalsIgnoreCase("REPLICAS_SAFE")) {
                return WriteConcern.REPLICAS_SAFE;
            } else if (input.equalsIgnoreCase("SAFE")) {
                return WriteConcern.SAFE;
            } else if (input.equalsIgnoreCase("NORMAL")) {
                return WriteConcern.NORMAL;
            } else // WriteConcern.ACKNOWLEDGED IS OUR DEFAULT
            {
                return WriteConcern.ACKNOWLEDGED;
            }
        }
    });
    configuration.add(stringToWriteConcern.getKey(), stringToWriteConcern);
    CoercionTuple stringToReadPreference = new CoercionTuple(String.class, ReadPreference.class, new Coercion<String, ReadPreference>() {

        public ReadPreference coerce(String input) {
            if (input.equalsIgnoreCase("SECONDARY")) {
                return ReadPreference.secondary();
            } else // PRIMARY IS OUR DEFAULT
            {
                return ReadPreference.primary();
            }
        }
    });
    configuration.add(stringToReadPreference.getKey(), stringToReadPreference);
}
Also used : ReadPreference(com.mongodb.ReadPreference) WriteConcern(com.mongodb.WriteConcern) CoercionTuple(org.apache.tapestry5.commons.services.CoercionTuple)

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