conor 2002/06/17 04:31:09
Modified: proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib
AntLibHandler.java
proposal/mutant/src/java/antcore/org/apache/ant/antcore/config
AntConfigHandler.java
proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution
ComponentManager.java CoreExecService.java
proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser
BuildElementHandler.java ProjectHandler.java
TargetHandler.java XMLProjectParser.java
proposal/mutant/src/java/antcore/org/apache/ant/antcore/xml
ElementHandler.java ParseContext.java
proposal/mutant/src/java/common/org/apache/ant/common/service
ComponentService.java
proposal/mutant/src/java/frontend/org/apache/ant/frontend
FrontendUtils.java
Added: proposal/mutant/src/java/common/org/apache/ant/common/constants
Namespace.java
Removed: proposal/mutant/src/java/common/org/apache/ant/common
Namespace.java
Log:
The old crimson parser incorrectly supported namespaces by default. Under
Xerces, need to turn on support
Revision Changes Path
1.10 +2 -2
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibHandler.java
Index: AntLibHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibHandler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -u -r1.9 -r1.10
--- AntLibHandler.java 27 May 2002 15:52:21 -0000 1.9
+++ AntLibHandler.java 17 Jun 2002 11:31:08 -0000 1.10
@@ -129,8 +129,8 @@
* @param attributes The attributes attached to the element.
* @throws SAXParseException if there is a parsing problem.
*/
- public void startElement(String uri, String localName, String
qualifiedName,
- Attributes attributes)
+ protected void addNestedElement(String uri, String localName,
+ String qualifiedName, Attributes
attributes)
throws SAXParseException {
try {
if (qualifiedName.equals("taskdef")
1.13 +2 -2
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfigHandler.java
Index: AntConfigHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfigHandler.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -u -r1.12 -r1.13
--- AntConfigHandler.java 13 Jun 2002 15:47:54 -0000 1.12
+++ AntConfigHandler.java 17 Jun 2002 11:31:08 -0000 1.13
@@ -126,8 +126,8 @@
* @param attributes The attributes attached to the element.
* @throws SAXParseException if there is a parsing problem.
*/
- public void startElement(String uri, String localName, String
qualifiedName,
- Attributes attributes)
+ protected void addNestedElement(String uri, String localName,
+ String qualifiedName, Attributes
attributes)
throws SAXParseException {
// configs support two task collections as elements
1.22 +49 -14
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java
Index: ComponentManager.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -w -u -r1.21 -r1.22
--- ComponentManager.java 13 Jun 2002 15:47:54 -0000 1.21
+++ ComponentManager.java 17 Jun 2002 11:31:08 -0000 1.22
@@ -397,6 +397,45 @@
}
/**
+ * Set an attribute on an object.
+ *
+ * This method is useful for manipulating components without assuming
+ * anything about the component's type. The context classloader should be
+ * set to the component's loaded when calling this method.
+ *
+ * @param component the component on which to set the attribute
+ * @param attributeName the attribute name
+ * @param attributeValue the required value
+ *
+ * @exception AntException if the attribute cannot be set.
+ */
+ public void setAttribute(Object component, String attributeName,
+ String attributeValue) throws AntException {
+
+ Setter setter = getSetter(component.getClass());
+ setter.setAttribute(component, attributeName,
+ frame.replacePropertyRefs(attributeValue));
+ }
+
+ /**
+ * Add a nested element to a component.
+ *
+ * This method is useful for manipulating components without assuming
+ * anything about the component's type. The context classloader should be
+ * set to the component's loaded when calling this method.
+ *
+ * @param component the component to which the nested element will be
added.
+ * @param nestedElementName the name of the nested element.
+ * @param nestedElement the actual object to be added.
+ *
+ * @exception AntException if the nested element cannot be added.
+ */
+ public void addNestedElement(Object component, String nestedElementName,
+ Object nestedElement) throws AntException {
+ Setter setter = getSetter(component.getClass());
+ setter.addElement(component, nestedElementName, nestedElement);
+ }
+ /**
* Get an imported definition from the component manager
*
* @param name the name under which the component has been imported
@@ -416,7 +455,7 @@
* @exception AntException if there is a problem creating or
* configuring the component
*/
- protected Object createComponent(BuildElement model)
+ public Object createComponent(BuildElement model)
throws AntException {
String componentName = model.getType();
return createComponent(componentName, model);
@@ -474,7 +513,6 @@
boolean isTask
= libDefinition.getDefinitionType() == AntLibrary.TASKDEF;
-
Object component = null;
if (model != null) {
location = model.getLocation();
@@ -678,7 +716,7 @@
* the attribute is to be added.
* @exception AntException if the nested element cannot be created
*/
- private void addNestedElement(AntLibFactory factory, Setter setter,
+ private void addNested(AntLibFactory factory, Setter setter,
Object element, BuildElement model)
throws AntException {
String nestedElementName = model.getType();
@@ -686,7 +724,7 @@
// is there a polymorph indicator - look in Ant aspects
String typeName
- = model.getNamespaceAttributeValue(Namespace.ANT_META_URI,
"type");
+ = model.getNamespaceAttributeValue(Namespace.XSI_URI, "type");
Object typeInstance = null;
if (typeName != null) {
@@ -706,9 +744,8 @@
} 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");
+ + "Please specify by the type using the \"xsi:type\" "
+ + "attribute or provide a reference to another instance");
}
// is the typeInstance compatible with the type expected
@@ -732,7 +769,7 @@
* the nested element
* @exception AntException if the nested element cannot be created.
*/
- private void createNestedElement(AntLibFactory factory, Setter setter,
+ private void createNested(AntLibFactory factory, Setter setter,
Object element, BuildElement model)
throws AntException {
String nestedElementName = model.getType();
@@ -819,11 +856,9 @@
container.addNestedTask(nestedTask);
} else {
if (setter.supportsNestedAdder(nestedElementName)) {
- addNestedElement(factory, setter, element,
- nestedElementModel);
+ addNested(factory, setter, element, nestedElementModel);
} else if (setter.supportsNestedCreator(nestedElementName)) {
- createNestedElement(factory, setter, element,
- nestedElementModel);
+ createNested(factory, setter, element,
nestedElementModel);
} else {
throw new ExecutionException("<" + model.getType() + ">"
+ " does not support the \"" + nestedElementName
1.19 +0 -2
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreExecService.java
Index: CoreExecService.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreExecService.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -w -u -r1.18 -r1.19
--- CoreExecService.java 13 Jun 2002 15:47:54 -0000 1.18
+++ CoreExecService.java 17 Jun 2002 11:31:08 -0000 1.19
@@ -145,8 +145,6 @@
frame.executeTask(task, aspectValues);
}
-
-
/**
* Get the base directory for this execution of this frame
*
1.8 +2 -2
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/BuildElementHandler.java
Index: BuildElementHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/BuildElementHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -u -r1.7 -r1.8
--- BuildElementHandler.java 13 Jun 2002 15:47:54 -0000 1.7
+++ BuildElementHandler.java 17 Jun 2002 11:31:08 -0000 1.8
@@ -107,8 +107,8 @@
* @param attributes The attributes attached to the element.
* @throws SAXParseException if there is a parsing problem.
*/
- public void startElement(String uri, String localName, String
qualifiedName,
- Attributes attributes)
+ protected void addNestedElement(String uri, String localName,
+ String qualifiedName, Attributes
attributes)
throws SAXParseException {
// everything within a task element is also a task element
1.10 +2 -2
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/ProjectHandler.java
Index: ProjectHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/ProjectHandler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -u -r1.9 -r1.10
--- ProjectHandler.java 13 Jun 2002 15:47:54 -0000 1.9
+++ ProjectHandler.java 17 Jun 2002 11:31:08 -0000 1.10
@@ -154,8 +154,8 @@
* @param attributes The attributes attached to the element.
* @throws SAXParseException if there is a parsing problem.
*/
- public void startElement(String uri, String localName, String
qualifiedName,
- Attributes attributes)
+ protected void addNestedElement(String uri, String localName,
+ String qualifiedName, Attributes
attributes)
throws SAXParseException {
if (qualifiedName.equals(INCLUDE_ELEMENT)) {
1.8 +2 -2
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/TargetHandler.java
Index: TargetHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/TargetHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -u -r1.7 -r1.8
--- TargetHandler.java 13 Jun 2002 15:47:54 -0000 1.7
+++ TargetHandler.java 17 Jun 2002 11:31:08 -0000 1.8
@@ -130,8 +130,8 @@
* @param attributes The attributes attached to the element.
* @throws SAXParseException if there is a parsing problem.
*/
- public void startElement(String uri, String localName, String
qualifiedName,
- Attributes attributes)
+ protected void addNestedElement(String uri, String localName,
+ String qualifiedName, Attributes
attributes)
throws SAXParseException {
// everything is a task
BuildElementHandler taskHandler = new BuildElementHandler();
1.4 +6 -1
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/XMLProjectParser.java
Index: XMLProjectParser.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/XMLProjectParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -u -r1.3 -r1.4
--- XMLProjectParser.java 13 Jun 2002 15:47:54 -0000 1.3
+++ XMLProjectParser.java 17 Jun 2002 11:31:08 -0000 1.4
@@ -58,6 +58,7 @@
import org.apache.ant.common.model.Project;
import org.apache.ant.antcore.xml.ParseContext;
import org.apache.ant.antcore.xml.XMLParseException;
+import org.apache.ant.common.constants.Namespace;
/**
* Parses an Ant project model from an XML source using a SAX Parser.
@@ -78,7 +79,11 @@
throws XMLParseException {
try {
ParseContext context = new ParseContext();
- context.declareNamespace("ant", "http://jakarta.apache.org/ant");
+ context.declareNamespace(Namespace.ANT_META_PREFIX,
+ Namespace.ANT_META_URI);
+ context.declareNamespace(Namespace.XSI_PREFIX,
+ Namespace.XSI_URI);
+
ProjectHandler projectHandler = new ProjectHandler();
context.parse(buildSource, "project", projectHandler);
1.9 +23 -7
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/xml/ElementHandler.java
Index: ElementHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/xml/ElementHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -u -r1.8 -r1.9
--- ElementHandler.java 14 Jun 2002 06:36:51 -0000 1.8
+++ ElementHandler.java 17 Jun 2002 11:31:08 -0000 1.9
@@ -216,6 +216,22 @@
/**
+ * Process an element. This resolves any namespaces against
+ * prefixes declared in the ParseContext.
+ *
+ * @param uri The Namespace URI.
+ * @param localName The local name (without prefix).
+ * @param qualifiedName The qualified name (with prefix)
+ * @param attributes The attributes attached to the element.
+ * @throws SAXParseException if there is a problem parsng the subelement
+ */
+ final public void startElement(String uri, String localName,
+ String qualifiedName, Attributes
attributes)
+ throws SAXParseException {
+ addNestedElement(uri, localName, qualifiedName, attributes);
+ }
+
+ /**
* By default an element handler does not support nested elements. This
* method will always throw an exception. Subclasses should override
* this method to support their own nested elements
@@ -226,10 +242,10 @@
* @param attributes The attributes attached to the element.
* @throws SAXParseException if there is a problem parsng the subelement
*/
- public void startElement(String uri, String localName, String
qualifiedName,
+ protected void addNestedElement(String uri, String localName,
+ String qualifiedName,
Attributes attributes)
throws SAXParseException {
- // everything is a task
throw new SAXParseException("<" + elementName + "> does not support
a <"
+ qualifiedName + "> nested element", getLocator());
}
@@ -320,7 +336,6 @@
protected abstract void processElement(String elementName)
throws SAXParseException;
-
/**
* Process all of the attributes of the element into maps, one for
* aspects and one for other attributes
@@ -335,12 +350,13 @@
elementAttributes = new AttributeCollection();
int length = attributes.getLength();
for (int i = 0; i < length; ++i) {
+ String localName = attributes.getLocalName(i);
+ String qName = attributes.getQName(i);
String uri = attributes.getURI(i);
if (uri != null && uri.trim().length() == 0) {
uri = null;
}
- String localName = attributes.getLocalName(i);
- String qName = attributes.getQName(i);
+
if (uri == null) {
if (qName.indexOf(":") != -1) {
1.9 +3 -2
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/xml/ParseContext.java
Index: ParseContext.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/xml/ParseContext.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -u -r1.8 -r1.9
--- ParseContext.java 14 Jun 2002 06:36:51 -0000 1.8
+++ ParseContext.java 17 Jun 2002 11:31:08 -0000 1.9
@@ -95,6 +95,7 @@
ClassLoader thisLoader = this.getClass().getClassLoader();
thread.setContextClassLoader(thisLoader);
parserFactory = SAXParserFactory.newInstance();
+ parserFactory.setNamespaceAware(true);
} finally {
thread.setContextClassLoader(currentContextLoader);
}
1.1
jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/constants/Namespace.java
Index: Namespace.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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.ant.common.constants;
/**
* Namespace constants
*
* @author Conor MacNeill
* @created 14 June 2002
*/
public class Namespace {
/** The Ant namespace used to identify Ant metadata */
public static final String ANT_META_URI
= "http://jakarta.apache.org/ant/meta";
/** The namespace id that is predeclared for the Ant metadata namespace */
public static final String ANT_META_PREFIX = "ant";
/** The XML Schema namespace */
public static final String XSI_URI
= "http://www.w3.org/2001/XMLSchema-instance";
/** The namespace id that is predeclared for the Ant metadata namespace */
public static final String XSI_PREFIX = "xsi";
}
1.18 +44 -0
jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java
Index: ComponentService.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -w -u -r1.17 -r1.18
--- ComponentService.java 13 Jun 2002 15:47:55 -0000 1.17
+++ ComponentService.java 17 Jun 2002 11:31:08 -0000 1.18
@@ -54,6 +54,7 @@
package org.apache.ant.common.service;
import java.net.URL;
import org.apache.ant.common.antlib.AntLibFactory;
+import org.apache.ant.common.model.BuildElement;
import org.apache.ant.common.util.AntException;
import org.apache.ant.common.util.AttributeCollection;
@@ -186,6 +187,49 @@
*/
Object createComponent(String libraryId, String localName)
throws AntException;
+
+ /**
+ * Create a component from a build model. The returned object will be
+ * configured according to the model.
+ *
+ * @param model the build element to use to create and configure the
+ * component
+ * @return the created component.
+ * @exception AntException if the component cannot be created
+ */
+ Object createComponent(BuildElement model) throws AntException;
+
+ /**
+ * Set an attribute on an object.
+ *
+ * This method is useful for manipulating components without assuming
+ * anything about the component's type. The context classloader should be
+ * set to the component's loaded when calling this method.
+ *
+ * @param component the component on which to set the attribute
+ * @param attributeName the attribute name
+ * @param attributeValue the required value
+ *
+ * @exception AntException if the attribute cannot be set.
+ */
+ void setAttribute(Object component, String attributeName,
+ String attributeValue) throws AntException;
+
+ /**
+ * Add a nested element to a component.
+ *
+ * This method is useful for manipulating components without assuming
+ * anything about the component's type. The context classloader should be
+ * set to the component's loaded when calling this method.
+ *
+ * @param component the component to which the nested element will be
added.
+ * @param nestedElementName the name of the nested element.
+ * @param nestedElement the actual object to be added.
+ *
+ * @exception AntException if the nested element cannot be added.
+ */
+ void addNestedElement(Object component, String nestedElementName,
+ Object nestedElement) throws AntException;
/**
* configure an object with attribtes from the given map
1.3 +6 -0
jakarta-ant/proposal/mutant/src/java/frontend/org/apache/ant/frontend/FrontendUtils.java
Index: FrontendUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/frontend/org/apache/ant/frontend/FrontendUtils.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -u -r1.2 -r1.3
--- FrontendUtils.java 27 May 2002 15:52:27 -0000 1.2
+++ FrontendUtils.java 17 Jun 2002 11:31:09 -0000 1.3
@@ -62,6 +62,7 @@
import org.apache.ant.antcore.xml.ParseContext;
import org.apache.ant.antcore.xml.XMLParseException;
import org.apache.ant.init.InitUtils;
+import org.apache.ant.common.constants.Namespace;
/**
* Frontend Utilities methods and constants.
@@ -113,6 +114,11 @@
URL configFileURL = InitUtils.getFileURL(configFile);
ParseContext context = new ParseContext();
+ context.declareNamespace(Namespace.ANT_META_PREFIX,
+ Namespace.ANT_META_URI);
+ context.declareNamespace(Namespace.XSI_PREFIX,
+ Namespace.XSI_URI);
+
AntConfigHandler configHandler = new AntConfigHandler();
context.parse(configFileURL, "antconfig", configHandler);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>