use of org.apache.tapestry5.plastic.PlasticField in project tapestry-5 by apache.
the class CDIInjectionProvider method provideInjection.
/* (non-Javadoc)
* @see org.apache.tapestry5.services.transform.InjectionProvider2#provideInjection(org.apache.tapestry5.plastic.PlasticField, org.apache.tapestry5.ioc.ObjectLocator, org.apache.tapestry5.model.MutableComponentModel)
*/
@SuppressWarnings("rawtypes")
public boolean provideInjection(final PlasticField field, final ObjectLocator locator, final MutableComponentModel componentModel) {
Class type = cache.forName(field.getTypeName());
if (InternalUtils.isManagedByTapestry(type, new AnnotationProvider() {
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return field.getAnnotation(annotationClass);
}
}, locator)) {
logger.debug("Field " + field.getName() + " of type " + field.getTypeName() + " is managed by Tapestry");
return false;
}
logger.debug("Field " + field.getName() + " of type " + field.getTypeName() + " will be managed by CDI");
final Class<?> fieldClass = load(field.getTypeName());
final Annotation[] qualifiers = InternalUtils.getFieldQualifiers(type, new AnnotationProvider() {
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return field.getAnnotation(annotationClass);
}
});
logger.debug("[" + field.getName() + "][" + componentModel.getComponentClassName() + "] Qualifiers : ");
for (Annotation annotation : qualifiers) {
logger.debug("==> " + annotation.toString());
}
try {
final BeanInstance instance = getInstance(fieldClass, qualifiers);
final boolean resolved = instance != null && instance.isResolved();
if (resolved) {
field.inject(instance.getBean());
}
if (instance != null && instance.isReleasable()) {
synchronized (instancesToRelease) {
instancesToRelease.add(instance);
}
}
logger.debug("Is field " + field.getName() + " of type " + field.getTypeName() + " has been succesfully managed by CDI ? " + resolved);
return resolved;
} catch (IllegalStateException isa) {
logger.debug("CDI failed to manage the field " + field.getName() + " of type " + field.getTypeName());
return false;
}
}
use of org.apache.tapestry5.plastic.PlasticField in project tapestry-5 by apache.
the class TestInjectTransformer method transform.
@Override
public void transform(PlasticClass plasticClass) {
for (PlasticField f : plasticClass.getFieldsWithAnnotation(TestInject.class)) {
if (f.getTypeName().equals(className)) {
f.inject(fieldValue);
f.claim(this);
}
}
}
use of org.apache.tapestry5.plastic.PlasticField in project tapestry-5 by apache.
the class CachedWorker method adviseMethod.
private void adviseMethod(PlasticClass plasticClass, PlasticMethod method) {
// Every instance of the clas srequires its own per-thread value. This handles the case of multiple
// pages containing the component, or the same page containing the component multiple times.
PlasticField cacheField = plasticClass.introduceField(PerThreadValue.class, "cache$" + method.getDescription().methodName);
cacheField.injectComputed(new ComputedValue<PerThreadValue>() {
public PerThreadValue get(InstanceContext context) {
// Each instance will get a new PerThreadValue
return perThreadManager.createValue();
}
});
Cached annotation = method.getAnnotation(Cached.class);
MethodResultCacheFactory factory = createFactory(plasticClass, annotation.watch(), method);
MethodAdvice advice = createAdvice(cacheField, factory);
method.addAdvice(advice);
}
use of org.apache.tapestry5.plastic.PlasticField in project tapestry-5 by apache.
the class ComponentWorker method transformField.
private void transformField(PlasticClass transformation, MutableComponentModel model, PlasticField field) {
Component annotation = field.getAnnotation(Component.class);
field.claim(annotation);
String annotationId = annotation.id();
String fieldName = field.getName();
String id = InternalUtils.isNonBlank(annotationId) ? annotationId : InternalUtils.stripMemberName(fieldName);
String type = field.getTypeName();
Location location = new StringLocation(String.format("%s.%s", transformation.getClassName(), fieldName), 0);
MutableEmbeddedComponentModel embedded = model.addEmbeddedComponent(id, annotation.type(), type, annotation.inheritInformalParameters(), location);
addParameters(embedded, annotation.parameters());
updateModelWithPublishedParameters(embedded, annotation);
convertAccessToField(field, id);
addMixinClasses(field, embedded);
addMixinTypes(field, embedded);
}
use of org.apache.tapestry5.plastic.PlasticField in project tapestry-5 by apache.
the class ComponentWorker method addMixinClasses.
private void addMixinClasses(PlasticField field, MutableEmbeddedComponentModel model) {
MixinClasses annotation = field.getAnnotation(MixinClasses.class);
if (annotation == null)
return;
boolean orderEmpty = annotation.order().length == 0;
if (!orderEmpty && annotation.order().length != annotation.value().length)
throw new TapestryException(String.format("%d mixins defined via @MixinClasses on field '%s', but %d ordering constraints \\\n" + " specified (expected 0 or %1$d).", annotation.value().length, field.getName(), annotation.order().length), model, null);
for (int i = 0; i < annotation.value().length; i++) {
String[] constraints = orderEmpty ? CommonsUtils.EMPTY_STRING_ARRAY : TapestryInternalUtils.splitMixinConstraints(annotation.order()[i]);
model.addMixin(annotation.value()[i].getName(), constraints);
}
}
Aggregations