Search in sources :

Example 11 with FieldConduit

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;
}
Also used : Id(org.apache.tapestry5.annotations.Id)

Example 12 with FieldConduit

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);
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 13 with FieldConduit

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);
            }
        });
    }
}
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)

Example 14 with FieldConduit

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);
    }
}
Also used : InjectComponent(org.apache.tapestry5.annotations.InjectComponent) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 15 with FieldConduit

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);
}
Also used : InjectContainer(org.apache.tapestry5.annotations.InjectContainer)

Aggregations

InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)6 ComponentResources (org.apache.tapestry5.ComponentResources)5 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)3 InstanceContext (org.apache.tapestry5.plastic.InstanceContext)3 PlasticField (org.apache.tapestry5.plastic.PlasticField)2 Binding (org.apache.tapestry5.Binding)1 BindParameter (org.apache.tapestry5.annotations.BindParameter)1 Environmental (org.apache.tapestry5.annotations.Environmental)1 Id (org.apache.tapestry5.annotations.Id)1 InjectComponent (org.apache.tapestry5.annotations.InjectComponent)1 InjectContainer (org.apache.tapestry5.annotations.InjectContainer)1 PageActivationContext (org.apache.tapestry5.annotations.PageActivationContext)1 Parameter (org.apache.tapestry5.annotations.Parameter)1 Persist (org.apache.tapestry5.annotations.Persist)1 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)1 Predicate (org.apache.tapestry5.func.Predicate)1 LiteralBinding (org.apache.tapestry5.internal.bindings.LiteralBinding)1 MethodNode (org.apache.tapestry5.internal.plastic.asm.tree.MethodNode)1 ReadOnlyComponentFieldConduit (org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit)1 ComputedValue (org.apache.tapestry5.plastic.ComputedValue)1