use of org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit in project tapestry-5 by apache.
the class BlockInjectionProvider method createConduit.
private FieldConduit<Object> createConduit(PlasticField field, final String blockId) {
final String className = field.getPlasticClass().getClassName();
final String fieldName = field.getName();
return new ReadOnlyComponentFieldConduit(className, fieldName) {
public Object get(Object instance, InstanceContext context) {
ComponentResources resources = context.get(ComponentResources.class);
return resources.getBlock(blockId);
}
};
}
use of org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit in project tapestry-5 by apache.
the class MixinWorker method createMixinFieldProvider.
private ComputedValue<FieldConduit<Object>> createMixinFieldProvider(final String fieldName, final String mixinClassName) {
return new ComputedValue<FieldConduit<Object>>() {
public FieldConduit get(InstanceContext context) {
ComponentResources resources = context.get(ComponentResources.class);
final InternalComponentResources icr = (InternalComponentResources) resources;
return new ReadOnlyComponentFieldConduit(resources, fieldName) {
public Object get(Object instance, InstanceContext context) {
return icr.getMixinByClassName(mixinClassName);
}
};
}
};
}
use of org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit in project tapestry-5 by apache.
the class InjectContainerWorker method createFieldValueConduitProvider.
private ComputedValue<FieldConduit<Object>> createFieldValueConduitProvider(PlasticField field) {
final String fieldName = field.getName();
final String fieldTypeName = field.getTypeName();
return new ComputedValue<FieldConduit<Object>>() {
public FieldConduit<Object> get(InstanceContext context) {
final Class fieldType = cache.forName(fieldTypeName);
final ComponentResources resources = context.get(ComponentResources.class);
return new ReadOnlyComponentFieldConduit(resources, fieldName) {
public Object get(Object instance, InstanceContext context) {
Component container = resources.getContainer();
if (!fieldType.isInstance(container)) {
String message = String.format("Component %s (type %s) is not assignable to field %s.%s (of type %s).", container.getComponentResources().getCompleteId(), container.getClass().getName(), resources.getComponentModel().getComponentClassName(), fieldName, fieldTypeName);
throw new RuntimeException(message);
}
return container;
}
};
}
};
}
use of org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit in project tapestry-5 by apache.
the class PersistenceContextWorker method transform.
@Override
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
for (final PlasticField field : plasticClass.getFieldsWithAnnotation(PersistenceContext.class)) {
final PersistenceContext annotation = field.getAnnotation(PersistenceContext.class);
field.claim(annotation);
field.setConduit(new ReadOnlyComponentFieldConduit(plasticClass.getClassName(), field.getName()) {
@Override
public Object get(Object instance, InstanceContext context) {
return JpaInternalUtils.getEntityManager(entityManagerManager, annotation);
}
});
}
}
use of org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit in project tapestry-5 by apache.
the class ApplicationStateWorker method transform.
@SuppressWarnings("unchecked")
private void transform(PlasticClass transformation, PlasticField field, final boolean create) {
final Class fieldClass = componentClassCache.forName(field.getTypeName());
field.setConduit(new FieldConduit() {
public void set(Object instance, InstanceContext context, Object newValue) {
applicationStateManager.set(fieldClass, newValue);
}
public Object get(Object instance, InstanceContext context) {
return create ? applicationStateManager.get(fieldClass) : applicationStateManager.getIfExists(fieldClass);
}
});
final String expectedName = field.getName() + "Exists";
List<PlasticField> fields = F.flow(transformation.getAllFields()).filter(new Predicate<PlasticField>() {
public boolean accept(PlasticField field) {
return field.getTypeName().equals("boolean") && field.getName().equalsIgnoreCase(expectedName);
}
}).toList();
for (PlasticField existsField : fields) {
existsField.claim(this);
final String className = transformation.getClassName();
final String fieldName = existsField.getName();
existsField.setConduit(new ReadOnlyComponentFieldConduit(className, fieldName) {
public Object get(Object instance, InstanceContext context) {
return applicationStateManager.exists(fieldClass);
}
});
}
}
Aggregations