private MethodAdvice createAdvice(PlasticField cacheField, final MethodResultCacheFactory factory) final FieldHandle fieldHandle = cacheField.getHandle();
final FieldHandle bindingFieldHandle = plasticClass.introduceField(Binding.class, "cache$watchBinding$" + method.getDescription().methodName).getHandle();
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. }
private void decorateMethodWithOperation(PlasticClass componentClass, MutableComponentModel model, PlasticMethod method, String[] paths, Worker<Asset> operation) { if (paths.length == 0) { return; } String[] expandedPaths = expandPaths(paths); PlasticField assetListField = componentClass.introduceField(Asset[].class, "importedAssets_" + method.getDescription().methodName); initializeAssetsFromPaths(expandedPaths, assetListField, model.getLibraryName()); addMethodAssetOperationAdvice(method, assetListField.getHandle(), operation); }
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); }