Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /tada-sax/, /tada-sax/src/se/tada/util/sax/

tada-sax
Discussion topic

Back to topic list

CVS update: /tada-sax/, /tada-sax/src/se/tada/util/sax/

Reply

Author thhal
Full name Thomas Hallgren
Date 2005-05-17 03:47:51 PDT
Message User: thhal
Date: 2005/05/17 03:47:51

Added:
   tada-sax/plugin.xml
   tada-sax/build.properties

Modified:
   tada-sax/.cvsignore
   tada-sax/.project
   tada-sax/.classpath
   tada-sax/src/se/tada​/util/sax/Unrecogniz​edElementException.j​ava
   tada-sax/src/se/tada​/util/sax/Utils.java​
   tada-sax/src/se/tada​/util/sax/TopHandler​.java
   tada-sax/src/se/tada​/util/sax/ChildHandl​er.java

Log:
 Namespace support and support for xsi:type

File Changes:

Directory: /tada-sax/
=====================

File [changed]: .cvsignore
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/.cvsignore​?r1=1.2&r2=1.3
Delta lines: +1 -0
-------------------
--- .cvsignore 26 Jan 2005 21:43:20 -0000 1.2
+++ .cvsignore 17 May 2005 10:47:49 -0000 1.3
@@ -1,3 +1,4 @@
 output
 .settings
 
+bin

File [added]: plugin.xml
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/plugin.xml​?rev=1.1&content​-type=text/vnd.viewc​vs-markup
Added lines: 15
---------------
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
   id="se.tada.util.sax"
   name="tada-sax"
   version="1.0.1"
   provider-name="Tada AB, Täby Sweden">

   <runtime>
      <library name="tada-sax.jar">
         <export name="*"/>
      </library>
   </runtime>

</plugin>

File [added]: build.properties
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/build.prop​erties?rev=1.1&c​ontent-type=text/vnd​.viewcvs-markup
Added lines: 7
--------------
source.tada-sax.jar = src/
output.tada-sax.jar = bin/
bin.includes = plugin.xml,\
               tada-sax.jar,\
               COPYRIGHT
src.includes = src/,\
               COPYRIGHT

File [changed]: .project
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/.project?r​1=1.1&r2=1.2
Delta lines: +11 -0
--------------------
--- .project 25 Jan 2005 19:20:47 -0000 1.1
+++ .project 17 May 2005 10:47:49 -0000 1.2
@@ -10,8 +10,19 @@
             <arguments>
             </arguments>
         </buildCommand>
+ <buildCommand>
+ <name>org.ecli​pse.pde.ManifestBuil​der</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.ecli​pse.pde.SchemaBuilde​r</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
     </buildSpec>
     <natures>
+ <nature>org.ec​lipse.pde.PluginNatu​re</nature>
         <nature>org.ec​lipse.jdt.core.javan​ature</nature>​
     </natures>
 </projectDescription>

File [changed]: .classpath
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/.classpath​?r1=1.3&r2=1.4
Delta lines: +3 -2
-------------------
--- .classpath 26 Jan 2005 21:48:17 -0000 1.3
+++ .classpath 17 May 2005 10:47:49 -0000 1.4
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
- <classpathentry excluding="README.tx​t|tada-sax.jardesc" kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jd​t.launching.JRE_CONT​AINER/org.eclipse.jd​t.internal.debug.ui.​launcher.StandardVMT​ype/j2sdk1.4.2_07"/​>
+ <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="con" path="org.eclipse.pd​e.core.requiredPlugi​ns"/>
+ <classpathentry kind="con" path="org.eclipse.jd​t.launching.JRE_CONT​AINER"/>
     <classpathentry kind="output" path="bin"/>
 </classpath>

Directory: /tada-sax/src/se/tada/util/sax/
====================​====================​==

File [changed]: UnrecognizedElementE​xception.java
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/src/se/tad​a/util/sax/Unrecogni​zedElementException.​java?r1=1.2&r2=1​.3
Delta lines: +1 -1
-------------------
--- UnrecognizedElementE​xception.java 2 Mar 2005 21:24:50 -0000 1.2
+++ UnrecognizedElementE​xception.java 17 May 2005 10:47:49 -0000 1.3
@@ -20,7 +20,7 @@
 
     public UnrecognizedElementException (String inTag, String qName, Locator locator)
     {
- super("Unrecoginzed element <" + qName +
+ super("Unrecognized element <" + qName +
             "> encountered in tag <" + inTag + ">", locator);
     }
 }

