From 2a6e823ddbe8e7c29f5086c2b6d2fdafbbe4cb2d Mon Sep 17 00:00:00 2001 From: Costin Manolache Date: Fri, 13 Dec 2002 00:52:18 +0000 Subject: [PATCH] Add a method to support configuration using SAX2 attributes. Changed ( at least for few now ) the default helper to the SAX2 processor. The original processor can still be used using the system property, and we can revert if we have see problems. Description4 still fails - I'll add try to fix it later, I don't think it's a big show-stopper. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273656 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/ProjectHelper.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java index cce8f2fd6..b15556286 100644 --- a/src/main/org/apache/tools/ant/ProjectHelper.java +++ b/src/main/org/apache/tools/ant/ProjectHelper.java @@ -63,8 +63,10 @@ import java.util.Hashtable; import java.util.Locale; import java.util.Vector; import org.apache.tools.ant.helper.ProjectHelperImpl; +import org.apache.tools.ant.helper.ProjectHelper2; import org.apache.tools.ant.util.LoaderUtils; import org.xml.sax.AttributeList; +import org.xml.sax.Attributes; /** * Configures a Project (complete with Targets and Tasks) based on @@ -213,7 +215,8 @@ public class ProjectHelper { } else { try { // Default - return new ProjectHelperImpl(); + // return new ProjectHelperImpl(); + return new ProjectHelper2(); } catch (Throwable e) { String message = "Unable to load default ProjectHelper due to " + e.getClass().getName() + ": " + e.getMessage(); @@ -314,6 +317,44 @@ public class ProjectHelper { } } + /** Configure a component using SAX2 attributes. + */ + public static void configure( Object target, Attributes attrs, Project project ) + throws BuildException + { + if (target instanceof TaskAdapter) { + target = ((TaskAdapter) target).getProxy(); + } + + IntrospectionHelper ih = + IntrospectionHelper.getHelper(target.getClass()); + + // Why ??? + project.addBuildListener(ih); + + for (int i = 0; i < attrs.getLength(); i++) { + // reflect these into the target + String attValue=attrs.getValue(i); + + // XXX ADD SPECIAL CASE FOR ${property} - don't convert to string + // and support ARRAYS. + // reflect these into the target + //String value = replaceProperties(attValue); + String value = replaceProperties(project, attValue, + project.getProperties()); + try { + ih.setAttribute(project, target, + attrs.getQName(i).toLowerCase(Locale.US), value); + + } catch (BuildException be) { + // id attribute must be set externally + if (!attrs.getQName(i).equals("id")) { + throw be; + } + } + } + } + /** * Adds the content of #PCDATA sections to an element. *