@Override public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(CommitAfter.class)) { method.addAdvice(advice); } } }
@Override public void transform(final PlasticClass plasticClass) plasticClass.introduceInterface(Serializable.class); final PlasticField creatorField = plasticClass.introduceField(ObjectCreator.class, "creator").inject( creator); final PlasticField tokenField = plasticClass.introduceField(ServiceProxyToken.class, "token").inject( token); PlasticMethod delegateMethod = plasticClass.introducePrivateMethod(serviceInterface.getName(), "delegate", null, null); plasticClass.proxyInterface(serviceInterface, delegateMethod); plasticClass.introduceMethod(WRITE_REPLACE).changeImplementation(new InstructionBuilderCallback() plasticClass.addToString(description);
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (PlasticField field : plasticClass.getFieldsWithAnnotation(Persist.class)) { makeFieldPersistent(field, model); } }
private void implementComponentInterface(PlasticClass plasticClass) { plasticClass.introduceInterface(Component.class); final PlasticField resourcesField = plasticClass.introduceField(InternalComponentResources.class, "internalComponentResources").injectFromInstanceContext(); plasticClass.introduceMethod(GET_COMPONENT_RESOURCES, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { builder.loadThis().getField(resourcesField).returnResult(); } }); }
@Override public void transform(PlasticClass plasticClass) { PlasticField commandsField = plasticClass.introduceField(commandsArray.getClass(), "commands").inject( commandsArray); for (Method method : commandInterface.getMethods()) { implementMethod(plasticClass, method, commandsField); } plasticClass.addToString(String.format("<Command chain of %s>", commandInterface.getName())); } });
private void processClassAnnotationAtSetupRenderPhase(PlasticClass componentClass, MutableComponentModel model) { Import annotation = componentClass.getAnnotation(Import.class); if (annotation != null) { PlasticMethod setupRender = componentClass.introduceMethod(TransformConstants.SETUP_RENDER_DESCRIPTION); decorateMethod(componentClass, model, setupRender, annotation); model.addRenderPhase(SetupRender.class); } }
@Override public void transform(PlasticClass plasticClass) final PlasticField objectCreatorField = plasticClass.introduceField(ObjectCreator.class, "creator") .inject(creator); PlasticMethod delegateMethod = plasticClass.introducePrivateMethod(interfaceTypeName, "delegate", null, null); plasticClass.introduceMethod(method).delegateTo(delegateMethod); plasticClass.introduceMethod(getDelegateMethodDescription, returnCreateObject); plasticClass.addToString(description);
@Override public void transform(PlasticClass plasticClass) final PlasticField registryField = plasticClass.introduceField(StrategyRegistry.class, "registry") .inject(registry); Class<?> interfaceSelectorType = null; plasticClass.introduceMethod(new MethodDescription(method), new InstructionBuilderCallback() plasticClass.addToString(String.format("<Strategy for %s>", interfaceType.getName()));
private void implementListGetter(final Tree listNode) { plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { implementListConstructor(builder, listNode); builder.returnResult(); } }); }
@Override public void transform(PlasticClass plasticClass) final PlasticField objectCreatorField = plasticClass.introduceField(ObjectCreator.class, "creator") .injectFromInstanceContext(); PlasticMethod delegateMethod = plasticClass.introducePrivateMethod(interfaceType.getName(), "delegate", null, null); plasticClass.introduceMethod(method).delegateTo(delegateMethod); if (!plasticClass.isMethodImplemented(PlasticUtils.TO_STRING_DESCRIPTION)) final PlasticField descriptionField = plasticClass.introduceField(String.class, "description") .injectFromInstanceContext(); plasticClass.introduceMethod(PlasticUtils.TO_STRING_DESCRIPTION, new InstructionBuilderCallback()
public void transform(PlasticClass plasticClass) { PlasticMethod delegateMethod = plasticClass.introducePrivateMethod( PlasticUtils.toTypeName(serviceType), "delegate", null, null); delegateMethod.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.setReturnValue(environment.peekRequired(serviceType)); } }); for (Method method : serviceType.getMethods()) { plasticClass.introduceMethod(method).delegateTo(delegateMethod); } plasticClass.addToString(String.format("<EnvironmentalProxy for %s>", serviceType.getName())); } });
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 void addComponentIdValidationLogicOnPageLoad(PlasticClass plasticClass, Flow<EventHandlerMethod> eventHandlerMethods) { ComponentIdValidator[] validators = extractComponentIdValidators(eventHandlerMethods); if (validators.length > 0) { plasticClass.introduceInterface(PageLifecycleListener.class); plasticClass.introduceMethod(TransformConstants.CONTAINING_PAGE_DID_LOAD_DESCRIPTION).addAdvice(new ValidateComponentIds(validators)); } }
@Override public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (final PlasticField field : plasticClass .getFieldsWithAnnotation(PersistenceContext.class)) { final PersistenceContext annotation = field.getAnnotation(PersistenceContext.class); field.claim(annotation); field.setConduit(new ReadOnlyComponentFieldConduit(plasticClass.getClassName(), field.getName()) { @Override public Object get(Object instance, InstanceContext context) { return JpaInternalUtils.getEntityManager(entityManagerManager, annotation); } }); } } }
private void implementOtherMethods() PlasticField annotationProviderField = plasticClass.introduceField(AnnotationProvider.class, "annotationProvider").inject(annotationProvider); plasticClass.introduceMethod(ConduitMethods.GET_ANNOTATION).delegateTo(annotationProviderField); plasticClass.introduceMethod(ConduitMethods.GET_PROPERTY_NAME, new InstructionBuilderCallback() final PlasticField propertyTypeField = plasticClass.introduceField(Class.class, "propertyType").inject( conduitPropertyType); plasticClass.introduceMethod(ConduitMethods.GET_PROPERTY_TYPE, new InstructionBuilderCallback() final PlasticField propertyGenericTypeField = plasticClass.introduceField(Type.class, "propertyGenericType").inject( conduitPropertyGenericType); plasticClass.introduceMethod(ConduitMethods.GET_PROPERTY_GENERIC_TYPE, new InstructionBuilderCallback()
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { Flow<PlasticMethod> methods = findResetMethods(plasticClass); if (!methods.isEmpty()) { if (!plasticClass.isInterfaceImplemented(PageResetListener.class)) { plasticClass.introduceInterface(PageResetListener.class); plasticClass.onConstruct(REGISTER_AS_LISTENER); } invokeMethodsOnPageReset(plasticClass, methods); } }
public void run() String className = plasticClass.getClassName(); String parentClassName = plasticClass.getSuperClassName(); boolean superClassImplementsPageLifecycle = plasticClass.isInterfaceImplemented(PageLifecycleListener.class); if (!superClassImplementsPageLifecycle && plasticClass.isInterfaceImplemented(PageLifecycleListener.class)) plasticClass.onConstruct(REGISTER_AS_PAGE_LIFECYCLE_LISTENER);
/** * Creates the underlying {@link PlasticClassTransformation} for an interface proxy. This should only be * used in the cases where encapsulating the PlasticClass construction into a {@linkplain PlasticClassTransformer * callback} is not feasible (which is the case for some of the older APIs inside Tapestry IoC). * * @param interfaceType * class proxy will extend from * @param implementationType * class that implements interfaceType. It can be null. * @return transformation from which an instantiator may be created */ public <T> PlasticClassTransformation<T> createProxyTransformation(Class interfaceType, Class implementationType) { assert interfaceType != null; if (!interfaceType.isInterface()) throw new IllegalArgumentException(String.format( "Class %s is not an interface; proxies may only be created for interfaces.", interfaceType.getName())); String name = String.format("$%s_%s", interfaceType.getSimpleName(), PlasticUtils.nextUID()); final String implementationClassName = implementationType != null ? implementationType.getName() : null; PlasticClassTransformation<T> result = pool.createTransformation("java.lang.Object", name, implementationClassName); result.getPlasticClass().introduceInterface(interfaceType); return result; }
/** * Defer creation of the delegate field unless actually needed. */ private PlasticField getDelegateField() { if (delegateField == null) delegateField = plasticClass.introduceField(PropertyConduitDelegate.class, "delegate").inject( sharedDelegate); return delegateField; } }
public void transform(final PlasticClass plasticClass, TransformationSupport support, final MutableComponentModel model) { for (final PlasticField field : F.flow(plasticClass.getUnclaimedFields()).filter(MATCHER)) { final String fieldName = field.getName(); tracker.run(String.format("Injecting field %s.%s", plasticClass.getClassName(), fieldName), new Runnable() { public void run() { try { boolean success = injectionProvider.provideInjection(field, locator, model); if (success) { field.claim("@Inject"); } } catch (RuntimeException ex) { throw new RuntimeException(String.format("Error obtaining injected value for field %s.%s: %s", plasticClass.getClassName(), fieldName, ExceptionUtils.toMessage(ex)), ex); } } }); } } }