use of org.apache.tapestry5.plastic.InstanceContext 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);
}
});
}
}
use of org.apache.tapestry5.plastic.InstanceContext in project tapestry-5 by apache.
the class InjectComponentWorker method transform.
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
for (PlasticField field : plasticClass.getFieldsWithAnnotation(InjectComponent.class)) {
InjectComponent annotation = field.getAnnotation(InjectComponent.class);
field.claim(annotation);
final String type = field.getTypeName();
final String componentId = getComponentId(field, annotation);
final String fieldName = field.getName();
ComputedValue<FieldConduit<Object>> provider = new ComputedValue<FieldConduit<Object>>() {
public FieldConduit<Object> get(InstanceContext context) {
ComponentResources resources = context.get(ComponentResources.class);
return new InjectedComponentFieldValueConduit(resources, fieldName, type, componentId);
}
};
field.setComputedConduit(provider);
}
}
use of org.apache.tapestry5.plastic.InstanceContext in project tapestry-5 by apache.
the class PersistWorker method makeFieldPersistent.
private void makeFieldPersistent(PlasticField field, MutableComponentModel model) {
Persist annotation = field.getAnnotation(Persist.class);
field.claim(annotation);
final String logicalFieldName = model.setFieldPersistenceStrategy(field.getName(), annotation.value());
final Object defaultValue = determineDefaultValueFromFieldType(field);
ComputedValue<FieldConduit<Object>> computed = new ComputedValue<FieldConduit<Object>>() {
public FieldConduit<Object> get(InstanceContext context) {
InternalComponentResources resources = context.get(InternalComponentResources.class);
return new PersistentFieldConduit(resources, logicalFieldName, defaultValue);
}
};
field.setComputedConduit(computed);
}
Aggregations