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