jstrachan 2003/01/18 01:49:12
Modified: jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/tags/ant
AntTag.java
Log:
Fixed the protocol to deduce if a tag should be treated as an Ant task, data type or
nested property to work with CVS HEAD of Ant.
Thanks to Gump for spotting this!
Revision Changes Path
1.21 +75 -58
jakarta-commons-sandbox/jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/tags/ant/AntTag.java
Index: AntTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/tags/ant/AntTag.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- AntTag.java 25 Nov 2002 14:31:56 -0000 1.20
+++ AntTag.java 18 Jan 2003 09:49:12 -0000 1.21
@@ -161,70 +161,81 @@
// also its possible to have a root Ant tag which isn't a task, such as when
// defining <fileset id="...">...</fileset>
- if ( (parentTask == null || parentTask instanceof TaskContainer) &&
- project.getTaskDefinitions().containsKey( tagName )) {
-
- if ( log.isDebugEnabled() ) {
- log.debug( "Creating an ant Task for name: " + tagName );
- }
-
- // the following algorithm follows the lifetime of a tag
- // http://jakarta.apache.org/ant/manual/develop.html#writingowntask
- // kindly recommended by Stefan Bodewig
-
- // create and set its project reference
+ Object nested = null;
+ if (parentObject != null && !( parentTask instanceof TaskContainer) ) {
+ nested = createNestedObject( parentObject, tagName );
+ }
+
+ if (nested == null) {
task = createTask( tagName );
- if ( task instanceof TaskAdapter ) {
- setObject( ((TaskAdapter)task).getProxy() );
- }
- else {
- setObject( task );
- }
-
- // set the task ID if one is given
- Object id = getAttributes().remove( "id" );
- if ( id != null ) {
- project.addReference( (String) id, task );
- }
-
- // ### we might want to spoof a Target setting here
-
- // now lets initialize
- task.init();
-
- // now lets invoke the body to call all the createXXX() or addXXX()
methods
- String body = getBodyText();
+
+ if (task != null) {
- // now lets set any attributes of this tag...
- setBeanProperties();
-
- // now lets set the addText() of the body content, if its applicaable
- Method method = MethodUtils.getAccessibleMethod( task.getClass(),
- "addText",
- addTaskParamTypes );
- if (method != null) {
- Object[] args = { body };
- method.invoke(this.task, args);
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Creating an ant Task for name: " + tagName );
+ }
+
+ // the following algorithm follows the lifetime of a tag
+ // http://jakarta.apache.org/ant/manual/develop.html#writingowntask
+ // kindly recommended by Stefan Bodewig
+
+ // create and set its project reference
+ if ( task instanceof TaskAdapter ) {
+ setObject( ((TaskAdapter)task).getProxy() );
+ }
+ else {
+ setObject( task );
+ }
+
+ // set the task ID if one is given
+ Object id = getAttributes().remove( "id" );
+ if ( id != null ) {
+ project.addReference( (String) id, task );
+ }
+
+ // ### we might want to spoof a Target setting here
+
+ // now lets initialize
+ task.init();
+
+ // now lets invoke the body to call all the createXXX() or addXXX()
methods
+ String body = getBodyText();
+
+ // now lets set any attributes of this tag...
+ setBeanProperties();
+
+ // now lets set the addText() of the body content, if its
applicaable
+ Method method = MethodUtils.getAccessibleMethod( task.getClass(),
+ "addText",
+ addTaskParamTypes
);
+ if (method != null) {
+ Object[] args = { body };
+ method.invoke(this.task, args);
+ }
+
+ // now lets set all the attributes of the child elements
+ // XXXX: to do!
+
+ // now we're ready to invoke the task
+ // XXX: should we call execute() or perform()?
+ task.perform();
}
-
- // now lets set all the attributes of the child elements
- // XXXX: to do!
-
- // now we're ready to invoke the task
- // XXX: should we call execute() or perform()?
- task.perform();
}
- else {
-
- if ( log.isDebugEnabled() ) {
- log.debug( "Creating a nested object name: " + tagName );
- }
+
+ if (task == null) {
- Object nested = createNestedObject( parentObject, tagName );
-
- if ( nested == null ) {
+ if (nested == null) {
+
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Trying to create a data type for tag: " + tagName
);
+ }
nested = createDataType( tagName );
}
+ else {
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Created nested property tag: " + tagName );
+ }
+ }
if ( nested != null ) {
setObject( nested );
@@ -276,6 +287,8 @@
}
}
else {
+ log.warn("Could not convert tag: " + tagName + " into an Ant task,
data type or property");
+
// lets treat this tag as static XML...
StaticTag tag = new StaticTag("", tagName, tagName);
tag.setParent( getParent() );
@@ -312,7 +325,11 @@
}
public Project getAntProject() {
- return AntTagLibrary.getProject(context);
+ Project project = AntTagLibrary.getProject(context);
+ if (project == null) {
+ throw new NullPointerException("No Ant Project object is available");
+ }
+ return project;
}
// Implementation methods
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>