/** * Convience for {@link #add(String, Object[])} */ public void add(String pattern, Object arg0, Object arg1, Object arg2) { add(pattern, new Object[] { arg0, arg1, arg2 }); }
private void addMutator(EnhancementOperation op, String propertyName, Class propertyType, String fieldName, boolean persistent, Location location) { String methodName = EnhanceUtils.createMutatorMethodName(propertyName); BodyBuilder body = new BodyBuilder(); body.begin(); if (persistent) { body.add("org.apache.tapestry.Tapestry#fireObservedChange(this, "); body.addQuoted(propertyName); body.addln(", ($w) $1);"); } body.addln(fieldName + " = $1;"); body.end(); MethodSignature sig = new MethodSignature(void.class, methodName, new Class[] { propertyType }, null); op.addMethod(Modifier.PUBLIC, sig, body.toString(), location); }
/** * Creates a method that delegates to the _delegate object; this is used for * methods that are not logged. */ private void addPassThruMethodImplementation(ClassFab classFab, MethodSignature sig) { BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.add("return ($r) _delegate."); builder.add(sig.getName()); builder.addln("($$);"); builder.end(); classFab.addMethod(Modifier.PUBLIC, sig, builder.toString()); }
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()); }
private void addMutator(EnhancementOperation op, String propertyName, Class propertyType, String fieldName, boolean persistent, Location location) { String methodName = EnhanceUtils.createMutatorMethodName(propertyName); BodyBuilder body = new BodyBuilder(); body.begin(); if (persistent) { body.add("org.apache.tapestry.Tapestry#fireObservedChange(this, "); body.addQuoted(propertyName); body.addln(", ($w) $1);"); } body.addln(fieldName + " = $1;"); body.end(); MethodSignature sig = new MethodSignature(void.class, methodName, new Class[] { propertyType }, null); op.addMethod(Modifier.PUBLIC, sig, body.toString(), location); }
/** * Convience for {@link #add(String, Object[])} */ public void add(String pattern, Object arg0, Object arg1) { add(pattern, new Object[] { arg0, arg1 }); }
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()); }
void injectParameterFlag(EnhancementOperation op, String parameterName, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(parameterName, "parameterName"); Defense.notNull(propertyName, "propertyName"); Class propertyType = op.getPropertyType(propertyName); // null means no property at all; it's just in the XML // which is ok. Otherwise, make sure it is exactly boolean. if (propertyType != null && propertyType != boolean.class) throw new ApplicationRuntimeException("Property " + propertyName + " must be boolean", location, null); op.claimReadonlyProperty(propertyName); BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.add("return isParameterBound("); builder.addQuoted(parameterName); builder.addln(");"); builder.end(); String methodName = op.getAccessorMethodName(propertyName); MethodSignature sig = new MethodSignature(boolean.class, methodName, null, null); op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location); }
/** * @see DefaultLinkRenderer#constructURL(org.apache.tapestry.components.ILinkComponent, * org.apache.tapestry.IRequestCycle) */ protected String constructURL(ILinkComponent component, IRequestCycle cycle) { if (cycle.isRewinding()) { return null; } String anchor = component.getAnchor(); ILink link = component.getLink(cycle); String url = link.getURL(anchor, true); PageRenderSupport support = TapestryUtils.getPageRenderSupport(cycle, component); String functionName = support.getUniqueString("popup_window"); BodyBuilder builder = new BodyBuilder(); builder.addln("{0}=function()", functionName); builder.begin(); builder.add( "var newWindow = window.open({0}, {1}, {2});", TapestryUtils.enquote(url), TapestryUtils.enquote(getWindowName()), TapestryUtils.enquote(getFeatures())); builder.add("newWindow.focus();"); builder.end(); builder.addln(";"); support.addBodyScript(component, builder.toString()); return "javascript:" + functionName + "();"; }
/** * Convience for {@link #add(String, Object[])} */ public void add(String pattern, Object arg0) { add(pattern, new Object[] { arg0 }); }
void injectStateFlag(EnhancementOperation op, String objectName, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(objectName, "objectName"); Defense.notNull(propertyName, "propertyName"); Class propertyType = op.getPropertyType(propertyName); // null means no property at all; it's just in the XML // which is ok. Otherwise, make sure it is exactly boolean. if (propertyType != null && propertyType != boolean.class) throw new ApplicationRuntimeException(EnhanceMessages.mustBeBoolean(propertyName), location, null); op.claimReadonlyProperty(propertyName); String managerField = op.addInjectedField( "_$applicationStateManager", ApplicationStateManager.class, _applicationStateManager); BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.add("return {0}.exists(", managerField); builder.addQuoted(objectName); builder.addln(");"); builder.end(); String methodName = op.getAccessorMethodName(propertyName); MethodSignature sig = new MethodSignature(boolean.class, methodName, null, null); op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location); }
/** @since 1.1 */ private static void addDelegateAccessor(ClassFab classFab, ServicePoint servicePoint, Object delegate) { classFab.addField("_shutdown", boolean.class); Class delegateClass = ClassFabUtils.getInstanceClass(delegate, servicePoint .getServiceInterface()); classFab.addField("_delegate", delegateClass); classFab.addConstructor(new Class[] { delegateClass }, null, "{ super(); _delegate = $1; }"); classFab.addInterface(RegistryShutdownListener.class); if( RegistryShutdownListener.class.isAssignableFrom( delegateClass ) ) { classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class, "registryDidShutdown", null, null), "{ _delegate.registryDidShutdown(); _delegate = null; _shutdown = true; }"); } else { classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class, "registryDidShutdown", null, null), "{ _delegate = null; _shutdown = true; }"); } BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.addln("if (_shutdown)"); builder.addln(" throw org.apache.hivemind.HiveMind#createRegistryShutdownException();"); builder.add("return _delegate;"); builder.end(); classFab.addMethod(Modifier.FINAL | Modifier.PRIVATE, new MethodSignature(delegateClass, DELEGATE_ACCESSOR_METHOD_NAME, null, null), builder.toString()); }
/** * Adds text to the current line, without terminating the line. * * @param pattern * a string pattern, used with * {@link java.text.MessageFormat#format(java.lang.String, java.lang.Object[])} * @param arguments * arguments used witht the format string */ public void add(String pattern, Object[] arguments) { add(MessageFormat.format(pattern, arguments)); }
void injectStateFlag(EnhancementOperation op, String objectName, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(objectName, "objectName"); Defense.notNull(propertyName, "propertyName"); Class propertyType = op.getPropertyType(propertyName); // null means no property at all; it's just in the XML // which is ok. Otherwise, make sure it is exactly boolean. if (propertyType != null && propertyType != boolean.class) throw new ApplicationRuntimeException(EnhanceMessages.mustBeBoolean(propertyName), location, null); op.claimReadonlyProperty(propertyName); String managerField = op.addInjectedField( "_$applicationStateManager", ApplicationStateManager.class, _applicationStateManager); BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.add("return {0}.exists(", managerField); builder.addQuoted(objectName); builder.addln(");"); builder.end(); String methodName = op.getAccessorMethodName(propertyName); MethodSignature sig = new MethodSignature(boolean.class, methodName, null, null); op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location); }
/** * Adds the text to the current line, and terminates the line. */ public void addln(String text) { add(text); newline(); }
/** * We construct a method that always goes through this service model's * {@link #getServiceImplementationForCurrentThread())} method. */ private static void addServiceAccessor(ClassFab classFab, String serviceModelMethodName, ServicePoint servicePoint) { Class serviceInterface = servicePoint.getServiceInterface(); classFab.addField(SERVICE_ACCESSOR_METHOD_NAME, serviceInterface); BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.add("return ("); builder.add(serviceInterface.getName()); builder.add(") _serviceModel."); builder.add(serviceModelMethodName); builder.add("();"); builder.end(); classFab.addMethod(Modifier.PRIVATE | Modifier.FINAL, new MethodSignature(serviceInterface, SERVICE_ACCESSOR_METHOD_NAME, null, null), 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()); }