public Object build(Script script) { // this used to be synchronized, but we also used to remove the // metaclass. Since adding the metaclass is now a side effect, we // don't need to ensure the meta-class won't be observed and don't // need to hide the side effect. MetaClass scriptMetaClass = script.getMetaClass(); script.setMetaClass(new FactoryInterceptorMetaClass(scriptMetaClass, this)); script.setBinding(this); Object oldScriptName = getProxyBuilder().getVariables().get(SCRIPT_CLASS_NAME); try { getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, script.getClass().getName()); return script.run(); } finally { if(oldScriptName != null) { getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, oldScriptName); } else { getProxyBuilder().getVariables().remove(SCRIPT_CLASS_NAME); } } }
protected void rootAttributeDelegate(FactoryBuilderSupport builder, Object node, Map attributes) { Object isRootNode = attributes.remove("rootNode"); if (isRootNode != null && castToBoolean(isRootNode)) { String mvcId = String.valueOf(builder.getVariable(MVC_ID)); builder.getVariables().put(ROOT_NODE_IDENTIFIED_BY_ATTRIBUTE, true); builder.getVariables().put(mvcId + "-rootNode", node); } }
protected void rootNodePostNodeCompletionDelegate(FactoryBuilderSupport builder, Object parent, Object node) { Object hasRootNode = builder.getVariables().get(ROOT_NODE_IDENTIFIED_BY_ATTRIBUTE); if (hasRootNode != null && castToBoolean(hasRootNode)) { return; } String name = String.valueOf(builder.getContext().get(FactoryBuilderSupport.CURRENT_NAME)); if (builder.getVariable(KEY_ROOT_NODE_NAME).equals(name) && builder.hasVariable(MVC_ID)) { String mvcId = String.valueOf(builder.getVariable(MVC_ID)); builder.getVariables().put(mvcId + "-rootNode", node); } } }
public Object getRootNode() { return getBuilder().getVariables().get(getMvcId() + "-rootNode"); } }
@Override protected void destroyMembers(@Nonnull MVCGroup group, boolean fireDestructionEvents) { super.destroyMembers(group, fireDestructionEvents); try { FactoryBuilderSupport builder = (FactoryBuilderSupport) group.getMember(BUILDER); if (builder != null) { builder.dispose(); builder.getVariables().clear(); } } catch (Exception e) { // TODO find out why this call breaks applet mode on shutdown LOG.error("Application encountered an error while destroying group '" + group.getMvcId() + "'", sanitize(e)); } }
public Object build(Script script) { // this used to be synchronized, but we also used to remove the // metaclass. Since adding the metaclass is now a side effect, we // don't need to ensure the meta-class won't be observed and don't // need to hide the side effect. MetaClass scriptMetaClass = script.getMetaClass(); script.setMetaClass(new FactoryInterceptorMetaClass(scriptMetaClass, this)); script.setBinding(this); Object oldScriptName = getProxyBuilder().getVariables().get(SCRIPT_CLASS_NAME); try { getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, script.getClass().getName()); return script.run(); } finally { if(oldScriptName != null) { getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, oldScriptName); } else { getProxyBuilder().getVariables().remove(SCRIPT_CLASS_NAME); } } }