KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > impl > JMSAXElementParser


1 package org.apache.ws.jaxme.impl;
2
3 import javax.xml.bind.ValidationEvent;
4
5 import org.apache.ws.jaxme.ValidationEvents;
6 import org.apache.ws.jaxme.XMLConstants;
7 import org.apache.ws.jaxme.xs.xml.XsQName;
8 import org.xml.sax.Attributes JavaDoc;
9 import org.xml.sax.SAXException JavaDoc;
10
11
12 /** A subclass of {@link org.apache.ws.jaxme.impl.JMSAXGroupParser}
13  * for parsing complex elements.
14  */

15 public abstract class JMSAXElementParser extends JMSAXGroupParser {
16     private JMUnmarshallerHandlerImpl handler;
17     protected Object JavaDoc result;
18     private String JavaDoc namespaceURI, localName;
19     private int level;
20
21     public JMUnmarshallerHandlerImpl getHandler() {
22         return handler;
23     }
24
25     /** Returns, whether the element has atomic content.
26      */

27     public boolean isAtomic() { return false; }
28
29     /** Returns, whether the element is empty.
30      */

31     public boolean isEmpty() { return false; }
32
33     /** Returns the namespace URI of the element being parsed.
34      */

35     public String JavaDoc getNamespaceURI() { return namespaceURI; }
36     /** Returns the local name of the element being parsed.
37      */

38     public String JavaDoc getLocalName() { return localName; }
39     /** Returns the end elements level (number of nested
40      * elements enclosing this element).
41      */

42     public int getEndLevel() { return level; }
43
44     /** Initializes the element parser by setting the required data.
45      */

46     public void init(JMUnmarshallerHandlerImpl pHandler, Object JavaDoc pObject,
47                      String JavaDoc pNamespaceURI, String JavaDoc pLocalName, int pLevel) {
48         handler = pHandler;
49         result = pObject;
50         namespaceURI = pNamespaceURI;
51         localName = pLocalName;
52         level = pLevel;
53     }
54
55     /** Sets the attribute with the namespace
56      * <code>pNamespace</code> and the local name <code>pLocalName</code>
57      * to the value <code>pValue</code>.
58      */

59     public void addAttribute(String JavaDoc pNamespaceURI, String JavaDoc pLocalName,
60                              String JavaDoc pValue) throws SAXException JavaDoc {
61         if (javax.xml.XMLConstants.XML_NS_URI.equals(pNamespaceURI)
62             || javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(pNamespaceURI)
63             || XMLConstants.XML_SCHEMA_URI.equals(pNamespaceURI)) {
64             // Ignore attributes in the xsi namespace
65
} else {
66             XsQName qName = new XsQName(pNamespaceURI, pLocalName);
67             handler.validationEvent(ValidationEvent.WARNING, ValidationEvents.EVENT_UNKNOWN_ATTRIBUTE,
68                                     "Unknown attribute '" + qName + "' with value '"
69                                     + pValue + "'", null);
70         }
71     }
72
73     /** Invokes {@link #addAttribute(String, String, String)} for
74      * all the attributes in the list <code>pAttrs</code>.
75      */

76     public void setAttributes(Attributes JavaDoc pAttrs) throws SAXException JavaDoc {
77         if (pAttrs != null) {
78             for (int i = 0; i < pAttrs.getLength(); i++) {
79                 addAttribute(pAttrs.getURI(i), pAttrs.getLocalName(i),
80                              pAttrs.getValue(i));
81             }
82         }
83     }
84 }
85
Popular Tags