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); } }; }
@Override public PlasticMethod delegateTo(final PlasticField field) { plasticClass.check(); assert field != null; assert field.getPlasticClass() == plasticClass; // TODO: Better handling error case where delegating to a primitive or object array. // TODO: Is there a easy way to ensure that the type has the necessary method? I don't // like that errors along those lines may be deferred until execution time. changeImplementation(new InstructionBuilderCallback() { @Override public void doBuild(InstructionBuilder builder) { // Load the field builder.loadThis().getField(field); builder.loadArguments(); invokeDelegateAndReturnResult(builder, field.getTypeName()); } }); return this; }
@Override public PlasticMethod delegateTo(final PlasticField field) { plasticClass.check(); assert field != null; assert field.getPlasticClass() == plasticClass; // TODO: Better handling error case where delegating to a primitive or object array. // TODO: Is there a easy way to ensure that the type has the necessary method? I don't // like that errors along those lines may be deferred until execution time. changeImplementation(new InstructionBuilderCallback() { @Override public void doBuild(InstructionBuilder builder) { // Load the field builder.loadThis().getField(field); builder.loadArguments(); invokeDelegateAndReturnResult(builder, field.getTypeName()); } }); return this; }
private PropertyAccessType toType(PlasticField field) { Property annotation = field.getAnnotation(Property.class); boolean read = annotation.read(); boolean write = annotation.write(); if (read && write) return PropertyAccessType.READ_WRITE; if (read) return PropertyAccessType.READ_ONLY; if (write) return PropertyAccessType.WRITE_ONLY; throw new IllegalArgumentException(String.format( "@Property annotation on %s.%s should have either read() or write() enabled.", field.getPlasticClass() .getClassName(), field.getName())); } }
@Override public InstructionBuilder getField(PlasticField field) { check(); return getField(field.getPlasticClass().getClassName(), field.getName(), field.getTypeName()); }
@Override public InstructionBuilder getField(PlasticField field) { check(); return getField(field.getPlasticClass().getClassName(), field.getName(), field.getTypeName()); }
private void mapFieldToQueryParameter(PlasticField field, TransformationSupport support) { ActivationRequestParameter annotation = field.getAnnotation(ActivationRequestParameter.class); String parameterName = getParameterName(field, annotation); // Assumption: the field type is not one that's loaded by the component class loader, so it's safe // to convert to a hard type during class transformation. Class fieldType = classCache.forName(field.getTypeName()); ValueEncoder encoder = valueEncoderSource.getValueEncoder(fieldType); FieldHandle handle = field.getHandle(); String fieldName = String.format("%s.%s", field.getPlasticClass().getClassName(), field.getName()); setValueFromInitializeEventHandler(support, fieldName, annotation.required(), handle, parameterName, encoder, urlEncoder); decorateLinks(support, fieldName, handle, parameterName, encoder, urlEncoder); preallocateName(support, parameterName); }
private void addInjectedPage(PlasticField field) { InjectPage annotation = field.getAnnotation(InjectPage.class); field.claim(annotation); String pageName = annotation.value(); String fieldName = field.getName(); String injectedPageName = InternalUtils.isBlank(pageName) ? resolver .resolvePageClassNameToPageName(field.getTypeName()) : pageName; field.setConduit(new InjectedPageConduit(field.getPlasticClass().getClassName(), fieldName, injectedPageName)); } }