private String determineSessionKey(PlasticField field, String value) { return value.equals("") ? field.getName() : value; } }
public boolean accept(PlasticField field) { return field.getTypeName().equals("boolean") && field.getName().equalsIgnoreCase(expectedName); } }).toList();
private String getParameterName(PlasticField field, ActivationRequestParameter annotation) { if (annotation.value().equals("")) return field.getName(); return annotation.value(); }
public int compare(PlasticField field1, PlasticField field2) { int index1 = field1.getAnnotation(PageActivationContext.class).index(); int index2 = field2.getAnnotation(PageActivationContext.class).index(); int compare = index1 < index2 ? -1 : (index1 > index2 ? 1 : 0); if (compare == 0) { compare = field1.getName().compareTo(field2.getName()); } return compare; } };
public int compare(PlasticField o1, PlasticField o2) { boolean principal1 = o1.getAnnotation(Parameter.class).principal(); boolean principal2 = o2.getAnnotation(Parameter.class).principal(); if (principal1 == principal2) { return o1.getName().compareTo(o2.getName()); } return principal1 ? -1 : 1; } };
private void replaceFieldAccessWithMixin(PlasticField field, String mixinClassName) { ComputedValue<FieldConduit<Object>> provider = createMixinFieldProvider(field.getName(), mixinClassName); field.setComputedConduit(provider); }
private void convertAccessToField(PlasticField field, String id) { String fieldName = field.getName(); ComputedValue<FieldConduit<Object>> computedConduit = createProviderForEmbeddedComponentConduit(fieldName, id); field.setComputedConduit(computedConduit); }
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); } }; }
private String getComponentId(PlasticField field, InjectComponent annotation) { String id = annotation.value(); if (InternalUtils.isNonBlank(id)) return id; return InternalUtils.stripMemberName(field.getName()); } }
@Override public <F> PlasticField setComputedConduit(ComputedValue<FieldConduit<F>> computedConduit) { assert computedConduit != null; plasticClass.check(); verifyInitialState("set the computed FieldConduit for"); // First step: define a field to store the conduit and add constructor logic // to initialize it PlasticField conduitField = plasticClass.introduceField(FieldConduit.class, node.name + "_FieldConduit").injectComputed( computedConduit); replaceFieldReadAccess(conduitField.getName()); replaceFieldWriteAccess(conduitField.getName()); state = FieldState.CONDUIT; return this; }
@Override public <F> PlasticField setComputedConduit(ComputedValue<FieldConduit<F>> computedConduit) { assert computedConduit != null; plasticClass.check(); verifyInitialState("set the computed FieldConduit for"); // First step: define a field to store the conduit and add constructor logic // to initialize it PlasticField conduitField = plasticClass.introduceField(FieldConduit.class, node.name + "_FieldConduit").injectComputed( computedConduit); replaceFieldReadAccess(conduitField.getName()); replaceFieldWriteAccess(conduitField.getName()); state = FieldState.CONDUIT; 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())); } }
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); return true; // claim the field }
@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 makeFieldPersistent(PlasticField field, MutableComponentModel model) { Persist annotation = field.getAnnotation(Persist.class); field.claim(annotation); final String logicalFieldName = model.setFieldPersistenceStrategy(field.getName(), annotation.value()); final Object defaultValue = determineDefaultValueFromFieldType(field); ComputedValue<FieldConduit<Object>> computed = new ComputedValue<FieldConduit<Object>>() { public FieldConduit<Object> get(InstanceContext context) { InternalComponentResources resources = context.get(InternalComponentResources.class); return new PersistentFieldConduit(resources, logicalFieldName, defaultValue); } }; field.setComputedConduit(computed); }
private void addMixinClasses(PlasticField field, MutableEmbeddedComponentModel model) { MixinClasses annotation = field.getAnnotation(MixinClasses.class); if (annotation == null) return; boolean orderEmpty = annotation.order().length == 0; if (!orderEmpty && annotation.order().length != annotation.value().length) throw new TapestryException(String.format("%d mixins defined via @MixinClasses on field '%s', but %d ordering constraints \\\n" + " specified (expected 0 or %1$d).", annotation.value().length, field.getName(), annotation.order().length), model, null); for (int i = 0; i < annotation.value().length; i++) { String[] constraints = orderEmpty ? InternalConstants.EMPTY_STRING_ARRAY : TapestryInternalUtils .splitMixinConstraints(annotation.order()[i]); model.addMixin(annotation.value()[i].getName(), constraints); } }
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)); } }
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); }