ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/util JAXPUtils.java
Date Fri, 28 Nov 2003 12:36:34 GMT
bodewig     2003/11/28 04:36:34

  Modified:    src/main/org/apache/tools/ant/util Tag: ANT_16_BRANCH
                        JAXPUtils.java
  Log:
  Merge into 1.6
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.9.2.1   +42 -0     ant/src/main/org/apache/tools/ant/util/JAXPUtils.java
  
  Index: JAXPUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/JAXPUtils.java,v
  retrieving revision 1.9
  retrieving revision 1.9.2.1
  diff -u -r1.9 -r1.9.2.1
  --- JAXPUtils.java	21 Sep 2003 20:20:03 -0000	1.9
  +++ JAXPUtils.java	28 Nov 2003 12:36:34 -0000	1.9.2.1
  @@ -54,6 +54,8 @@
   package org.apache.tools.ant.util;
   
   import java.io.File;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
   import javax.xml.parsers.FactoryConfigurationError;
   import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.parsers.SAXParser;
  @@ -97,6 +99,12 @@
        */
       private static SAXParserFactory nsParserFactory = null;
   
  +    /**
  +     * Parser factory to use to create document builders.
  +     *
  +     * @since Ant 1.6
  +     */
  +    private static DocumentBuilderFactory builderFactory = null;
   
       /**
        * Returns the parser factory to use. Only one parser factory is
  @@ -210,6 +218,20 @@
       }
   
       /**
  +     * Returns a newly created DocumentBuilder.
  +     *
  +     * @return a DocumentBuilder
  +     * @since Ant 1.6
  +     */
  +    public static DocumentBuilder getDocumentBuilder() throws BuildException {
  +        try {
  +            return getDocumentBuilderFactory().newDocumentBuilder();
  +        } catch (ParserConfigurationException e) {
  +            throw new BuildException(e);
  +        }
  +    }
  +
  +    /**
        * @return a new SAXParser instance as helper for getParser and
        * getXMLReader.
        *
  @@ -239,6 +261,26 @@
           } else {
               return new BuildException(e);
           }
  +    }
  +
  +    /**
  +     * Obtains the default builder factory if not already.
  +     *
  +     * @since Ant 1.6
  +     */
  +    private static synchronized 
  +        DocumentBuilderFactory getDocumentBuilderFactory() 
  +        throws BuildException {
  +        if (builderFactory == null) {
  +            try {
  +                builderFactory = DocumentBuilderFactory.newInstance();
  +            } catch (FactoryConfigurationError e) {
  +                throw new BuildException("Document builder factory has not "
  +                                         + "been configured correctly: "
  +                                         + e.getMessage(), e);
  +            }
  +        }
  +        return builderFactory;
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message