File [changed]: Utils.java
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/src/se/tad​a/util/sax/Utils.jav​a?r1=1.1&r2=1.2
Delta lines: +25 -3
--------------------
--- Utils.java 26 Jan 2005 17:10:51 -0000 1.1
+++ Utils.java 17 May 2005 10:47:49 -0000 1.2
@@ -25,6 +25,7 @@
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.​AttributesImpl;
 
 /**
  * @author Thomas Hallgren
@@ -35,18 +36,37 @@
     private static final Object[] s_emptyArgs = new Object[] {};
     private static final SAXParserFactory s_parserFactory = SAXParserFactory.newInstance();
 
+
+ /**
+ * Adds a CDATA type attribute using the default namespace
+ * @param attrs The attribtue collection receiveing the attribute
+ * @param name The name of the attribute
+ * @param value The attribute value
+ */
+ public static void addAttribute(AttributesImpl attrs, String name, String value)
+ {
+ attrs.addAttribute("", name, name, "CDATA", value);
+ }
+
     /**
      * Create an XMLReader instance.
+ * @param validating true if a validating parser is desired
+ * @param withNamespace true if the parser is namespace aware
      * @return The created instance.
      * @throws SAXException If no XMLReader could be created.
      */
- public static XMLReader createXMLReader()
+ public static XMLReader createXMLReader(boolean validating, boolean withNamespace)
     throws SAXException
     {
         try
         {
+ synchronized(s_parserFactory)
+ {
+ s_parserFactory.setV​alidating(validating​);
+ s_parserFactory.setN​amespaceAware(withNa​mespace);
             return s_parserFactory.newS​AXParser().getXMLRea​der();
         }
+ }
         catch(ParserConfigur​ationException e)
         {
             throw new SAXException(e);
@@ -134,7 +154,9 @@
         // Java 5 has a bug that causes the indentation amount to be
         // lost when using an OutputStream instead of a Writer.
         //
- StreamResult out = new StreamResult(file);
+ StreamResult out = new StreamResult();
+ if(file != null)
+ out.setSystemId(file);
         if(java14 || indent <= 0)
             out.setOutputStream(stream);
         else

File [changed]: TopHandler.java
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/src/se/tad​a/util/sax/TopHandle​r.java?r1=1.4&r2​=1.5
Delta lines: +141 -23
----------------------
--- TopHandler.java 3 Mar 2005 15:20:53 -0000 1.4
+++ TopHandler.java 17 May 2005 10:47:49 -0000 1.5
@@ -12,6 +12,8 @@
 
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
@@ -32,6 +34,7 @@
     private XMLReader m_reader;
 
     private final Stack m_handlerStack = new Stack();
+
     private final ArrayList m_handlerCache = new ArrayList();
 
     /**
@@ -39,7 +42,8 @@
      * parent. The created <code>TopHandl​er</code> will become the content
      * handler of the parent.
      *
- * @param parent The XMLReader (the actual parser most likely).
+ * @param parent
+ * The XMLReader (the actual parser most likely).
      */
     protected TopHandler(XMLReader parent)
     {
@@ -48,19 +52,39 @@
     }
 
     /**
- * Obtains the current handler from the reader and
- * returns it.
+ * Obtains the current handler from the reader and returns it.
+ *
      * @return The handler that is current
      */
- public AbstractHandler getCurrentHandler()
+ public final AbstractHandler getCurrentHandler()
     {
         return (AbstractHandler)m_r​eader.getContentHand​ler();
     }
 
     /**
+ * Obtains the parent current handler
+ *
+ * @return The handler that is the parent of the current handler.
+ */
+ public AbstractHandler getParentHandler(ChildHandler handler)
+ {
+ int size = m_handlerStack.size();
+ if(handler == this.getCurrentHandler())
+ return (size == 0) ? this : (AbstractHandler)m_h​andlerStack.get(size​ - 1);
+
+ while(--size >= 0)
+ {
+ if(handler == m_handlerStack.get(size))
+ return (size == 0) ? this : (AbstractHandler)m_h​andlerStack.get(size​ - 1);
+ }
+ return null;
+ }
+
+ /**
      * Push a filter that will sit between the XMLReader and this handler.
      *
- * @param filter The filter.
+ * @param filter
+ * The filter.
      */
     public void pushFilter(XMLFilterImpl filter)
     {
@@ -90,14 +114,18 @@
      * to push a {@link ChildHandler}that maps to the root element of the XML
      * document.
      *
- * @param uri The Namespace URI, ignored.
- * @param localName The local name, ignored.
- * @param qName The qualified name, passed on to the thrown exception.
- * @param attributes The attributes attached to the element, ignored
- * @throws UnrecognizedElementException unless overridden.
+ * @param uri
+ * The Namespace URI, ignored.
+ * @param localName
+ * The local name, ignored.
+ * @param qName
+ * The qualified name, passed on to the thrown exception.
+ * @param attributes
+ * The attributes attached to the element, ignored
+ * @throws UnrecognizedElementException
+ * unless overridden.
      */
- public void startElement(String uri, String localName, String qName, Attributes attributes)
- throws SAXException
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
     {
         throw new UnrecognizedElementE​xception("root", qName, this.getDocumentLocator());
     }
@@ -105,9 +133,12 @@
     /**
      * Pop the current handler.
      *
- * @param uri The Namespace URI, ignored.
- * @param localName The local name, ignored.
- * @param qName The qualified name, ignored.
+ * @param uri
+ * The Namespace URI, ignored.
+ * @param localName
+ * The local name, ignored.
+ * @param qName
+ * The qualified name, ignored.
      */
     public void endElement(String uri, String localName, String qName) throws SAXException
     {
@@ -115,9 +146,10 @@
     }
 
     /**
- * Returns the encoding of the current document. This method must only
- * be after the call to {@link #startDocument()} has completed and
- * not after {@link #endDocument()} has completed.
+ * Returns the encoding of the current document. This method must only be
+ * after the call to {@link #startDocument()} has completed and not after
+ * {@link #endDocument()} has completed.
+ *
      * @return The document encoding for current document.
      */
     public String getEncoding()
@@ -152,6 +184,22 @@
     }
 
     /**
+ * Instruct this parser to use a specific EntityResolver.
+ */
+ public final void setEntityResolver(En​tityResolver resolver)
+ {
+ m_reader.setEntityRe​solver(resolver);
+ }
+
+ /**
+ * Instruct this parser to use a specific ErrorHandler.
+ */
+ public final void setErrorHandler(ErrorHandler errorHandler)
+ {
+ m_reader.setErrorHan​dler(errorHandler);
+ }
+
+ /**
      * Returns the XMLReader currently associated with this instance. This is
      * either the reader that was passed to the constructor or a filter that was
      * added using {@link #pushFilter(XMLFilterImpl)}.
@@ -179,16 +227,17 @@
      * handler. The handler is then made the <code>ContentH​andler</code> of
      * the current <code>XMLReade​r</code> and the previous handler is stacked.
      *
- * @param handler The new handler
- * @param attrs Attributes to pass to the new handler.
+ * @param handler
+ * The new handler
+ * @param attrs
+ * Attributes to pass to the new handler.
      * @throws SAXException
      */
- protected final void pushHandler(ChildHandler handler, Attributes attrs)
- throws SAXException
+ protected final void pushHandler(ChildHandler handler, Attributes attrs) throws SAXException
     {
- handler.handleAttrib​utes(attrs);
         m_handlerStack.push(​m_reader.getContentH​andler());
         m_reader.setContentH​andler(handler);
+ handler.handleAttrib​utes(attrs);
     }
 
     /**
@@ -230,5 +279,74 @@
             ++cacheSize;
         }
         return (HashMap)m_handlerCa​che.get(depth);
+ }
+
+ /**
+ * The SAXParserWrapper class is useful for parser implementations that want
+ * to expose themselves as a {@link ContentHandler}. The ContentHandler
+ * interface of the <code>TopHandl​er</code> is already taken and deciated
+ * to a handler that handles the top element only. An instance of
+ * <code>SAXParse​rWrapper</code​> will dispatch all events to the current
+ * <code>ContentH​andler</code> of the internal {@link XMLReader} and thus
+ * handle the full document.
+ *
+ * @author thhal
+ */
+ protected class SAXParserWrapper implements ContentHandler
+ {
+ public void setDocumentLocator(Locator locator)
+ {
+ m_reader.getContentH​andler().setDocument​Locator(locator);
+ }
+
+ public void startDocument() throws SAXException
+ {
+ m_reader.getContentH​andler().startDocume​nt();
+ }
+
+ public void endDocument() throws SAXException
+ {
+ m_reader.getContentH​andler().endDocument​();
+ }
+
+ public void startPrefixMapping(String prefix, String uri) throws SAXException
+ {
+ m_reader.getContentH​andler().startPrefix​Mapping(prefix, uri);
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException
+ {
+ m_reader.getContentH​andler().endPrefixMa​pping(prefix);
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
+ {
+ m_reader.getContentH​andler().startElemen​t(uri, localName, qName, atts);
+ }
+
+ public void endElement(String uri, String localName, String qName) throws SAXException
+ {
+ m_reader.getContentH​andler().endElement(​uri, localName, qName);
+ }
+
+ public void characters(char[] ch, int start, int length) throws SAXException
+ {
+ m_reader.getContentH​andler().characters(​ch, start, length);
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
+ {
+ m_reader.getContentH​andler().ignorableWh​itespace(ch, start, length);
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException
+ {
+ m_reader.getContentH​andler().processingI​nstruction(target, data);
+ }
+
+ public void skippedEntity(String name) throws SAXException
+ {
+ m_reader.getContentH​andler().skippedEnti​ty(name);
+ }
     }
 }

File [changed]: ChildHandler.java
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/src/se/tad​a/util/sax/ChildHand​ler.java?r1=1.2&​r2=1.3
Delta lines: +183 -144
-----------------------
--- ChildHandler.java 3 Mar 2005 15:20:53 -0000 1.2
+++ ChildHandler.java 17 May 2005 10:47:49 -0000 1.3
@@ -10,136 +10,144 @@
 import java.lang.reflect.Modifier;
 import java.util.HashMap;
 
+import javax.xml.XMLConstants;
+
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
 /**
- * This handler is the subclass of all handlers in the
- * Tada SAX parser system except the root handler. It
- * defines a standard way to associate a handler with an
- * element using a static public string variable called
- * <code>TAG</code>. Handlers are cached and reused.
- * The implementor of a <code>ChildHan​dler</code> should
- * implement the method {@link #createHandler(String qName)}
- * in order to create handlers for nested elements and the method
- * {@link #handleAttributes(Attributes)} to handle the attributes
- * for the element that the handler represents.
- * A concrete subclass of <code>ChildHan​dler</code> must also
- * have a static String attribute called <code>TAG</code>.
+ * This handler is the subclass of all handlers in the Tada SAX parser system
+ * except the root handler. It defines a standard way to associate a handler
+ * with an element using a static public string variable called <code>TAG</code>.
+ * Handlers are cached and reused. The implementor of a
+ * <code>ChildHan​dler</code> should implement the method
+ * {@link #createHandler(String qName)} in order to create handlers for nested
+ * elements and the method {@link #handleAttributes(Attributes)} to handle the
+ * attributes for the element that the handler represents. A concrete subclass
+ * of <code>ChildHan​dler</code> must also have a static String attribute
+ * called <code>TAG</code>.
  *
  * @author Thomas Hallgren
  */
 public abstract class ChildHandler extends AbstractHandler
 {
- private final NSKey m_nsKeyTemplate = new NSKey();
+ private static final HandlerKey s_keyTemplate = new HandlerKey();
+
     private TopHandler m_topHandler;
 
     /**
- * Push a handler that corresponds to the <code>qName</code>, cached
- * or created, on the handler stack so that it becomes the current
+ * Push a handler that corresponds to the <code>qName</code>, cached or
+ * created, on the handler stack so that it becomes the current
      * <code>ContentH​andler</code> of the <code>TopHandl​er</code>.
- * @param uri The Namespace URI.
- * @param localName The local name.
- * @param qName The qualified name.
- * @param attributes The attributes that will be sent to the
- * {@link #handleAttributes(Attributes)} method of the new handler.
- * @exception org.xml.sax.SAXException Any SAX exception, possibly
- * wrapping another exception.
+ *
+ * @param uri
+ * The Namespace URI.
+ * @param localName
+ * The local name.
+ * @param qName
+ * The qualified name.
+ * @param attributes
+ * The attributes that will be sent to the
+ * {@link #handleAttributes(Attributes)} method of the new
+ * handler.
+ * @exception org.xml.sax.SAXException
+ * Any SAX exception, possibly wrapping another exception.
      */
- public void startElement(String uri, String localName, String qName, Attributes attrs)
- throws SAXException
+ public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException
     {
         if(localName.length() == 0)
             localName = qName;
         if(uri.length() == 0)
             uri = null;
- this.pushHandler(thi​s.getHandler(uri, localName), attrs);
+ this.pushHandler(thi​s.getHandler(uri, localName, attrs), attrs);
     }
 
     /**
      * Pop this handler from the <code>TopHandl​er</code> handler stack.
- * @param uri The Namespace URI, ignored.
- * @param localName The local name, ignored.
- * @param qName The qualified name, ignored.
+ *
+ * @param uri
+ * The Namespace URI, ignored.
+ * @param localName
+ * The local name, ignored.
+ * @param qName
+ * The qualified name, ignored.
      */
- public void endElement(String uri, String localName, String qName)
- throws SAXException
+ public void endElement(String uri, String localName, String qName) throws SAXException
     {
         this.popHandler();
     }
 
     /**
- * Obtain a new or cached handler that corresponds to the
- * <code>uri</code> and <code>localNam​e</code>.
- * @param <code>uri</code> The namespace URI or <code>null</code>
- * if no namespace processing is performed.
- * @param <code>localNam​e</code> The local tag name of the
- * element for which a handler should be obtained.
+ * Obtain a new or cached handler that corresponds to the <code>uri</code>
+ * and <code>localNam​e</code>.
+ *
+ * @param <code>uri</code> The namespace URI or <code>null</code> if no
+ * namespace processing is performed.
+ * @param <code>localNam​e</code> The local tag name of the element for which
+ * a handler should be obtained.
+ * @param attrs
+ * Attributes passed to the element definition
      * @return The handler that corresponds to <code>qName</code>.
- * @throws UnrecognizedElementException when no handler
- * could be found or created.
+ * @throws UnrecognizedElementException
+ * when no handler could be found or created.
      */
- protected ChildHandler getHandler(String uri, String localName)
+ protected ChildHandler getHandler(String uri, String localName, Attributes attrs)
     throws UnrecognizedElementException
     {
- ChildHandler ch;
+ String typeName = attrs.getValue(XMLCo​nstants.W3C_XML_SCHE​MA_NS_URI, "type");
         HashMap handlerCache = this.getTopHandler()​.getHandlerCache();
- if(uri == null)
- {
- ch = (ChildHandler)handle​rCache.get(localName​);
- if(ch == null)
- {
- ch = this.createHandler(uri, localName);
- ch.setTopHandler(m_topHandler);
- handlerCache.put(localName, ch);
- }
- }
- else
+ synchronized(s_keyTemplate)
         {
- m_nsKeyTemplate.init(uri, localName);
- ch = (ChildHandler)handle​rCache.get(m_nsKeyTe​mplate);
+ s_keyTemplate.init(uri, localName, typeName);
+ ChildHandler ch = (ChildHandler)handle​rCache.get(s_keyTemp​late);
             if(ch == null)
             {
- ch = this.createHandler(uri, localName);
+ ch = this.createHandler(uri, localName, typeName);
+ handlerCache.put(s_k​eyTemplate.clone(), ch);
                 ch.setTopHandler(m_topHandler);
- handlerCache.put(m_n​sKeyTemplate.clone()​, ch);
- }
         }
         return ch;
     }
+ }
 
     /**
- * This method must be overridden by handlers that deals with
- * nested elements.
- * @param qName The qualified tag name of the
- * element for which a handler should be created.
- * @return Derived methods returns a new handler that corresponds
- * to <code>qName</code>.
- * @throws UnrecognizedElementException unless overridden.
+ * This method must be overridden by handlers that deals with nested
+ * elements.
+ *
+ * @param uri
+ * The namespace of the element for which a handler should be
+ * created or <code>null</code> if namespace are not used.
+ * @param localName The unqualified name of the element.
+ * @param typeName The value of the xsi:type attribute. May be <code>null</code>.
+ * @return Derived methods returns a new handler that corresponds to
+ * <code>qName</code>.
+ * @throws UnrecognizedElementException
+ * unless overridden.
      */
- protected ChildHandler createHandler(String uri, String localName)
+ protected ChildHandler createHandler(String uri, String localName, String typeName)
     throws UnrecognizedElementException
     {
- throw new UnrecognizedElementException(
- this.getTAG(), localName, this.getDocumentLocator());
+ throw new UnrecognizedElementE​xception(this.getTAG​(), localName, this.getDocumentLocator());
     }
 
     /**
- * This method should be overridden by handlers that deals with
- * element attributes. By default, this method does nothing.
+ * This method should be overridden by handlers that deals with element
+ * attributes. By default, this method does nothing.
      *
- * @param attributes The attributes as passed to the
+ * @param attributes
+ * The attributes as passed to the
      * {@link #startElement(String, String, String, Attributes)}
      * method.
      * @throws SAXException
      */
- protected void handleAttributes(Attributes attributes)
- throws SAXException
- {}
+ protected void handleAttributes(Attributes attributes) throws SAXException
+ {
+ }
 
     /**
      * Returns the document locator.
+ *
      * @return the document locator.
      */
     protected final Locator getDocumentLocator()
@@ -147,8 +155,14 @@
         return m_topHandler.getDocu​mentLocator();
     }
 
+ protected final AbstractHandler getParentHandler()
+ {
+ return m_topHandler.getPare​ntHandler(this);
+ }
+
     /**
      * Returns the top element handler.
+ *
      * @return the top element handler.
      */
     protected final TopHandler getTopHandler()
@@ -157,8 +171,7 @@
     }
 
     /**
- * Pop the current handler from the <code>TopHandl​er</code> handler
- * stack.
+ * Pop the current handler from the <code>TopHandl​er</code> handler stack.
      */
     protected final void popHandler()
     {
@@ -168,22 +181,25 @@
     /**
      * Push a handler on the <code>TopHandl​er</code> handler stack so that it
      * becomes the active <code>ContentH​andler</code>.​
- * @param handler The handler to push.
- * @param attrs Attributes to send to the
- * {@link #handleAttributes(Attributes)} method of the new handler.
+ *
+ * @param handler
+ * The handler to push.
+ * @param attrs
+ * Attributes to send to the
+ * {@link #handleAttributes(Attributes)} method of the new
+ * handler.
      * @throws SAXException
      */
- protected final void pushHandler(ChildHandler handler, Attributes attrs)
- throws SAXException
+ protected final void pushHandler(ChildHandler handler, Attributes attrs) throws SAXException
     {
         m_topHandler.pushHan​dler(handler, attrs);
     }
 
     /**
- * Return the value of the public static String TAG field declared
- * for the class of the receiver of the call.
+ * Return the value of the public static String TAG field declared for the
+ * class of the receiver of the call.
      */
- protected final String getTAG()
+ protected String getTAG()
     {
         try
         {
@@ -191,9 +207,7 @@
             int mods = idField.getModifiers();
             if(!idField.isAccessible())
                 idField.setAccessible(true);
- return (Modifier.isStatic(mods))
- ? (String)idField.get(null)
- : null;
+ return (Modifier.isStatic(mods)) ? (String)idField.get(null) : null;
         }
         catch(NoSuchFieldException e)
         {
@@ -210,24 +224,36 @@
      * Assign the <code>TopHandl​er</code>. This method is only called once at
      * creation time.
      *
- * @param topHandler The topmost handler of the handler hierarcy.
+ * @param topHandler
+ * The topmost handler of the handler hierarcy.
      */
     protected final void setTopHandler(TopHandler topHandler)
     {
         m_topHandler = topHandler;
     }
 
- private static class NSKey implements Cloneable
+ private static class HandlerKey implements Cloneable
     {
         private String m_uri;
+
         private String m_localName;
+
+ private String m_typeName;
+
         private int m_hash;
 
- void init(String uri, String localName)
+ void init(String uri, String localName, String typeName)
         {
+ int hash = (localName == null) ? 1 : 31 + localName.hashCode();
+ if(uri != null)
+ hash = 31 * hash + uri.hashCode();
+ if(typeName != null)
+ hash = 31 * hash + typeName.hashCode();
+
             m_uri = uri;
             m_localName = localName;
- m_hash = (m_uri.hashCode() << 3) ^ m_localName.hashCode();
+ m_typeName = typeName;
+ m_hash = hash;
         }
 
         public Object clone()
@@ -244,15 +270,28 @@
 
         public boolean equals(Object obj)
         {
- if(!(obj instanceof NSKey))
+ if(this == obj)
+ return true;
+
+ if(!(obj instanceof HandlerKey))
                 return false;
- NSKey other = (NSKey)obj;
- return other.m_uri.equals(m_uri) && other.m_localName.eq​uals(m_localName);
+
+ HandlerKey other = (HandlerKey)obj;
+ return nullEquals(m_uri, other.m_uri)
+ && nullEquals(m_typeName, other.m_typeName)
+ && nullEquals(m_localName, other.m_localName);
         }
 
         public int hashCode()
         {
             return m_hash;
+ }
+
+ private static boolean nullEquals(String a, String b)
+ {
+ return (a == null)
+ ? (b == null)
+ : (b != null) && a.equals(b);
         }
     }
 }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /tada-sax/, /tada-sax/src/se/tada/util/sax/ thhal Thomas Hallgren 2005-05-17 03:47:51 PDT
Messages per page: