Browse Source

* Retain difference between "" and "antlib:org.apache.tools.ant" namespaces

in UE.getNamespace()
* Remove near duplicate method in IntrospectionHelper
* Add UnknownElement to signature of IntrospectionHelper#getElementCreator
  for future xml Namespace use


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275797 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
f948bb98aa
3 changed files with 13 additions and 52 deletions
  1. +5
    -41
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  2. +2
    -1
      src/main/org/apache/tools/ant/UnknownElement.java
  3. +6
    -10
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java

+ 5
- 41
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -603,45 +603,6 @@ public final class IntrospectionHelper implements BuildListener {
throw new BuildException(msg); throw new BuildException(msg);
} }


private NestedCreator getNestedCreator(Project project, Object parent,
String elementName) throws BuildException {

NestedCreator nc = (NestedCreator) nestedCreators.get(
elementName.toLowerCase(Locale.US));
if (nc == null) {
nc = createAddTypeCreator(project, parent, elementName);
}
if (nc == null && parent instanceof DynamicConfigurator) {
DynamicConfigurator dc = (DynamicConfigurator) parent;
final Object nestedElement = dc.createDynamicElement(elementName);
if (nestedElement != null) {
nc = new NestedCreator() {
public boolean isPolyMorphic() {
return false;
}
public Class getElementClass() {
return null;
}

public Object getRealObject() {
return null;
}

public Object create(
Project project, Object parent, Object ignore) {
return nestedElement;
}
public void store(Object parent, Object child) {
}
};
}
}
if (nc == null) {
throwNotSupported(project, parent, elementName);
}
return nc;
}

