Search in sources :

Example 1 with Predicate

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);
            }
        });
    }
}
Also used : FieldConduit(org.apache.tapestry5.plastic.FieldConduit) InstanceContext(org.apache.tapestry5.plastic.InstanceContext) PlasticField(org.apache.tapestry5.plastic.PlasticField) PlasticClass(org.apache.tapestry5.plastic.PlasticClass) Predicate(org.apache.tapestry5.func.Predicate)

Aggregations

Predicate (org.apache.tapestry5.func.Predicate)1 FieldConduit (org.apache.tapestry5.plastic.FieldConduit)1 InstanceContext (org.apache.tapestry5.plastic.InstanceContext)1 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)1 PlasticField (org.apache.tapestry5.plastic.PlasticField)1