From f16a5cd623bf73ae80a737e38e025d9354e20ef2 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Tue, 12 Feb 2002 13:23:20 +0000 Subject: [PATCH] Add in nested element processing for scriptdefs git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271296 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/ant/antcore/execution/Frame.java | 8 +++++++- .../org/apache/ant/antlib/script/ScriptBase.java | 16 +++++++++++++++- .../ant/common/service/ComponentService.java | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java index 39a5e057b..41c593aef 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java @@ -943,7 +943,7 @@ public class Frame { throw new ExecutionException("The given ant:refid value '" + refId + "' is not defined", model.getLocation()); } - } else { + } else if (nestedType != null) { // We need to create an instance of the class expected by the nested // element's adder method if that is possible if (nestedType.isInterface()) { @@ -954,6 +954,12 @@ public class Frame { } typeInstance = createTypeInstance(nestedType, factory, model, null); + } else { + throw new ExecutionException("The type of the <" + + nestedElementName + "> nested element is not known. " + + "Please specify by the type using the \"ant:type\" " + + "attribute or provide a reference to an instance with " + + "the \"ant:id\" attribute"); } // is the typeInstance compatible with the type expected diff --git a/proposal/mutant/src/java/antlibs/script/org/apache/ant/antlib/script/ScriptBase.java b/proposal/mutant/src/java/antlibs/script/org/apache/ant/antlib/script/ScriptBase.java index 2af7b619f..d7c2e0248 100644 --- a/proposal/mutant/src/java/antlibs/script/org/apache/ant/antlib/script/ScriptBase.java +++ b/proposal/mutant/src/java/antlibs/script/org/apache/ant/antlib/script/ScriptBase.java @@ -120,9 +120,12 @@ public class ScriptBase extends AbstractTask implements DeferredTask { try { BSFManager manager = new BSFManager(); - + manager.declareBean("self", this, getClass()); + manager.declareBean("context", getContext, AntContext.class); + // execute the script BSFEngine engine = manager.loadScriptingEngine(language); + engine.exec(scriptName, 0, 0, script); for (Iterator i = attributes.keySet().iterator(); i.hasNext(); ) { String attributeName = (String)i.next(); @@ -131,6 +134,17 @@ public class ScriptBase extends AbstractTask implements DeferredTask { setter.setCharAt(0, Character.toUpperCase(setter.charAt(0))); engine.call(null, "set" + setter, new Object[]{value}); } + + Iterator i = nestedElementNames.iterator(); + Iterator j = nestedElements.iterator(); + while (i.hasNext()) { + String nestedName = (String)i.next(); + Object nestedElement = j.next(); + StringBuffer adder = new StringBuffer(nestedName); + adder.setCharAt(0, Character.toUpperCase(adder.charAt(0))); + engine.call(null, "add" + adder, new Object[]{nestedElement}); + } + engine.call(null, "execute", new Object[]{}); } catch (BSFException e) { Throwable t = e; diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java b/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java index b35e571d5..8942e801b 100644 --- a/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java +++ b/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java @@ -95,7 +95,7 @@ public interface ComponentService { void addLibPath(String libraryId, URL libPath) throws ExecutionException; /** - * Experimental - define a new type + * Define a new type * * @param typeName the name by which this type will be referred * @param factory the library factory object to create the type