use of org.apache.tapestry5.plastic.ComputedValue in project tapestry-5 by apache.
the class AssetInjectionProvider method provideInjection.
public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
Path path = field.getAnnotation(Path.class);
if (path == null) {
return false;
}
final String assetPath = path.value();
final String libraryName = componentModel.getLibraryName();
ComputedValue<Asset> computedAsset = new ComputedValue<Asset>() {
public Asset get(InstanceContext context) {
ComponentResources resources = context.get(ComponentResources.class);
// a different library name than the subclass).
return assetSource.getComponentAsset(resources, assetPath, libraryName);
}
};
field.injectComputed(computedAsset);
return true;
}
use of org.apache.tapestry5.plastic.ComputedValue 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.plastic.ComputedValue in project tapestry-5 by apache.
the class BindParameterWorker method convertFieldIntoContainerBoundParameter.
private void convertFieldIntoContainerBoundParameter(PlasticField field) {
BindParameter annotation = field.getAnnotation(BindParameter.class);
field.claim(annotation);
final String[] possibleNames = annotation.value();
final String fieldTypeName = field.getTypeName();
final String fieldName = field.getName();
ComputedValue<FieldConduit<Object>> computedConduit = new ComputedValue<FieldConduit<Object>>() {
public FieldConduit<Object> get(InstanceContext context) {
ComponentResources resources = context.get(ComponentResources.class);
try {
return createConduit(resources, fieldTypeName, fieldName, possibleNames);
} catch (Exception ex) {
throw new TapestryException(String.format("Failure binding parameter field '%s' of mixin %s (type %s): %s", fieldName, resources.getCompleteId(), resources.getComponentModel().getComponentClassName(), ExceptionUtils.toMessage(ex)), ex);
}
}
};
field.setComputedConduit(computedConduit);
}
use of org.apache.tapestry5.plastic.ComputedValue in project tapestry-5 by apache.
the class EnvironmentalWorker method transform.
private void transform(final String componentClassName, PlasticField field) {
Environmental annotation = field.getAnnotation(Environmental.class);
field.claim(annotation);
final String fieldName = field.getName();
final Class fieldType = classCache.forName(field.getTypeName());
final boolean required = annotation.value();
ComputedValue<FieldConduit<Object>> provider = new ComputedValue<FieldConduit<Object>>() {
public FieldConduit<Object> get(InstanceContext context) {
return new EnvironmentalConduit(componentClassName, fieldName, fieldType, required);
}
public void set(Object instance, InstanceContext context, Object newValue) {
throw new RuntimeException(String.format("Field %s of component %s is read only.", fieldName, componentClassName));
}
};
field.setComputedConduit(provider);
}
use of org.apache.tapestry5.plastic.ComputedValue in project tapestry-5 by apache.
the class ParameterWorker method convertFieldIntoParameter.
private void convertFieldIntoParameter(PlasticClass plasticClass, MutableComponentModel model, PlasticField field) {
Parameter annotation = field.getAnnotation(Parameter.class);
String fieldType = field.getTypeName();
String parameterName = getParameterName(field.getName(), annotation.name());
field.claim(annotation);
model.addParameter(parameterName, annotation.required(), annotation.allowNull(), annotation.defaultPrefix(), annotation.cache());
MethodHandle defaultMethodHandle = findDefaultMethodHandle(plasticClass, parameterName);
ComputedValue<FieldConduit<Object>> computedParameterConduit = createComputedParameterConduit(parameterName, fieldType, annotation, defaultMethodHandle);
field.setComputedConduit(computedParameterConduit);
}
Aggregations