You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2004/05/24 17:09:57 UTC
cvs commit: ant/src/main/org/apache/tools/ant/util XMLFragment.java
peterreilly 2004/05/24 08:09:57
Modified: src/main/org/apache/tools/ant IntrospectionHelper.java
ProjectHelper.java RuntimeConfigurable.java
src/main/org/apache/tools/ant/helper ProjectHelper2.java
src/main/org/apache/tools/ant/util XMLFragment.java
Log:
DynamicConfiguratorNS
Initial code for dynamicConfiguratorNS.
Change from patch the qualified name is given and
not the prefix.
PR: 28426
Revision Changes Path
1.81 +55 -6 ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
Index: IntrospectionHelper.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- IntrospectionHelper.java 13 May 2004 07:06:49 -0000 1.80
+++ IntrospectionHelper.java 24 May 2004 15:09:54 -0000 1.81
@@ -486,13 +486,30 @@
public void setAttribute(Project p, Object element, String attributeName,
String value) throws BuildException {
AttributeSetter as
- = (AttributeSetter) attributeSetters.get(attributeName);
+ = (AttributeSetter) attributeSetters.get(
+ attributeName.toLowerCase(Locale.US));
if (as == null) {
- if (element instanceof DynamicConfigurator) {
+ if (element instanceof DynamicConfiguratorNS) {
+ DynamicConfiguratorNS dc = (DynamicConfiguratorNS) element;
+ String uriPlusPrefix =
+ ProjectHelper.extractUriFromComponentName(attributeName);
+ String uri =
+ ProjectHelper.extractUriFromComponentName(uriPlusPrefix);
+ String localName =
+ ProjectHelper.extractNameFromComponentName(attributeName);
+ String qName = ("".equals(uri)
+ ? localName : (uri + ":" + localName));
+
+ dc.setDynamicAttribute(uri, localName, qName, value);
+ return;
+ } else if (element instanceof DynamicConfigurator) {
DynamicConfigurator dc = (DynamicConfigurator) element;
- dc.setDynamicAttribute(attributeName, value);
+ dc.setDynamicAttribute(attributeName.toLowerCase(Locale.US), value);
return;
} else {
+ if (attributeName.indexOf(':') != -1) {
+ return; // Ignore attribute from unknown uri's
+ }
String msg = getElementName(p, element)
+ " doesn't support the \"" + attributeName
+ "\" attribute.";
@@ -512,6 +529,7 @@
throw new BuildException(t);
}
}
+
/**
* Adds PCDATA to an element, using the element's
@@ -574,7 +592,7 @@
private NestedCreator getNestedCreator(
Project project, String parentUri, Object parent,
- String elementName) throws BuildException {
+ String elementName, UnknownElement child) throws BuildException {
String uri = ProjectHelper.extractUriFromComponentName(elementName);
String name = ProjectHelper.extractNameFromComponentName(elementName);
@@ -593,6 +611,35 @@
if (nc == null) {
nc = createAddTypeCreator(project, parent, elementName);
}
+ if (nc == null && parent instanceof DynamicConfiguratorNS) {
+ DynamicConfiguratorNS dc = (DynamicConfiguratorNS) parent;
+ String qName = (child == null ? name : child.getQName());
+ final Object nestedElement =
+ dc.createDynamicElement(
+ (child == null ? "" : child.getNamespace()),
+ name, qName);
+ 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 && parent instanceof DynamicConfigurator) {
DynamicConfigurator dc = (DynamicConfigurator) parent;
final Object nestedElement =
@@ -649,7 +696,7 @@
*/
public Object createElement(Project project, Object parent,
String elementName) throws BuildException {
- NestedCreator nc = getNestedCreator(project, "", parent, elementName);
+ NestedCreator nc = getNestedCreator(project, "", parent, elementName, null);
try {
Object nestedElement = nc.create(project, parent, null);
if (project != null) {
@@ -688,7 +735,7 @@
Project project, String parentUri, Object parent, String elementName,
UnknownElement ue) {
NestedCreator nc = getNestedCreator(
- project, parentUri, parent, elementName);
+ project, parentUri, parent, elementName, ue);
return new Creator(project, parent, nc);
}
@@ -703,6 +750,7 @@
public boolean supportsNestedElement(String elementName) {
return nestedCreators.containsKey(elementName.toLowerCase(Locale.US))
|| DynamicConfigurator.class.isAssignableFrom(bean)
+ || DynamicConfiguratorNS.class.isAssignableFrom(bean)
|| addTypeMethods.size() != 0;
}
@@ -729,6 +777,7 @@
nestedCreators.containsKey(name.toLowerCase(Locale.US))
&& (uri.equals(parentUri))) // || uri.equals("")))
|| DynamicConfigurator.class.isAssignableFrom(bean)
+ || DynamicConfiguratorNS.class.isAssignableFrom(bean)
|| addTypeMethods.size() != 0;
}
1.113 +3 -0 ant/src/main/org/apache/tools/ant/ProjectHelper.java
Index: ProjectHelper.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -r1.112 -r1.113
--- ProjectHelper.java 13 May 2004 07:06:49 -0000 1.112
+++ ProjectHelper.java 24 May 2004 15:09:55 -0000 1.113
@@ -56,6 +56,9 @@
/** The URI for defined types/tasks - the format is antlib:<package> */
public static final String ANTLIB_URI = "antlib:";
+ /** Polymorphic attribute */
+ public static final String ANT_TYPE = "ant-type";
+
/**
* Name of JVM system property which provides the name of the
* ProjectHelper class to use.
1.51 +2 -7 ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java
Index: RuntimeConfigurable.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- RuntimeConfigurable.java 9 Mar 2004 16:47:59 -0000 1.50
+++ RuntimeConfigurable.java 24 May 2004 15:09:55 -0000 1.51
@@ -40,9 +40,6 @@
*/
public class RuntimeConfigurable implements Serializable {
- /** Polymorphic attribute (May be XML NS attribute later) */
- private static final String ANT_TYPE = "ant-type";
-
/** Name of the element to configure. */
private String elementTag = null;
@@ -168,7 +165,7 @@
* @param value the attribute's value.
*/
public void setAttribute(String name, String value) {
- if (name.equalsIgnoreCase(ANT_TYPE)) {
+ if (name.equalsIgnoreCase(ProjectHelper.ANT_TYPE)) {
this.polyType = value;
} else {
if (attributeNames == null) {
@@ -353,7 +350,6 @@
Object target = (wrappedObject instanceof TypeAdapter)
? ((TypeAdapter) wrappedObject).getProxy() : wrappedObject;
- //PropertyHelper ph=PropertyHelper.getPropertyHelper(p);
IntrospectionHelper ih =
IntrospectionHelper.getHelper(p, target.getClass());
@@ -365,8 +361,7 @@
// reflect these into the target
value = p.replaceProperties(value);
try {
- ih.setAttribute(p, target,
- name.toLowerCase(Locale.US), value);
+ ih.setAttribute(p, target, name, value);
} catch (BuildException be) {
// id attribute must be set externally
if (!name.equals("id")) {
1.47 +6 -3 ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
Index: ProjectHelper2.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- ProjectHelper2.java 26 Apr 2004 17:49:51 -0000 1.46
+++ ProjectHelper2.java 24 May 2004 15:09:57 -0000 1.47
@@ -942,19 +942,22 @@
= new RuntimeConfigurable(task, task.getTaskName());
for (int i = 0; i < attrs.getLength(); i++) {
+ String name = attrs.getLocalName(i);
String attrUri = attrs.getURI(i);
if (attrUri != null
&& !attrUri.equals("")
&& !attrUri.equals(uri)) {
- continue; // Ignore attributes from unknown uris
+ name = attrUri + ":" + attrs.getQName(i);
}
- String name = attrs.getLocalName(i);
String value = attrs.getValue(i);
// PR: Hack for ant-type value
// an ant-type is a component name which can
// be namespaced, need to extract the name
// and convert from qualified name to uri/name
- if (name.equals("ant-type")) {
+ if (ANT_TYPE.equals(name)
+ || (ANT_CORE_URI.equals(attrUri)
+ && ANT_TYPE.equals(attrs.getLocalName(i)))) {
+ name = ANT_TYPE;
int index = value.indexOf(":");
if (index != -1) {
String prefix = value.substring(0, index);
1.6 +20 -16 ant/src/main/org/apache/tools/ant/util/XMLFragment.java
Index: XMLFragment.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/XMLFragment.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLFragment.java 9 Feb 2004 21:05:38 -0000 1.5
+++ XMLFragment.java 24 May 2004 15:09:57 -0000 1.6
@@ -24,7 +24,7 @@
import org.w3c.dom.Text;
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DynamicConfigurator;
+import org.apache.tools.ant.DynamicConfiguratorNS;
import org.apache.tools.ant.ProjectHelper;
/**
@@ -38,7 +38,7 @@
*
* @since Ant 1.7
*/
-public class XMLFragment implements DynamicConfigurator {
+public class XMLFragment implements DynamicConfiguratorNS {
private Document doc;
private DocumentFragment fragment;
@@ -66,7 +66,7 @@
/**
* No attributes for the wrapping element.
*/
- public void setDynamicAttribute(String name, String value)
+ public void setDynamicAttribute(String uri, String name, String qName, String value)
throws BuildException {
throw new BuildException("Attribute " + name + " is not supported.");
}
@@ -74,10 +74,8 @@
/**
* Creates a nested element.
*/
- public Object createDynamicElement(String name) {
- Element e = doc
- .createElementNS(ProjectHelper.extractUriFromComponentName(name),
- ProjectHelper.extractNameFromComponentName(name));
+ public Object createDynamicElement(String uri, String name, String qName) {
+ Element e = doc.createElementNS(uri, qName);
fragment.appendChild(e);
return new Child(e);
}
@@ -89,7 +87,7 @@
}
}
- public class Child implements DynamicConfigurator {
+ public class Child implements DynamicConfiguratorNS {
private Element e;
Child(Element e) {
@@ -106,19 +104,25 @@
/**
* Sets the attribute
*/
- public void setDynamicAttribute(String name, String value) {
- e.setAttribute(name, value);
+ public void setDynamicAttribute(
+ String uri, String name, String qName, String value) {
+ if (uri.equals("")) {
+ e.setAttribute(name, value);
+ } else {
+ e.setAttributeNS(uri, qName, value);
+ }
}
/**
* Creates a nested element.
*/
- public Object createDynamicElement(String name) {
- Element e2 = doc
- .createElementNS(ProjectHelper
- .extractUriFromComponentName(name),
- ProjectHelper
- .extractNameFromComponentName(name));
+ public Object createDynamicElement(String uri, String name, String qName) {
+ Element e2 = null;
+ if (uri.equals("")) {
+ e2 = doc.createElement(name);
+ } else {
+ e2 = doc.createElementNS(uri, qName);
+ }
e.appendChild(e2);
return new Child(e2);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant/util XMLFragment.java
Posted by Peter Reilly <pe...@corvil.com>.
Stefan Bodewig wrote:
>Peter,
>
>you forgot to cvs add DynamicConfiguratorNS itself. I'll comment the
>changes so that Ant can bootstrap again.
>
>
Opps,
I have added DynamicConfiguratorNS and decommented the changes.
Cheers,
Peter
>Stefan
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant/util
XMLFragment.java
Posted by Stefan Bodewig <bo...@apache.org>.
Peter,
you forgot to cvs add DynamicConfiguratorNS itself. I'll comment the
changes so that Ant can bootstrap again.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org