use of org.apache.tapestry5.func.Predicate 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