private void addMethodAssetOperationAdvice(PlasticMethod method, final FieldHandle access, final Worker<Asset> operation) { method.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.proceed(); Asset[] assets = (Asset[]) access.get(invocation.getInstance()); F.flow(assets).each(operation); } }); } }
@Override public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(CommitAfter.class)) { method.addAdvice(advice); } } }
@Override public void adviseMethod(Method method, org.apache.tapestry5.plastic.MethodAdvice advice) { assert method != null; assert advice != null; if (!allMethods.contains(method)) throw new IllegalArgumentException(String.format("Method %s is not defined for interface %s.", method, serviceInterface)); plasticClass.introduceMethod(method).addAdvice(advice); }
private void importStacks(PlasticMethod method, String[] stacks) { if (stacks.length != 0) { method.addAdvice(createImportStackAdvice(stacks)); } }
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(DiscardAfter.class)) { method.addAdvice(advice); } } }
@Override public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(CommitAfter.class)) { method.addAdvice(advice); } } }
private void importModules(PlasticMethod method, String[] moduleNames) { if (moduleNames.length != 0) { method.addAdvice(createImportModulesAdvice(moduleNames)); } }
@Override public void adviseMethod(Method method, org.apache.tapestry5.plastic.MethodAdvice advice) { assert method != null; assert advice != null; if (!allMethods.contains(method)) throw new IllegalArgumentException(String.format("Method %s is not defined for interface %s.", method, serviceInterface)); plasticClass.introduceMethod(method).addAdvice(advice); }
/** * Commits any stored changes to the PlasticClass; this is used to defer adding advice to the dispatch method. */ public void commit() { if (!eventHandlerAdvice.isEmpty()) { PlasticMethod dispatchMethod = plasticClass.introduceMethod(TransformConstants.DISPATCH_COMPONENT_EVENT_DESCRIPTION); for (MethodAdvice advice : eventHandlerAdvice) { dispatchMethod.addAdvice(advice); } } }
void deferMethodInvocations(PlasticMethod method) { validateVoid(method); validateNoCheckedExceptions(method); method.addAdvice(deferredAdvice); }
@Override public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (final PlasticMethod method : plasticClass.getMethodsWithAnnotation(CommitAfter.class)) { PersistenceContext annotation = method.getAnnotation(PersistenceContext.class); method.addAdvice(methodAdvices.get(annotation == null ? null : annotation.unitName())); } } }
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { if (model.getComponentClassName().equals(Form.class.getName())) { PlasticMethod setupRender = plasticClass.introduceMethod(TransformConstants.SETUP_RENDER_DESCRIPTION); setupRender.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { javaScriptSupport.importStack(FormSupportStack.STACK_ID); invocation.proceed(); } }); model.addRenderPhase(SetupRender.class); } } }
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { List<PlasticMethod> methods = plasticClass.getMethodsWithAnnotation(Log.class); if (methods.isEmpty()) { return; } final MethodAdvice loggingAdvice = new LoggingAdvice(model.getLogger(), exceptionTracker); for (PlasticMethod method : methods) { method.addAdvice(loggingAdvice); } } }
@Override public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (final PlasticMethod method : plasticClass .getMethodsWithAnnotation(CommitAfter.class)) { PersistenceContext annotation = method.getAnnotation(PersistenceContext.class); MethodAdvice advice = annotation == null ? shared : new CommitAfterMethodAdvice(manager); method.addAdvice(advice); } } }
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(ReverseStrings.class)) { method.addAdvice(advice); } } }
private void invokeMethodWithinLifecycle(PlasticClass plasticClass, PlasticMethod method) { MethodHandle handle = method.getHandle(); plasticClass.introduceMethod(lifecycleMethodDescription).addAdvice(createAdvice(handle)); }
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 void invokeMethodsOnPageReset(PlasticClass plasticClass, Flow<PlasticMethod> methods) { final MethodHandle[] handles = methods.map(TO_HANDLE).toArray(MethodHandle.class); plasticClass.introduceMethod(TransformConstants.CONTAINING_PAGE_DID_RESET_DESCRIPTION).addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.proceed(); Object instance = invocation.getInstance(); for (MethodHandle handle : handles) { handle.invoke(instance); } } }); }
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(Operation.class)) { Operation annotation = method.getAnnotation(Operation.class); method.addAdvice(advisor.createAdvice(annotation.value())); } } }
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)); } }