Browse Source

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
master
Conor MacNeill 23 years ago
parent
commit
f16a5cd623
3 changed files with 23 additions and 3 deletions
  1. +7
    -1
      proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java
  2. +15
    -1
      proposal/mutant/src/java/antlibs/script/org/apache/ant/antlib/script/ScriptBase.java
  3. +1
    -1
      proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java

+ 7
- 1
proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java View File

@@ -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


+ 15
- 1
proposal/mutant/src/java/antlibs/script/org/apache/ant/antlib/script/ScriptBase.java View File

@@ -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;


+ 1
- 1
proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java View File

@@ -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


Loading…
Cancel
Save