private void initializeAssetsFromPaths(final String[] expandedPaths, PlasticField assetsField, final String libraryName) { assetsField.injectComputed(new ComputedValue<Asset[]>() { public Asset[] get(InstanceContext context) { ComponentResources resources = context.get(ComponentResources.class); return convertPathsToAssetArray(resources, expandedPaths, libraryName); } }); }
public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) { final ResourceProvider provider = configuration.get(field.getTypeName()); if (provider == null) { return false; } field.injectComputed(provider); return true; } }
public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) { Path path = field.getAnnotation(Path.class); if (path == null) { return false; } final String assetPath = path.value(); final String libraryName = componentModel.getLibraryName(); ComputedValue<Asset> computedAsset = new ComputedValue<Asset>() { public Asset get(InstanceContext context) { ComponentResources resources = context.get(ComponentResources.class); // Note how this works: the resources represents the actual instantiated class, and the libraryName // comes from the componentModel, potentially, the componentModel of a base class (which may have // a different library name than the subclass). return assetSource.getComponentAsset(resources, assetPath, libraryName); } }; field.injectComputed(computedAsset); return true; }
@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 void adviseMethod(PlasticClass plasticClass, PlasticMethod method) { // Every instance of the clas srequires its own per-thread value. This handles the case of multiple // pages containing the component, or the same page containing the component multiple times. PlasticField cacheField = plasticClass.introduceField(PerThreadValue.class, "cache$" + method.getDescription().methodName); cacheField.injectComputed(new ComputedValue<PerThreadValue>() { public PerThreadValue get(InstanceContext context) { // Each instance will get a new PerThreadValue return perThreadManager.createValue(); } }); Cached annotation = method.getAnnotation(Cached.class); MethodResultCacheFactory factory = createFactory(plasticClass, annotation.watch(), method); MethodAdvice advice = createAdvice(cacheField, factory); method.addAdvice(advice); }