private void addPrimitive(EnhancementOperation op, String metaKey, String propertyName, MethodSignature sig, String sourceName, String parser, Location location) { BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.addln("java.lang.String meta = {0}.getComponentProperty(this, \"{1}\");", sourceName, metaKey); builder.addln("return {0}(meta);", parser); builder.end(); op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location); }
/** * Convience for {@link #add(String, Object[])} */ public void add(String pattern, Object arg0, Object arg1) { add(pattern, new Object[] { arg0, arg1 }); }
private BodyBuilder constructorBuilder() { if (_constructorBuilder == null) { _constructorBuilder = new BodyBuilder(); _constructorBuilder.begin(); } return _constructorBuilder; }
public void injectComponent(EnhancementOperation op, String componentId, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(componentId, "componentId"); Defense.notNull(propertyName, "propertyName"); Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null); op.claimReadonlyProperty(propertyName); String fieldName = "_$" + propertyName; String classField = op.getClassReference(propertyType); String locationField = op.addInjectedField(fieldName + "$location", Location.class, location); op.addField(fieldName, propertyType); EnhanceUtils.createSimpleAccessor(op, fieldName, propertyName, propertyType, location); // I.e. _$fred = (IComponent) TapestryUtils.getComponent(this, "fred", // IComponent.class, // location) BodyBuilder builder = new BodyBuilder(); builder.add("{0} = ({1}) ", fieldName, ClassFabUtils .getJavaClassName(propertyType)); builder.add("{0}#getComponent(this, ", TapestryUtils.class.getName()); builder.addQuoted(componentId); builder.add(", {0}, {1});", classField, locationField); op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, builder.toString()); }
/** @since 1.1 */ private void addSerializable(String pointId) { _classFab.addInterface(Serializable.class); BodyBuilder bb = new BodyBuilder(); bb.add( "return {0}.getServiceSerializationSupport().getServiceTokenForService(\"{1}\");", ServiceSerializationHelper.class.getName(), pointId); MethodSignature sig = new MethodSignature(Object.class, "writeReplace", null, null); _classFab.addMethod(Modifier.PRIVATE, sig, bb.toString()); }
private void addInitialValue(EnhancementOperation op, String propertyName, Class propertyType, String fieldName, String initialValue, boolean persistent, Location location) { String description = EnhanceMessages.initialValueForProperty(propertyName); InitialValueBindingCreator creator = new InitialValueBindingCreator(_bindingSource, description, initialValue, location); String creatorField = op.addInjectedField(fieldName + "$initialValueBindingCreator", InitialValueBindingCreator.class, creator); String bindingField = fieldName + "$initialValueBinding"; op.addField(bindingField, IBinding.class); BodyBuilder builder = new BodyBuilder(); builder.addln("{0} = {1}.createBinding(this);", bindingField, creatorField); op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, builder.toString()); builder.clear(); builder.addln("{0} = {1};", fieldName, EnhanceUtils.createUnwrapExpression(op, bindingField, propertyType)); String code = builder.toString(); // In finishLoad() and pageDetach(), de-reference the binding to get the // value // for the property. op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, code); op.extendMethodImplementation(PageDetachListener.class, EnhanceUtils.PAGE_DETACHED_SIGNATURE, code); }
private BodyBuilder createIncompleteMethod(MethodSignature sig) { BodyBuilder result = new BodyBuilder(); // Matched inside finalizeIncompleteMethods() result.begin(); if (existingImplementation(sig)) result.addln("super.{0}($$);", sig.getName()); return result; }
private void finalizeIncompleteMethods() { Iterator i = _incompleteMethods.entrySet().iterator(); while(i.hasNext()) { Map.Entry e = (Map.Entry) i.next(); MethodSignature sig = (MethodSignature) e.getKey(); BodyBuilder builder = (BodyBuilder) e.getValue(); // Each BodyBuilder is created and given a begin(), this is // the matching end() builder.end(); _classFab.addMethod(Modifier.PUBLIC, sig, builder.toString()); } }
void extendCleanupAfterRender(EnhancementOperation op, String fieldName) { BodyBuilder cleanupBody = new BodyBuilder(); cleanupBody.addln("{0} = null;", fieldName); op.extendMethodImplementation(IComponent.class, EnhanceUtils.CLEANUP_AFTER_RENDER_SIGNATURE, cleanupBody.toString()); } }
/** * Convience for {@link #addln(String, Object[])}. */ public void addln(String pattern, Object arg0, Object arg1, Object arg2) { addln(pattern, new Object[] { arg0, arg1, arg2 }); }
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec, Method method, Location location) { Class<?> type = method.getReturnType(); if (type.equals(void.class)) throw new ApplicationRuntimeException( "Cached annotation cannot be used with a method that returns void"); String fieldName = "_$cached$" + method.getName(); MethodSignature signature = new MethodSignature(method); op.addField(fieldName, type); BodyBuilder builder = createCacheMethod(signature, fieldName); op.addMethod(Modifier.PUBLIC, signature, builder.toString(), location); extendCleanupAfterRender(op, fieldName); }
public void injectComponent(EnhancementOperation op, String componentId, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(componentId, "componentId"); Defense.notNull(propertyName, "propertyName"); Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null); op.claimReadonlyProperty(propertyName); String fieldName = "_$" + propertyName; String classField = op.getClassReference(propertyType); String locationField = op.addInjectedField(fieldName + "$location", Location.class, location); op.addField(fieldName, propertyType); EnhanceUtils.createSimpleAccessor(op, fieldName, propertyName, propertyType, location); // I.e. _$fred = (IComponent) TapestryUtils.getComponent(this, "fred", // IComponent.class, // location) BodyBuilder builder = new BodyBuilder(); builder.add("{0} = ({1}) ", fieldName, ClassFabUtils .getJavaClassName(propertyType)); builder.add("{0}#getComponent(this, ", TapestryUtils.class.getName()); builder.addQuoted(componentId); builder.add(", {0}, {1});", classField, locationField); op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, builder.toString()); }
.getAccessorMethodName(propertyName), null, null); BodyBuilder builder = new BodyBuilder(); builder.add("return "); builder.add("({0})", propertyType.getName()); builder.add("getPage().getRequestCycle().getPage(\"{0}\");", pageName); op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);
private void addInitialValue(EnhancementOperation op, String propertyName, Class propertyType, String fieldName, String initialValue, boolean persistent, Location location) { String description = EnhanceMessages.initialValueForProperty(propertyName); InitialValueBindingCreator creator = new InitialValueBindingCreator(_bindingSource, description, initialValue, location); String creatorField = op.addInjectedField(fieldName + "$initialValueBindingCreator", InitialValueBindingCreator.class, creator); String bindingField = fieldName + "$initialValueBinding"; op.addField(bindingField, IBinding.class); BodyBuilder builder = new BodyBuilder(); builder.addln("{0} = {1}.createBinding(this);", bindingField, creatorField); op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, builder.toString()); builder.clear(); builder.addln("{0} = {1};", fieldName, EnhanceUtils.createUnwrapExpression(op, bindingField, propertyType)); String code = builder.toString(); // In finishLoad() and pageDetach(), de-reference the binding to get the // value // for the property. op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, code); op.extendMethodImplementation(PageDetachListener.class, EnhanceUtils.PAGE_DETACHED_SIGNATURE, code); }
private BodyBuilder createIncompleteMethod(MethodSignature sig) { BodyBuilder result = new BodyBuilder(); // Matched inside finalizeIncompleteMethods() result.begin(); if (existingImplementation(sig)) result.addln("super.{0}($$);", sig.getName()); return result; }
private void finalizeIncompleteMethods() { Iterator i = _incompleteMethods.entrySet().iterator(); while(i.hasNext()) { Map.Entry e = (Map.Entry) i.next(); MethodSignature sig = (MethodSignature) e.getKey(); BodyBuilder builder = (BodyBuilder) e.getValue(); // Each BodyBuilder is created and given a begin(), this is // the matching end() builder.end(); _classFab.addMethod(Modifier.PUBLIC, sig, builder.toString()); } }
/** * Convience for {@link #addln(String, Object[])} */ public void addln(String pattern, Object arg0) { addln(pattern, new Object[] { arg0 }); }
private BodyBuilder constructorBuilder() { if (_constructorBuilder == null) { _constructorBuilder = new BodyBuilder(); _constructorBuilder.begin(); } return _constructorBuilder; }
BodyBuilder createCacheMethod(MethodSignature sig, String cacheField) { BodyBuilder result = new BodyBuilder(); result.begin(); result.addln("if (this.{0}==null)", cacheField); result.addln("this.{0} = super.{1}($$);", cacheField, sig.getName()); result.addln("return this.{0};", cacheField); result.end(); return result; }