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); } } }
@Override @SuppressWarnings("ConstantConditions") protected void adjustMvcArguments(@Nonnull MVCGroup group, @Nonnull Map<String, Object> args) { super.adjustMvcArguments(group, args); FactoryBuilderSupport builder = (FactoryBuilderSupport) group.getMember(BUILDER); args.put(BUILDER, builder); for (Map.Entry<String, Object> variable : args.entrySet()) { builder.setVariable(variable.getKey(), variable.getValue()); } }
@Override protected void initializeMembers(@Nonnull MVCGroup group, @Nonnull Map<String, Object> args) { FactoryBuilderSupport builder = (FactoryBuilderSupport) group.getMember(BUILDER); builder.setVariable(CURRENT_MVCGROUP, group); super.initializeMembers(group, args); }
protected void rootNodePreInstantiateDelegate(FactoryBuilderSupport builder, Map attributes, Object value) { String name = String.valueOf(builder.getContext().get(FactoryBuilderSupport.CURRENT_NAME)); if (!builder.hasVariable(KEY_ROOT_NODE_NAME)) { builder.setVariable(KEY_ROOT_NODE_NAME, name); } }
public void onInitializeMVCGroup(@Nonnull MVCGroupConfiguration configuration, @Nonnull MVCGroup group) { GriffonController controller = group.getController(); if (controller == null) return; FactoryBuilderSupport builder = (FactoryBuilderSupport) group.getMember("builder"); if (builder == null) return; Map<String, Action> actions = application.getActionManager().actionsFor(controller); for (Map.Entry<String, Action> action : actions.entrySet()) { String actionKey = application.getActionManager().normalizeName(action.getKey()) + ActionManager.ACTION; getLog().trace("Adding action {} to {}:{}:builder", actionKey, configuration.getMvcType(), group.getMvcId()); builder.setVariable(actionKey, action.getValue().getToolkitAction()); } } }
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); } } }