use of org.apache.tapestry5.plastic.FieldConduit in project tapestry-5 by apache.
the class BlockInjectionProvider method provideInjection.
public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
if (!field.getTypeName().equals(BLOCK_TYPE_NAME)) {
return false;
}
Id annotation = field.getAnnotation(Id.class);
String blockId = getBlockId(field.getName(), annotation);
FieldConduit<Object> conduit = createConduit(field, blockId);
field.setConduit(conduit);
// claim the field
return true;
}
use of org.apache.tapestry5.plastic.FieldConduit in project tapestry-5 by apache.
the class BindParameterWorker method createConduit.
private FieldConduit<Object> createConduit(final ComponentResources resources, final String fieldTypeName, final String fieldName, final String[] possibleNames) {
if (!resources.isMixin())
throw new TapestryException(String.format("@BindParameter was used on field '%s' of component class '%s', but @BindParameter should only be used in mixins.", fieldName, resources.getComponentModel().getComponentClassName()), null);
InternalComponentResources containerResources = (InternalComponentResources) resources.getContainerResources();
// Evaluate this early so that we get a fast fail.
String containerParameterName = identifyParameterName(resources, InternalUtils.stripMemberName(fieldName), possibleNames);
Class fieldType = componentClassCache.forName(fieldTypeName);
return new BoundParameterFieldValueConduit(containerParameterName, containerResources, fieldType);
}
use of org.apache.tapestry5.plastic.FieldConduit 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.FieldConduit 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.FieldConduit in project tapestry-5 by apache.
the class InjectContainerWorker method transformField.
private void transformField(PlasticField field) {
InjectContainer annotation = field.getAnnotation(InjectContainer.class);
field.claim(annotation);
ComputedValue<FieldConduit<Object>> provider = createFieldValueConduitProvider(field);
field.setComputedConduit(provider);
}
Aggregations