use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class DefaultInjectionProvider method provideInjection.
public boolean provideInjection(final PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
Class fieldType = classCache.forName(field.getTypeName());
Object injectionValue = masterObjectProvider.provide(fieldType, new AnnotationProvider() {
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return field.getAnnotation(annotationClass);
}
}, this.locator, false);
if (injectionValue != null) {
field.inject(injectionValue);
return true;
}
return false;
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class RegistryImpl method getObject.
@Override
public <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator, Module localModule) {
lock.check();
AnnotationProvider effectiveProvider = annotationProvider != null ? annotationProvider : new NullAnnotationProvider();
// We do a check here for known marker/type combinations, so that you can use a marker
// annotation
// to inject into a contribution method that contributes to MasterObjectProvider.
// We also force a contribution into MasterObjectProvider to accomplish the same thing.
T result = findServiceByMarkerAndType(objectType, annotationProvider, localModule);
if (result != null)
return result;
MasterObjectProvider masterProvider = getService(IOCConstants.MASTER_OBJECT_PROVIDER_SERVICE_ID, MasterObjectProvider.class);
return masterProvider.provide(objectType, effectiveProvider, locator, true);
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class TapestryBeanFactory method resolveDependency.
@Override
public Object resolveDependency(final DependencyDescriptor descriptor, String beanName, Set autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
Class objectType = descriptor.getDependencyType();
final Annotation[] annotations = descriptor.getAnnotations();
if (annotations != null) {
AnnotationProvider provider = new AnnotationProvider() {
@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
for (Object a : annotations) {
if (annotationClass.isInstance(a))
return annotationClass.cast(a);
}
return null;
}
};
if (provider.getAnnotation(Inject.class) != null || provider.getAnnotation(InjectService.class) != null)
return registry.getObject(objectType, provider);
}
return super.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter);
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class EntityManagerObjectProvider method getOrCreateProxy.
@SuppressWarnings({ "unchecked", "rawtypes" })
private EntityManager getOrCreateProxy(final AnnotationProvider annotationProvider, final ObjectLocator objectLocator) {
final PersistenceContext annotation = annotationProvider.getAnnotation(PersistenceContext.class);
final String unitName = annotation == null ? null : annotation.unitName();
EntityManager proxy = emProxyByName.get(unitName);
if (proxy == null)
synchronized (this) {
final PlasticProxyFactory proxyFactory = objectLocator.getService("PlasticProxyFactory", PlasticProxyFactory.class);
proxy = proxyFactory.createProxy(EntityManager.class, new ObjectCreator() {
@Override
public Object createObject() {
final EntityManagerManager entityManagerManager = objectLocator.getService(EntityManagerManager.class);
return JpaInternalUtils.getEntityManager(entityManagerManager, annotation);
}
}, "<EntityManagerProxy>");
emProxyByName.put(unitName, proxy);
}
return proxy;
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_default_translator_with_name_and_null_key.
@Test
public void create_default_translator_with_name_and_null_key() {
Field field = mockField();
Messages messages = mockMessages();
Locale locale = Locale.ENGLISH;
Class propertyType = Map.class;
TranslatorSource ts = mockTranslatorSource();
FormSupport fs = mockFormSupport();
Translator translator = mockTranslator("maptrans", Map.class);
Messages globalMessages = mockMessages();
MessageFormatter formatter = mockMessageFormatter();
MarkupWriter writer = mockMarkupWriter();
String label = "Field Label";
String message = "Woops, did it again.";
AnnotationProvider ap = mockAnnotationProvider(null);
train_findByType(ts, propertyType, translator);
train_getFormValidationId(fs, "myform");
train_contains(messages, "myform-myfield-maptrans-message", false);
train_contains(messages, "myfield-maptrans-message", false);
train_getMessageKey(translator, null);
train_getMessageFormatter(globalMessages, "maptrans-message", formatter);
train_getLabel(field, label);
train_format(formatter, message, label);
translator.render(field, message, writer, fs);
replay();
FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, globalMessages, fs);
FieldTranslator ft = source.createDefaultTranslator(field, "myfield", messages, locale, propertyType, ap);
assertEquals(ft.getType(), Map.class);
ft.render(writer);
verify();
}
Aggregations