KickJava   Java API By Example, From Geeks To Geeks.

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


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.xml.sax.Attributes JavaDoc;
7 import org.xml.sax.SAXException JavaDoc;
8
9
10 /** The {@link javax.xml.parsers.SAXParser} is controlling
11  * an internal stack of {@link JMSAXGroupParser} instances, one
12  * for any nested sequence, choice, or all group being parsed.<br>
13  * Note, that complex types with complex content are
14  */

15 public abstract class JMSAXGroupParser {
16     protected abstract JMUnmarshallerHandlerImpl getHandler();
17
18     /** Equivalent to
19      * {@link org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)}.
20      */

21     public abstract boolean startElement(String JavaDoc pNamespaceURI, String JavaDoc pLocalName, String JavaDoc pQName,
22                                          Attributes JavaDoc pAttrs) throws SAXException JavaDoc;
23     /** Roughly equivalent to
24      * {@link org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)}.
25      * @param pResult The object that has been parsed.
26      */

27     public abstract void endElement(String JavaDoc pNamespaceURI, String JavaDoc pLocalName,
28                                     String JavaDoc pQName, Object JavaDoc pResult) throws SAXException JavaDoc;
29
30     /** Returns, whether the group contents are valid.
31      */

32     public abstract boolean isFinished();
33
34     private boolean isEmpty(char[] pChars, int pOffset, int pLen) {
35         for (int i = 0; i < pLen; i++) {
36             if (!Character.isWhitespace(pChars[pOffset+i])) {
37                 return false;
38             }
39         }
40         return true;
41     }
42
43     /** Returns, whether the group supports mixed content.
44      */

45     public boolean isMixed() {
46         return false;
47     }
48
49     /** Used for adding textual context. Valid only, if
50      * {@link #isMixed()} returns true.
51      * @param pChars Character buffer, as specified by
52      * {@link org.xml.sax.ContentHandler#characters(char[], int, int)}.
53      * @param pOffset Offset into buffer, as specified by
54      * {@link org.xml.sax.ContentHandler#characters(char[], int, int)}.
55      * @param pLen Length of relevant buffer part, as specified by
56      * {@link org.xml.sax.ContentHandler#characters(char[], int, int)}.
57      */

58     public void addText(char[] pChars, int pOffset, int pLen) throws SAXException JavaDoc {
59         if (!isEmpty(pChars, pOffset, pLen)) {
60             if (pLen > 100) {
61                 pLen = 100; // Keep the message approximately human readable.
62
}
63             getHandler().validationEvent(ValidationEvent.WARNING, "Unexpected non-whitespace characters: '" +
64                                          new String JavaDoc(pChars, pOffset, pLen) + "'",
65                                          ValidationEvents.EVENT_UNEXPECTED_TEXTUAL_CONTENTS,
66                                          null);
67         }
68     }
69 }
70
Popular Tags