conor 2003/01/18 06:21:02
Modified: src/main/org/apache/tools/ant/helper ProjectHelper2.java
Added: src/main/org/apache/tools/ant/helper AntXMLContext.java
Log:
Factor out XML Context into its own class
Clean up style conformance in ProjectHelper2
Revision Changes Path
1.14 +200 -313
jakarta-ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
Index: ProjectHelper2.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -u -r1.13 -r1.14
--- ProjectHelper2.java 17 Jan 2003 10:27:12 -0000 1.13
+++ ProjectHelper2.java 18 Jan 2003 14:21:02 -0000 1.14
@@ -60,7 +60,6 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Hashtable;
-import java.util.Vector;
import java.util.Stack;
import java.util.Locale;
@@ -82,6 +81,8 @@
import org.apache.tools.ant.Location;
import org.apache.tools.ant.UnknownElement;
+import org.xml.sax.XMLReader;
+
/**
* Sax2 based project reader
*
@@ -92,10 +93,10 @@
/* Stateless */
// singletons - since all state is in the context
- static AntHandler elementHandler=new ElementHandler();
- static AntHandler targetHandler=new TargetHandler();
- static AntHandler mainHandler=new MainHandler();
- static AntHandler projectHandler=new ProjectHandler();
+ private static AntHandler elementHandler = new ElementHandler();
+ private static AntHandler targetHandler = new TargetHandler();
+ private static AntHandler mainHandler = new MainHandler();
+ private static AntHandler projectHandler = new ProjectHandler();
/**
* helper for path -> URI and URI -> path conversions.
@@ -103,46 +104,46 @@
private static FileUtils fu = FileUtils.newFileUtils();
public void parse(Project project, Object source)
- throws BuildException
- {
+ throws BuildException {
this.getImportStack().addElement(source);
//System.out.println("Adding " + source);
- AntXmlContext context=null;
- context=(AntXmlContext)project.getReference("ant.parsing.context");
+ AntXMLContext context = null;
+ context = (AntXMLContext)
project.getReference("ant.parsing.context");
// System.out.println("Parsing " + getImportStack().size() + " " +
// context+ " " + getImportStack() );
if (context==null ) {
- context=new AntXmlContext(project, this);
+ context = new AntXMLContext(project);
project.addReference( "ant.parsing.context", context );
- project.addReference( "ant.targets", context.targetVector );
+ project.addReference("ant.targets", context.getTargets());
}
if (this.getImportStack().size() > 1 ) {
// we are in an imported file.
- context.ignoreProjectTag=true;
+ context.setIgnoreProjectTag(true);
parse(project, source, new RootHandler(context));
} else {
// top level file
parse(project, source,new RootHandler(context));
// Execute the top-level target
- context.implicitTarget.execute();
+ context.getImplicitTarget().execute();
}
}
/**
* Parses the project file, configuring the project as it goes.
*
- * @exception org.apache.tools.ant.BuildException if the configuration
is invalid or cannot
+ * @exception BuildException if the configuration is invalid or cannot
* be read
*/
public void parse(Project project, Object source, RootHandler handler)
- throws BuildException
- {
+ throws BuildException {
+
+ AntXMLContext context = handler.context;
- AntXmlContext context=handler.context;
+ File buildFile = null;
if(source instanceof File) {
- context.buildFile=(File)source;
+ buildFile = (File) source;
// } else if (source instanceof InputStream ) {
// } else if (source instanceof URL ) {
// } else if (source instanceof InputSource ) {
@@ -154,32 +155,33 @@
FileInputStream inputStream = null;
InputSource inputSource = null;
- context.buildFile = new File(context.buildFile.getAbsolutePath());
- context.buildFileParent = new File(context.buildFile.getParent());
+ buildFile = new File(buildFile.getAbsolutePath());
+ context.setBuildFile(buildFile);
try {
/**
* SAX 2 style parser used to parse the given file.
*/
- context.parser =JAXPUtils.getNamespaceXMLReader();
+ XMLReader parser = JAXPUtils.getNamespaceXMLReader();
- String uri = fu.toURI(context.buildFile.getAbsolutePath());
+ String uri = fu.toURI(buildFile.getAbsolutePath());
- inputStream = new FileInputStream(context.buildFile);
+ inputStream = new FileInputStream(buildFile);
inputSource = new InputSource(inputStream);
inputSource.setSystemId(uri);
- project.log("parsing buildfile " + context.buildFile + " with
URI = " + uri, Project.MSG_VERBOSE);
+ project.log("parsing buildfile " + buildFile
+ + " with URI = " + uri, Project.MSG_VERBOSE);
DefaultHandler hb = handler;
- context.parser.setContentHandler(hb);
- context.parser.setEntityResolver(hb);
- context.parser.setErrorHandler(hb);
- context.parser.setDTDHandler(hb);
- context.parser.parse(inputSource);
+ parser.setContentHandler(hb);
+ parser.setEntityResolver(hb);
+ parser.setErrorHandler(hb);
+ parser.setDTDHandler(hb);
+ parser.parse(inputSource);
} catch(SAXParseException exc) {
- Location location =
- new Location(exc.getSystemId(), exc.getLineNumber(),
exc.getColumnNumber());
+ Location location = new Location(exc.getSystemId(),
+ exc.getLineNumber(), exc.getColumnNumber());
Throwable t = exc.getException();
if (t instanceof BuildException) {
@@ -191,29 +193,25 @@
}
throw new BuildException(exc.getMessage(), t, location);
- }
- catch(SAXException exc) {
+ } catch (SAXException exc) {
Throwable t = exc.getException();
if (t instanceof BuildException) {
throw (BuildException) t;
}
throw new BuildException(exc.getMessage(), t);
- }
- catch(FileNotFoundException exc) {
+ } catch (FileNotFoundException exc) {
throw new BuildException(exc);
- }
- catch(UnsupportedEncodingException exc) {
- throw new BuildException("Encoding of project file is
invalid.",exc);
- }
- catch(IOException exc) {
- throw new BuildException("Error reading project file: "
+exc.getMessage(), exc);
- }
- finally {
+ } catch (UnsupportedEncodingException exc) {
+ throw new BuildException("Encoding of project file is
invalid.",
+ exc);
+ } catch (IOException exc) {
+ throw new BuildException("Error reading project file: "
+ + exc.getMessage(), exc);
+ } finally {
if (inputStream != null) {
try {
inputStream.close();
- }
- catch (IOException ioe) {
+ } catch (IOException ioe) {
// ignore this
}
}
@@ -230,21 +228,21 @@
*/
public static class AntHandler {
/**
- * Handles the start of an element. This base implementation does
nothing.
+ * Handles the start of an element. This base implementation does
+ * nothing.
*
* @param tag The name of the element being started.
* Will not be <code>null</code>.
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
*
- * @exception org.xml.sax.SAXParseException if this method is not
overridden, or in
+ * @exception SAXParseException if this method is not overridden, or
in
* case of error in an overridden
version
*/
public void onStartElement(String uri, String tag, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
}
/**
@@ -257,28 +255,28 @@
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
*
- * @exception org.xml.sax.SAXParseException if this method is not
overridden, or in
+ * @exception SAXParseException if this method is not overridden, or
in
* case of error in an overridden
version
*/
public AntHandler onStartChild(String uri, String tag, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
- throw new SAXParseException("Unexpected element \"" + qname + "
\"", context.locator);
+ AntXMLContext context)
+ throws SAXParseException {
+ throw new SAXParseException("Unexpected element \"" + qname
+ + " \"", context.getLocator());
}
public void onEndChild(String uri, String tag, String qname,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
}
/**
* Called when this element and all elements nested into it have been
* handled (i.e. at the </end_tag_of_the_element> ).
*/
- public void onEndElement(String uri, String tag, AntXmlContext
context) {
+ public void onEndElement(String uri, String tag,
+ AntXMLContext context) {
}
/**
@@ -290,139 +288,29 @@
* @param start The start element in the array.
* @param count The number of characters to read from the array.
*
- * @exception org.xml.sax.SAXParseException if this method is not
overridden, or in
+ * @exception SAXParseException if this method is not overridden, or
in
* case of error in an overridden
version
*/
- public void characters(char[] buf, int start, int count,
AntXmlContext context)
- throws SAXParseException
- {
+ public void characters(char[] buf, int start, int count,
AntXMLContext context)
+ throws SAXParseException {
String s = new String(buf, start, count).trim();
if (s.length() > 0) {
- throw new SAXParseException("Unexpected text \"" + s + "\"",
context.locator);
+ throw new SAXParseException("Unexpected text \"" + s
+ + "\"", context.getLocator());
}
}
- /** Will be called every time a namespace is reached.
- It'll verify if the ns was processed, and if not load the task
definitions.
- */
- protected void checkNamespace( String uri ) {
-
- }
- }
-
- /** Context information for the ant processing.
- */
- public static class AntXmlContext {
- /** The project to configure. */
- public Project project;
-
- /** The configuration file to parse. */
- public File buildFile;
-
- /** Vector with all the targets, in the order they are
- * defined. Project maintains a Hashtable, which is not ordered.
- * This will allow description to know the original order.
- */
- public Vector targetVector=new Vector();
-
- /**
- * Parent directory of the build file. Used for resolving entities
- * and setting the project's base directory.
- */
- public File buildFileParent;
-
- /** Name of the current project */
- public String currentProjectName;
-
/**
- * Locator for the configuration file parser.
- * Used for giving locations of errors etc.
- */
- public Locator locator;
-
- // Do we need those ?
- public ProjectHelper2 helper;
-
- org.xml.sax.XMLReader parser;
-
- /**
- * Target that all other targets will depend upon implicitly.
- *
- * <p>This holds all tasks and data type definitions that have
- * been placed outside of targets.</p>
- */
- public Target implicitTarget = new Target();
-
- /** Current target ( no need for a stack as the processing model
- allows only one level of target ) */
- public Target currentTarget=null;
-
- /** The stack of RuntimeConfigurable2 wrapping the
- objects.
+ * Will be called every time a namespace is reached.
+ * It'll verify if the ns was processed, and if not load the task
+ * definitions.
*/
- public Vector wStack=new Vector();
-
- public Hashtable namespaces=new Hashtable();
-
- // Import stuff
- public boolean ignoreProjectTag=false;
- public Hashtable importedFiles = new Hashtable();
- public int importlevel = 0;
-
- public AntXmlContext(Project project, ProjectHelper2 helper) {
- this.project=project;
- implicitTarget.setName("");
- targetVector.addElement( implicitTarget );
- this.helper=helper;
- }
-
- public Project getProject() {
- return project;
- }
-
- public RuntimeConfigurable currentWrapper() {
- if (wStack.size() < 1 ) return null;
- return (RuntimeConfigurable)wStack.elementAt( wStack.size() - 1
);
- }
-
- public RuntimeConfigurable parentWrapper() {
- if (wStack.size() < 2 ) return null;
- return (RuntimeConfigurable)wStack.elementAt( wStack.size() - 2
);
- }
-
- public void pushWrapper( RuntimeConfigurable wrapper ) {
- wStack.addElement(wrapper);
- }
-
- public void popWrapper() {
- if (wStack.size() > 0 )
- wStack.removeElementAt( wStack.size() - 1 );
- }
-
- public Vector getWrapperStack() {
- return wStack;
- }
+ protected void checkNamespace(String uri) {
- /**
- * Scans an attribute list for the <code>id</code> attribute and
- * stores a reference to the target object in the project if an
- * id is found.
- * <p>
- * This method was moved out of the configure method to allow
- * it to be executed at parse time.
- *
- * @see
#configure(java.lang.Object,org.xml.sax.AttributeList,org.apache.tools.ant.Project)
- */
- public void configureId(Object element, Attributes attr) {
- String id = attr.getValue("id");
- if (id != null) {
- project.addReference(id, element);
}
}
- }
-
/**
* Handler for ant processing. Uses a stack of AntHandlers to
* implement each element ( the original parser used a recursive
behavior,
@@ -431,9 +319,9 @@
public static class RootHandler extends DefaultHandler {
private Stack antHandlers=new Stack();
private AntHandler currentHandler=null;
- private AntXmlContext context;
+ private AntXMLContext context;
- public RootHandler(AntXmlContext context) {
+ public RootHandler(AntXMLContext context) {
currentHandler=ProjectHelper2.mainHandler;
antHandlers.push( currentHandler );
this.context=context;
@@ -459,7 +347,7 @@
File file = new File(path);
if (!file.isAbsolute()) {
- file = fu.resolveFile(context.buildFileParent, path);
+ file = fu.resolveFile(context.getBuildFileParent(),
path);
}
try {
InputSource inputSource =
@@ -467,7 +355,7 @@
inputSource.setSystemId(fu.toURI(file.getAbsolutePath()));
return inputSource;
} catch (FileNotFoundException fne) {
- context.project.log(file.getAbsolutePath() +
+ context.getProject().log(file.getAbsolutePath() +
" could not be found", Project.MSG_WARN);
}
@@ -489,9 +377,9 @@
* <code>"project"</code>
*/
public void startElement(String uri, String tag, String qname,
Attributes attrs)
- throws SAXParseException
- {
- AntHandler next=currentHandler.onStartChild(uri, tag, qname,
attrs, context);
+ throws SAXParseException {
+ AntHandler next
+ = currentHandler.onStartChild(uri, tag, qname, attrs,
context);
antHandlers.push( currentHandler );
currentHandler=next;
currentHandler.onStartElement( uri, tag, qname, attrs, context );
@@ -504,18 +392,18 @@
* Will not be <code>null</code>.
*/
public void setDocumentLocator(Locator locator) {
- context.locator = locator;
+ context.setLocator(locator);
}
/**
* Handles the end of an element. Any required clean-up is performed
- * by the onEndElement() method and then the original handler is
restored to
- * the parser.
+ * by the onEndElement() method and then the original handler
+ * is restored to the parser.
*
* @param name The name of the element which is ending.
* Will not be <code>null</code>.
*
- * @exception org.xml.sax.SAXException in case of error (not thrown
in
+ * @exception SAXException in case of error (not thrown in
* this implementation)
*
*/
@@ -523,13 +411,13 @@
currentHandler.onEndElement(uri, name, context);
AntHandler prev=(AntHandler)antHandlers.pop();
currentHandler=prev;
- if (currentHandler!=null )
+ if (currentHandler != null) {
currentHandler.onEndChild( uri, name, qName, context );
}
+ }
public void characters(char[] buf, int start, int count)
- throws SAXParseException
- {
+ throws SAXParseException {
currentHandler.characters( buf, start, count, context );
}
}
@@ -538,9 +426,8 @@
public AntHandler onStartChild(String uri, String name, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
if (qname.equals("project")) {
return ProjectHelper2.projectHandler;
} else {
@@ -549,7 +436,8 @@
// if (qname.equals( "target" ) )
// return ProjectHelper2.targetHandler;
// }
- throw new SAXParseException("Unexpected element \"" + qname
+ "\" " + name, context.locator);
+ throw new SAXParseException("Unexpected element \"" + qname
+ + "\" " + name, context.getLocator());
}
}
}
@@ -571,15 +459,14 @@
* @param attrs Attributes of the element which caused this
* handler to be created. Must not be <code>null</code>.
*
- * @exception org.xml.sax.SAXParseException if an unexpected
attribute is
+ * @exception SAXParseException if an unexpected attribute is
* encountered or if the <code>"default"</code> attribute
* is missing.
*/
public void onStartElement(String uri, String tag, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
String id = null;
String baseDir = null;
@@ -602,14 +489,15 @@
if (key.equals("default")) {
if ( value != null && !value.equals("")) {
- if (!context.ignoreProjectTag )
+ if (!context.isIgnoringProjectTag()) {
project.setDefaultTarget(value);
}
+ }
} else if (key.equals("name")) {
if (value != null) {
- context.currentProjectName=value;
+ context.setCurrentProjectName(value);
- if (!context.ignoreProjectTag ) {
+ if (!context.isIgnoringProjectTag()) {
project.setName(value);
project.addReference(value, project);
}
@@ -617,39 +505,42 @@
} else if (key.equals("id")) {
if (value != null) {
// What's the difference between id and name ?
- if (!context.ignoreProjectTag ) {
+ if (!context.isIgnoringProjectTag()) {
project.addReference(value, project);
}
}
} else if (key.equals("basedir")) {
- if (!context.ignoreProjectTag )
+ if (!context.isIgnoringProjectTag()) {
baseDir = value;
+ }
} else {
// XXX ignore attributes in a different NS ( maybe store
them ? )
- throw new SAXParseException("Unexpected attribute \"" +
attrs.getQName(i) + "\"", context.locator);
+ throw new SAXParseException("Unexpected attribute \""
+ + attrs.getQName(i) + "\"", context.getLocator());
}
}
// XXX Move to Project ( so it is shared by all helpers )
- String antFileProp = "ant.file." + context.currentProjectName;
+ String antFileProp = "ant.file." +
context.getCurrentProjectName();
String dup = project.getProperty(antFileProp);
if (dup != null) {
File dupFile = new File(dup);
- if( context.ignoreProjectTag &&
- !dupFile.equals(context.buildFile)) {
+ if (context.isIgnoringProjectTag() &&
+ !dupFile.equals(context.getBuildFile())) {
project.log("Duplicated project name in import. Project
"+
- context.currentProjectName + " defined first in " +
- dup + " and again in " + context.buildFile,
+ context.getCurrentProjectName() + " defined first in
" +
+ dup + " and again in " + context.getBuildFile(),
Project.MSG_WARN);
}
}
- if (context.buildFile != null ) {
-
project.setUserProperty("ant.file."+context.currentProjectName,
- context.buildFile.toString());
+ if (context.getBuildFile() != null) {
+ project.setUserProperty("ant.file."
+ + context.getCurrentProjectName(),
+ context.getBuildFile().toString());
}
- if (context.ignoreProjectTag ) {
+ if (context.isIgnoringProjectTag()) {
// no further processing
return;
}
@@ -659,20 +550,20 @@
} else {
// Default for baseDir is the location of the build file.
if (baseDir == null) {
-
project.setBasedir(context.buildFileParent.getAbsolutePath());
+
project.setBasedir(context.getBuildFileParent().getAbsolutePath());
} else {
// check whether the user has specified an absolute path
if ((new File(baseDir)).isAbsolute()) {
project.setBasedir(baseDir);
} else {
project.setBaseDir(project.resolveFile(baseDir,
-
context.buildFileParent));
+
context.getBuildFileParent()));
}
}
}
- project.addTarget("", context.implicitTarget);
- context.currentTarget=context.implicitTarget;
+ project.addTarget("", context.getImplicitTarget());
+ context.setCurrentTarget(context.getImplicitTarget());
}
/**
@@ -692,9 +583,8 @@
*/
public AntHandler onStartChild(String uri, String name, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
if (qname.equals("target")) {
return ProjectHelper2.targetHandler;
} else {
@@ -723,21 +613,19 @@
* @param attrs Attributes of the element which caused this
* handler to be created. Must not be <code>null</code>.
*
- * @exception org.xml.sax.SAXParseException if an unexpected
attribute is encountered
+ * @exception SAXParseException if an unexpected attribute is
encountered
* or if the <code>"name"</code> attribute is missing.
*/
public void onStartElement(String uri, String tag, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
String name = null;
String depends = "";
Project project=context.getProject();
Target target = new Target();
- context.currentTarget=target;
- context.targetVector.addElement( target );
+ context.addTarget(target);
for (int i = 0; i < attrs.getLength(); i++) {
String key = attrs.getQName(i);
@@ -745,8 +633,10 @@
if (key.equals("name")) {
name = value;
- if ("".equals( name ) )
- throw new BuildException("name attribute must not be
empty");
+ if ("".equals(name)) {
+ throw new BuildException("name attribute must "
+ + "not be empty");
+ }
} else if (key.equals("depends")) {
depends = value;
} else if (key.equals("if")) {
@@ -760,13 +650,14 @@
} else if (key.equals("description")) {
target.setDescription(value);
} else {
- throw new SAXParseException("Unexpected attribute \"" +
key + "\"", context.locator);
+ throw new SAXParseException("Unexpected attribute \""
+ + key + "\"", context.getLocator());
}
}
if (name == null) {
- throw new SAXParseException("target element appears without
a name attribute",
- context.locator);
+ throw new SAXParseException("target element appears without "
+ + "a name attribute", context.getLocator());
}
Hashtable currentTargets = project.getTargets();
@@ -774,16 +665,16 @@
// If the name has already beend defined ( import for example )
if(currentTargets.containsKey(name)) {
// Alter the name.
- if (context.currentProjectName != null ) {
- String newName=context.currentProjectName + "." + name;
- project.log("Already defined in main or a previous
import, define "
- + name + " as " + newName,
+ if (context.getCurrentProjectName() != null) {
+ String newName = context.getCurrentProjectName()
+ + "." + name;
+ project.log("Already defined in main or a previous
import, "
+ + "define " + name + " as " + newName,
Project.MSG_VERBOSE);
name=newName;
} else {
- project.log("Already defined in main or a previous
import, ignore "
- + name,
- Project.MSG_VERBOSE);
+ project.log("Already defined in main or a previous
import, "
+ + "ignore " + name, Project.MSG_VERBOSE);
name=null;
}
}
@@ -807,18 +698,18 @@
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
*
- * @exception org.xml.sax.SAXParseException if an error occurs when
initialising
+ * @exception SAXParseException if an error occurs when initialising
* the appropriate child handler
*/
public AntHandler onStartChild(String uri, String name, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
return ProjectHelper2.elementHandler;
}
- public void onEndElement(String uri, String tag, AntXmlContext
context) {
- context.currentTarget=context.implicitTarget;
+
+ public void onEndElement(String uri, String tag, AntXMLContext
context) {
+ context.setCurrentTarget(context.getImplicitTarget());
}
}
@@ -846,14 +737,13 @@
* @param attrs Attributes of the element which caused this
* handler to be created. Must not be <code>null</code>.
*
- * @exception org.xml.sax.SAXParseException in case of error (not
thrown in
+ * @exception SAXParseException in case of error (not thrown in
* this implementation)
*/
public void onStartElement(String uri, String tag, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
RuntimeConfigurable parentWrapper=context.currentWrapper();
RuntimeConfigurable wrapper=null;
Object parent=null;
@@ -887,11 +777,11 @@
task.setTaskName(qname);
- Location location=new Location(context.locator.getSystemId(),
- context.locator.getLineNumber(),
- context.locator.getColumnNumber());
+ Location location = new
Location(context.getLocator().getSystemId(),
+ context.getLocator().getLineNumber(),
+ context.getLocator().getColumnNumber());
task.setLocation(location);
- task.setOwningTarget(context.currentTarget);
+ task.setOwningTarget(context.getCurrentTarget());
context.configureId(task, attrs);
@@ -900,7 +790,7 @@
((UnknownElement)parent).addChild( task );
} else {
// Task included in a target ( including the default one ).
- context.currentTarget.addTask( task );
+ context.getCurrentTarget().addTask(task);
}
// container.addTask(task);
@@ -928,14 +818,13 @@
* @param start The start element in the array.
* @param count The number of characters to read from the array.
*
- * @exception org.xml.sax.SAXParseException if the element doesn't
support text
+ * @exception SAXParseException if the element doesn't support text
*
- * @see
org.apache.tools.ant.ProjectHelper#addText(org.apache.tools.ant.Project,java.lang.Object,char[],int,int)
+ * @see
ProjectHelper#addText(Project,java.lang.Object,char[],int,int)
*/
public void characters(char[] buf, int start, int count,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
RuntimeConfigurable wrapper=context.currentWrapper();
wrapper.addText(buf, start, count);
}
@@ -950,14 +839,13 @@
* @param attrs Attributes of the element being started.
* Will not be <code>null</code>.
*
- * @exception org.xml.sax.SAXParseException if an error occurs when
initialising
+ * @exception SAXParseException if an error occurs when initialising
* the appropriate child handler
*/
public AntHandler onStartChild(String uri, String tag, String qname,
Attributes attrs,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
// this element
RuntimeConfigurable wrapper=context.currentWrapper();
@@ -966,14 +854,13 @@
return ProjectHelper2.elementHandler;
}
- public void onEndElement(String uri, String tag, AntXmlContext
context) {
+ public void onEndElement(String uri, String tag, AntXMLContext
context) {
context.popWrapper();
}
public void onEndChild(String uri, String tag, String qname,
- AntXmlContext context)
- throws SAXParseException
- {
+ AntXMLContext context)
+ throws SAXParseException {
}
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/helper/AntXMLContext.java
Index: AntXMLContext.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.helper;
import java.io.File;
import java.util.Vector;
import org.xml.sax.Locator;
import org.xml.sax.Attributes;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.RuntimeConfigurable;
/**
* Context information for the ant processing.
*
* @author Costin Manolache
*/
public class AntXMLContext {
/** The project to configure. */
private Project project;
/** The configuration file to parse. */
private File buildFile;
/** Vector with all the targets, in the order they are
* defined. Project maintains a Hashtable, which is not ordered.
* This will allow description to know the original order.
*/
private Vector targetVector = new Vector();
/**
* Parent directory of the build file. Used for resolving entities
* and setting the project's base directory.
*/
private File buildFileParent;
/** Name of the current project */
private String currentProjectName;
/**
* Locator for the configuration file parser.
* Used for giving locations of errors etc.
*/
private Locator locator;
/**
* Target that all other targets will depend upon implicitly.
*
* <p>This holds all tasks and data type definitions that have
* been placed outside of targets.</p>
*/
private Target implicitTarget = new Target();
/** Current target ( no need for a stack as the processing model
allows only one level of target ) */
private Target currentTarget = null;
/** The stack of RuntimeConfigurable2 wrapping the
objects.
*/
private Vector wStack = new Vector();
/**
* Indicates whether the project tag attributes are to be ignored
* when processing a particular build file.
*/
private boolean ignoreProjectTag = false;
public AntXMLContext(Project project) {
this.project = project;
implicitTarget.setName("");
targetVector.addElement(implicitTarget);
}
public void setBuildFile(File buildFile) {
this.buildFile = buildFile;
this.buildFileParent = new File(buildFile.getParent());
}
public File getBuildFile() {
return buildFile;
}
public File getBuildFileParent() {
return buildFileParent;
}
public Project getProject() {
return project;
}
public String getCurrentProjectName() {
return currentProjectName;
}
public void setCurrentProjectName(String name) {
this.currentProjectName = name;
}
public RuntimeConfigurable currentWrapper() {
if (wStack.size() < 1) {
return null;
}
return (RuntimeConfigurable) wStack.elementAt(wStack.size() - 1);
}
public RuntimeConfigurable parentWrapper() {
if (wStack.size() < 2) {
return null;
}
return (RuntimeConfigurable) wStack.elementAt(wStack.size() - 2);
}
public void pushWrapper(RuntimeConfigurable wrapper) {
wStack.addElement(wrapper);
}
public void popWrapper() {
if (wStack.size() > 0) {
wStack.removeElementAt(wStack.size() - 1);
}
}
public Vector getWrapperStack() {
return wStack;
}
public void addTarget(Target target) {
targetVector.addElement(target);
currentTarget = target;
}
public Target getCurrentTarget() {
return currentTarget;
}
public Target getImplicitTarget() {
return implicitTarget;
}
public void setCurrentTarget(Target target) {
this.currentTarget = target;
}
public void setImplicitTarget(Target target) {
this.implicitTarget = target;
}
public Vector getTargets() {
return targetVector;
}
/**
* Scans an attribute list for the <code>id</code> attribute and
* stores a reference to the target object in the project if an
* id is found.
* <p>
* This method was moved out of the configure method to allow
* it to be executed at parse time.
*
* @see
#configure(java.lang.Object,org.xml.sax.AttributeList,org.apache.tools.ant.Project)
*/
public void configureId(Object element, Attributes attr) {
String id = attr.getValue("id");
if (id != null) {
project.addReference(id, element);
}
}
public Locator getLocator() {
return locator;
}
public void setLocator(Locator locator) {
this.locator = locator;
}
public boolean isIgnoringProjectTag() {
return ignoreProjectTag;
}
public void setIgnoreProjectTag(boolean flag) {
this.ignoreProjectTag = flag;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>