ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder DefaultModelBuilder.java
Date Sun, 19 May 2002 08:32:01 GMT
donaldp     02/05/19 01:32:01

  Added:       container/src/java/org/apache/myrmidon/components/builder
                        DefaultModelBuilder.java
  Log:
  Create a basic implementation of ModelBuilder.
  
  Revision  Changes    Path
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/DefaultModelBuilder.java
  
  Index: DefaultModelBuilder.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.components.builder;
  
  import javax.xml.parsers.SAXParser;
  import javax.xml.parsers.SAXParserFactory;
  import org.apache.myrmidon.api.metadata.ModelElement;
  import org.apache.myrmidon.api.metadata.ModelException;
  import org.apache.myrmidon.interfaces.builder.ModelBuilder;
  import org.apache.myrmidon.interfaces.model.ModelElementSaxHandler;
  import org.xml.sax.XMLReader;
  
  /**
   * A simple ModelBuilder that will build a {@link ModelElement}
   * tree from an XML source.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/19 08:32:01 $
   */
  public class DefaultModelBuilder
      implements ModelBuilder
  {
      public ModelElement build( final String source )
          throws ModelException
      {
          try
          {
              final ModelElementSaxHandler contentHandler = new ModelElementSaxHandler();
              final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
              final SAXParser saxParser = saxParserFactory.newSAXParser();
              final XMLReader parser = saxParser.getXMLReader();
              parser.setFeature( "http://xml.org/sax/features/namespace-prefixes", false );
              parser.setFeature( "http://xml.org/sax/features/namespaces", false );
              //parser.setFeature( "http://xml.org/sax/features/validation", false );
  
              parser.setContentHandler( contentHandler );
              parser.parse( source );
  
              return contentHandler.getModel();
          }
          catch( final Exception e )
          {
              final String message = e.getMessage();
              throw new ModelException( message, e );
          }
      }
  }
  
  
  

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


Mime
View raw message