use of org.apache.tapestry5.plastic.FieldConduit in project tapestry-5 by apache.
the class BlockInjectionProvider method createConduit.
private FieldConduit<Object> createConduit(PlasticField field, final String blockId) {
final String className = field.getPlasticClass().getClassName();
final String fieldName = field.getName();
return new ReadOnlyComponentFieldConduit(className, fieldName) {
public Object get(Object instance, InstanceContext context) {
ComponentResources resources = context.get(ComponentResources.class);
return resources.getBlock(blockId);
}
};
}
use of org.apache.tapestry5.plastic.FieldConduit in project tapestry-5 by apache.
the class PlasticFieldImpl method replaceFieldReadAccess.
private void replaceFieldReadAccess(String conduitFieldName) {
ensureNotPublic();
boolean writeBehindEnabled = isWriteBehindEnabled();
String getAccessName = plasticClass.makeUnique(plasticClass.methodNames, "conduit_get_" + node.name);
getAccess = new MethodNode(accessForMethod(), getAccessName, "()" + node.desc, null, null);
InstructionBuilder builder = plasticClass.newBuilder(getAccess);
// Get the correct FieldConduit object on the stack
pushFieldConduitOntoStack(conduitFieldName, builder);
builder.loadThis();
// Now push the instance context on the stack
plasticClass.pushInstanceContextFieldOntoStack(builder);
builder.invoke(FieldConduit.class, Object.class, "get", Object.class, InstanceContext.class).castOrUnbox(typeName);
if (writeBehindEnabled) {
if (isWide()) {
// Dupe this under the wide value, then pop the wide value
builder.dupeWide().loadThis().dupe(2).pop();
} else {
builder.dupe().loadThis().swap();
}
// At which point the stack is the result value, this, the result value
builder.putField(plasticClass.className, node.name, typeName);
// And now it is just the result value
}
builder.returnResult();
plasticClass.addMethod(getAccess);
plasticClass.redirectFieldRead(node.name, isPrivate(), getAccess);
}
use of org.apache.tapestry5.plastic.FieldConduit 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.FieldConduit in project tapestry-5 by apache.
the class PageActivationContextWorker method transformFields.
private void transformFields(TransformationSupport support, List<PlasticField> fields) {
List<PlasticField> sortedFields = CollectionFactory.newList(fields);
Collections.sort(sortedFields, INDEX_COMPARATOR);
validateSortedFields(sortedFields);
PlasticField firstField = sortedFields.get(0);
PageActivationContext firstAnnotation = firstField.getAnnotation(PageActivationContext.class);
// these arrays reduce memory usage and allow the PlasticField instances to be garbage collected
FieldHandle[] handles = new FieldHandle[sortedFields.size()];
String[] typeNames = new String[sortedFields.size()];
int i = 0;
for (PlasticField field : sortedFields) {
handles[i] = field.getHandle();
typeNames[i] = field.getTypeName();
++i;
}
if (firstAnnotation.activate()) {
support.addEventHandler(EventConstants.ACTIVATE, 1, "PageActivationContextWorker activate event handler", createActivationHandler(handles, typeNames));
}
if (firstAnnotation.passivate()) {
support.addEventHandler(EventConstants.PASSIVATE, 0, "PageActivationContextWorker passivate event handler", createPassivateHandler(handles));
}
// We don't claim the field, and other workers may even replace it with a FieldConduit.
}
use of org.apache.tapestry5.plastic.FieldConduit 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);
}
Aggregations