hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/parse AbstractParser.java DescriptorParser.java
Date Mon, 03 May 2004 21:00:42 GMT
hlship      2004/05/03 14:00:42

  Modified:    framework/src/java/org/apache/hivemind/parse
                        AbstractParser.java DescriptorParser.java
  Log:
  Tweak AbstractParser to make it easier to create subclasses.
  
  Revision  Changes    Path
  1.2       +56 -2     jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/AbstractParser.java
  
  Index: AbstractParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/AbstractParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractParser.java	30 Apr 2004 19:22:39 -0000	1.1
  +++ AbstractParser.java	3 May 2004 21:00:42 -0000	1.2
  @@ -15,13 +15,16 @@
   package org.apache.hivemind.parse;
   
   import java.util.ArrayList;
  +import java.util.HashMap;
   import java.util.List;
  +import java.util.Map;
   
   import org.apache.hivemind.ApplicationRuntimeException;
   import org.apache.hivemind.HiveMind;
   import org.apache.hivemind.Location;
   import org.apache.hivemind.Resource;
   import org.apache.hivemind.impl.LocationImpl;
  +import org.xml.sax.Attributes;
   import org.xml.sax.Locator;
   import org.xml.sax.SAXException;
   import org.xml.sax.SAXParseException;
  @@ -89,7 +92,7 @@
               return null;
           }
       }
  -    
  +
       private int _currentColumn;
       private int _currentLine;
       private Location _location;
  @@ -364,4 +367,55 @@
           fatalError(ex);
       }
   
  +    private Map constructAttributesMap(Attributes attributes)
  +    {
  +        Map result = new HashMap();
  +        int count = attributes.getLength();
  +
  +        for (int i = 0; i < count; i++)
  +        {
  +            String key = attributes.getLocalName(i);
  +
  +            if (HiveMind.isBlank(key))
  +                key = attributes.getQName(i);
  +
  +            String value = attributes.getValue(i);
  +
  +            result.put(key, value);
  +        }
  +
  +        return result;
  +    }
  +
  +    /**
  +     * Invoked when an element's start tag is recognized. The element and attributes are
provided to the subclass
  +     * for further processing.
  +     */
  +    protected abstract void begin(String elementName, Map attributes);
  +
  +    /**
  +     * Invoked when an element's close tag is recognized. The element is provided. The
content of the
  +     * element (the unparsed whitespace within the element's tags) is available via
  +     * {@link #peekContent()}.
  +     */
  +
  +    protected abstract void end(String elementName);
  +
  +    public void endElement(String uri, String localName, String qName) throws SAXException
  +    {
  +        end(getElementName(localName, qName));
  +    }
  +
  +    public void startElement(String uri, String localName, String qName, Attributes attributes)
  +        throws SAXException
  +    {
  +        String elementName = getElementName(localName, qName);
  +
  +        begin(elementName, constructAttributesMap(attributes));
  +    }
  +
  +    private String getElementName(String localName, String qName)
  +    {
  +        return qName != null ? qName : localName;
  +    }
   }
  
  
  
  1.10      +4 -15     jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java
  
  Index: DescriptorParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DescriptorParser.java	30 Apr 2004 19:22:39 -0000	1.9
  +++ DescriptorParser.java	3 May 2004 21:00:42 -0000	1.10
  @@ -19,11 +19,9 @@
   import java.io.InputStream;
   import java.lang.reflect.Constructor;
   import java.net.URL;
  -import java.util.ArrayList;
   import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Iterator;
  -import java.util.List;
   import java.util.Map;
   import java.util.Properties;
   
  @@ -43,7 +41,6 @@
   import org.apache.hivemind.Resource;
   import org.apache.hivemind.impl.AttributeImpl;
   import org.apache.hivemind.impl.ElementImpl;
  -import org.apache.hivemind.impl.LocationImpl;
   import org.apache.hivemind.impl.RegistryAssembly;
   import org.apache.hivemind.impl.ServiceModelType;
   import org.apache.hivemind.schema.ElementModel;
  @@ -63,10 +60,7 @@
   import org.apache.hivemind.util.PropertyUtils;
   import org.xml.sax.Attributes;
   import org.xml.sax.InputSource;
  -import org.xml.sax.Locator;
   import org.xml.sax.SAXException;
  -import org.xml.sax.SAXParseException;
  -import org.xml.sax.helpers.DefaultHandler;
   
   /**
    * Used to parse HiveMind module deployment descriptors.
  @@ -471,15 +465,10 @@
           }
       }
   
  -    public void startElement(String uri, String localName, String qName, Attributes attributes)
  -        throws SAXException
  +    public void begin(String elementName, Map attributes)
       {
  -        // The SDL parser reports localName but not qName.  The standard SAX parsers
  -        // report qName but not localName.
   
  -        String elementName = qName != null ? qName : localName;
  -
  -        buildAttributes(attributes);
  +        _attributes = attributes;
   
           switch (getState())
           {
  @@ -556,7 +545,7 @@
           }
       }
   
  -    public void endElement(String uri, String localName, String qName) throws SAXException
  +    public void end(String elementName)
       {
           switch (getState())
           {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message