001: /**
002: * Redistribution and use of this software and associated documentation
003: * ("Software"), with or without modification, are permitted provided
004: * that the following conditions are met:
005: *
006: * 1. Redistributions of source code must retain copyright
007: * statements and notices. Redistributions must also contain a
008: * copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the
011: * above copyright notice, this list of conditions and the
012: * following disclaimer in the documentation and/or other
013: * materials provided with the distribution.
014: *
015: * 3. The name "Exolab" must not be used to endorse or promote
016: * products derived from this Software without prior written
017: * permission of Intalio, Inc. For written permission,
018: * please contact info@exolab.org.
019: *
020: * 4. Products derived from this Software may not be called "Exolab"
021: * nor may "Exolab" appear in their names without prior written
022: * permission of Intalio, Inc. Exolab is a registered
023: * trademark of Intalio, Inc.
024: *
025: * 5. Due credit should be given to the Exolab Project
026: * (http://www.exolab.org/).
027: *
028: * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
029: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
030: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
031: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
032: * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
033: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
034: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
035: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
036: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
037: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
038: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
039: * OF THE POSSIBILITY OF SUCH DAMAGE.
040: *
041: * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved.
042: *
043: * $Id: AnnotationUnmarshaller.java 5951 2006-05-30 22:18:48Z bsnyder $
044: */package org.exolab.castor.xml.schema.reader;
045:
046: //-- imported classes and packages
047: import org.exolab.castor.xml.AttributeSet;
048: import org.exolab.castor.xml.Namespaces;
049: import org.exolab.castor.xml.XMLException;
050: import org.exolab.castor.xml.schema.Annotation;
051: import org.exolab.castor.xml.schema.AppInfo;
052: import org.exolab.castor.xml.schema.Documentation;
053: import org.exolab.castor.xml.schema.SchemaNames;
054:
055: /**
056: * A class for Unmarshalling Annotations
057: * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
058: * @version $Revision: 5951 $ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
059: **/
060: public class AnnotationUnmarshaller extends ComponentReader {
061:
062: //--------------------/
063: //- Member Variables -/
064: //--------------------/
065:
066: /**
067: * The current ComponentReader
068: **/
069: private ComponentReader unmarshaller;
070:
071: /**
072: * The current branch depth
073: **/
074: private int depth = 0;
075:
076: /**
077: * The Annotation we are constructing
078: **/
079: private Annotation _annotation = null;
080:
081: //----------------/
082: //- Constructors -/
083: //----------------/
084:
085: /**
086: * Creates a new AnnotationUnmarshaller
087: * @param atts the AttributeList
088: **/
089: public AnnotationUnmarshaller(AttributeSet atts)
090: throws XMLException {
091: super ();
092:
093: _annotation = new Annotation();
094:
095: if ((atts != null) && (atts.getSize() > 0))
096: illegalAttribute(atts.getName(0));
097:
098: } //-- AnnotationUnmarshaller
099:
100: //-----------/
101: //- Methods -/
102: //-----------/
103:
104: /**
105: * Returns the name of the element that this ComponentReader
106: * handles
107: * @return the name of the element that this ComponentReader
108: * handles
109: **/
110: public String elementName() {
111: return SchemaNames.ANNOTATION;
112: } //-- elementName
113:
114: /**
115: *
116: **/
117: public Annotation getAnnotation() {
118: return _annotation;
119: } //-- getAnnotation
120:
121: /**
122: * Returns the Object created by this Unmarshaller
123: * @return the object created by this Unmarshaller
124: **/
125: public Object getObject() {
126: return getAnnotation();
127: } //-- getObject
128:
129: /**
130: * Signals the start of an element with the given name.
131: *
132: * @param name the NCName of the element. It is an error
133: * if the name is a QName (ie. contains a prefix).
134: * @param namespace the namespace of the element. This may be null.
135: * Note: A null namespace is not the same as the default namespace unless
136: * the default namespace is also null.
137: * @param atts the AttributeSet containing the attributes associated
138: * with the element.
139: * @param nsDecls the namespace declarations being declared for this
140: * element. This may be null.
141: **/
142: public void startElement(String name, String namespace,
143: AttributeSet atts, Namespaces nsDecls) throws XMLException {
144: //-- Do delagation if necessary
145: if (unmarshaller != null) {
146: unmarshaller.startElement(name, namespace, atts, nsDecls);
147: ++depth;
148: return;
149: }
150:
151: if (SchemaNames.APPINFO.equals(name)) {
152: unmarshaller = new AppInfoUnmarshaller(atts);
153: } else if (SchemaNames.DOCUMENTATION.equals(name)) {
154: unmarshaller = new DocumentationUnmarshaller(atts);
155: } else
156: illegalElement(name);
157:
158: } //-- startElement
159:
160: /**
161: * Signals to end of the element with the given name.
162: *
163: * @param name the NCName of the element. It is an error
164: * if the name is a QName (ie. contains a prefix).
165: * @param namespace the namespace of the element.
166: **/
167: public void endElement(String name, String namespace)
168: throws XMLException {
169:
170: //-- Do delagation if necessary
171: if ((unmarshaller != null) && (depth > 0)) {
172: unmarshaller.endElement(name, namespace);
173: --depth;
174: return;
175: }
176:
177: //-- have unmarshaller perform any necessary clean up
178: unmarshaller.finish();
179:
180: //-- appinfo
181: if (SchemaNames.APPINFO.equals(name)) {
182: _annotation.addAppInfo((AppInfo) unmarshaller.getObject());
183: }
184: //-- info
185: else {
186: _annotation.addDocumentation((Documentation) unmarshaller
187: .getObject());
188: }
189: unmarshaller = null;
190: } //-- endElement
191:
192: public void characters(char[] ch, int start, int length)
193: throws XMLException {
194: //-- Do delagation if necessary
195: if (unmarshaller != null) {
196: unmarshaller.characters(ch, start, length);
197: }
198:
199: } //-- characters
200:
201: } //-- ArchetypeUnmarshaller
|