private NestedCreator getNestedCreator( private NestedCreator getNestedCreator(
Project project, String parentUri, Object parent, Project project, String parentUri, Object parent,
String elementName) throws BuildException { String elementName) throws BuildException {
@@ -705,6 +666,7 @@ public final class IntrospectionHelper implements BuildListener {
* Must not be <code>null</code>. * Must not be <code>null</code>.
* *
* @return an instance of the specified element type * @return an instance of the specified element type
* @deprecated This is not a namespace aware method.
* *
* @exception BuildException if no method is available to create the * @exception BuildException if no method is available to create the
* element instance, or if the creating method * element instance, or if the creating method
@@ -712,7 +674,7 @@ public final class IntrospectionHelper implements BuildListener {
*/ */
public Object createElement(Project project, Object parent, public Object createElement(Project project, Object parent,
String elementName) throws BuildException { String elementName) throws BuildException {
NestedCreator nc = getNestedCreator(project, parent, elementName);
NestedCreator nc = getNestedCreator(project, "", parent, elementName);
try { try {
Object nestedElement = nc.create(project, parent, null); Object nestedElement = nc.create(project, parent, null);
if (project != null) { if (project != null) {
@@ -743,11 +705,13 @@ public final class IntrospectionHelper implements BuildListener {
* @param parent Parent object used to create the creator object to * @param parent Parent object used to create the creator object to
* create and store and instance of a subelement. * create and store and instance of a subelement.
* @param elementName Name of the element to create an instance of. * @param elementName Name of the element to create an instance of.
* @param ue The unknown element associated with the element.
* @return a creator object to create and store the element instance. * @return a creator object to create and store the element instance.
*/ */


public Creator getElementCreator( public Creator getElementCreator(
Project project, String parentUri, Object parent, String elementName) {
Project project, String parentUri, Object parent, String elementName,
UnknownElement ue) {
NestedCreator nc = getNestedCreator( NestedCreator nc = getNestedCreator(
project, parentUri, parent, elementName); project, parentUri, parent, elementName);
return new Creator(project, parent, nc); return new Creator(project, parent, nc);


+ 2
- 1
src/main/org/apache/tools/ant/UnknownElement.java View File

@@ -564,7 +564,8 @@ public class UnknownElement extends Task {
child.getNamespace(), child.getTag()); child.getNamespace(), child.getTag());
if (ih.supportsNestedElement(parentUri, childName)) { if (ih.supportsNestedElement(parentUri, childName)) {
IntrospectionHelper.Creator creator = IntrospectionHelper.Creator creator =
ih.getElementCreator(getProject(), parentUri, parent, childName);
ih.getElementCreator(
getProject(), parentUri, parent, childName, child);
creator.setPolyType(childWrapper.getPolyType()); creator.setPolyType(childWrapper.getPolyType());
Object realChild = creator.create(); Object realChild = creator.create();
if (realChild instanceof PreSetDef.PreSetDefinition) { if (realChild instanceof PreSetDef.PreSetDefinition) {


+ 6
- 10
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -272,7 +272,7 @@ public class ProjectHelper2 extends ProjectHelper {
+ buildFileName + " is invalid.", + buildFileName + " is invalid.",
exc); exc);
} catch (IOException exc) { } catch (IOException exc) {
throw new BuildException("Error reading project file "
throw new BuildException("Error reading project file "
+ buildFileName + ": " + exc.getMessage(), + buildFileName + ": " + exc.getMessage(),
exc); exc);
} finally { } finally {
@@ -484,9 +484,6 @@ public class ProjectHelper2 extends ProjectHelper {
*/ */
public void startElement(String uri, String tag, String qname, Attributes attrs) public void startElement(String uri, String tag, String qname, Attributes attrs)
throws SAXParseException { throws SAXParseException {
if (uri.equals(ANT_CORE_URI)) {
uri = "";
}
AntHandler next AntHandler next
= currentHandler.onStartChild(uri, tag, qname, attrs, context); = currentHandler.onStartChild(uri, tag, qname, attrs, context);
antHandlers.push(currentHandler); antHandlers.push(currentHandler);
@@ -519,9 +516,6 @@ public class ProjectHelper2 extends ProjectHelper {
* *
*/ */
public void endElement(String uri, String name, String qName) throws SAXException { public void endElement(String uri, String name, String qName) throws SAXException {
if (uri.equals(ANT_CORE_URI)) {
uri = "";
}
currentHandler.onEndElement(uri, name, context); currentHandler.onEndElement(uri, name, context);
AntHandler prev = (AntHandler) antHandlers.pop(); AntHandler prev = (AntHandler) antHandlers.pop();
currentHandler = prev; currentHandler = prev;
@@ -585,7 +579,8 @@ public class ProjectHelper2 extends ProjectHelper {
Attributes attrs, Attributes attrs,
AntXMLContext context) AntXMLContext context)
throws SAXParseException { throws SAXParseException {
if (name.equals("project") && uri.equals("")) {
if (name.equals("project")
&& (uri.equals("") || uri.equals(ANT_CORE_URI))) {
return ProjectHelper2.projectHandler; return ProjectHelper2.projectHandler;
} else { } else {
// if (context.importlevel > 0) { // if (context.importlevel > 0) {
@@ -653,7 +648,7 @@ public class ProjectHelper2 extends ProjectHelper {
} }
String key = attrs.getLocalName(i); String key = attrs.getLocalName(i);
String value = attrs.getValue(i); String value = attrs.getValue(i);
if (key.equals("default")) { if (key.equals("default")) {
if (value != null && !value.equals("")) { if (value != null && !value.equals("")) {
if (!context.isIgnoringProjectTag()) { if (!context.isIgnoringProjectTag()) {
@@ -756,7 +751,8 @@ public class ProjectHelper2 extends ProjectHelper {
Attributes attrs, Attributes attrs,
AntXMLContext context) AntXMLContext context)
throws SAXParseException { throws SAXParseException {
if (name.equals("target") && uri.equals("")) {
if (name.equals("target")
&& (uri.equals("") || uri.equals(ANT_CORE_URI))) {
return ProjectHelper2.targetHandler; return ProjectHelper2.targetHandler;
} else { } else {
return ProjectHelper2.elementHandler; return ProjectHelper2.elementHandler;


Loading…
Cancel
Save