View Javadoc
1   /**
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Intalio, Inc.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Intalio, Inc. Exolab is a registered
23   *    trademark of Intalio, Inc.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 1999-2003 (C) Intalio, Inc. All Rights Reserved.
42   *
43   * $Id$
44   */
45  
46  package org.exolab.castor.xml.schema;
47  
48  import org.exolab.castor.types.AnyNode;
49  import org.exolab.castor.xml.ValidationException;
50  
51  import java.util.Enumeration;
52  import java.util.Vector;
53  
54  /**
55   * A class which represents the superclass of
56   * either AppInfo or Documentation element.
57   *
58   * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
59   * @version $Revision$ $Date: 2003-03-03 02:57:21 -0700 (Mon, 03 Mar 2003) $ 
60   */
61  public abstract class AnnotationItem extends Structure {
62      
63      
64      /**
65       * List of any elements
66      **/
67      private Vector _objects = null;
68      
69      /**
70       * The source attribute
71      **/
72      private String _source = null;
73      
74      /**
75       * Creates a new AnnotationItem
76       */
77      AnnotationItem() {
78          _objects = new Vector(3);
79      } //-- AnnotationItem
80      
81      /**
82       * Adds the given Object to this Annotation item.
83       *
84       * @param object the Object to add
85       */
86      public void add(Object object) {
87          if (object != null)
88              _objects.addElement(object);
89      } //-- add
90      
91      /**
92       * Returns the String content of this Annotation item.
93       *
94       * @return the String content of this Annotation item.
95       */
96      public String getContent() {
97          if (_objects.size() == 0) return null;
98          StringBuffer sb = new StringBuffer();
99          for (int i = 0; i < _objects.size(); i++) {
100             Object obj = _objects.elementAt(i);
101             if (obj instanceof AnyNode) {
102                 //-- the getStringValue of AnyNode is a bit messed up
103                 //-- so we'll do our own here
104                 getStringValue((AnyNode)obj, sb);
105             }
106             else {
107                 sb.append(obj.toString());
108             }
109         }
110         return sb.toString();
111     } //-- getContent
112     
113     /**
114      * Returns an Enumeration of all objects contained by this Annotation item.
115      *
116      * @return an Enumeration of all objects contained by this Annotation item.
117      */
118     public Enumeration getObjects() {
119         return _objects.elements();
120     } //-- getObjects
121     
122     /**
123      * Returns the source property of this Annotaion item.
124      *
125      * @return the source property of this Annotation item.
126      */
127     public String getSource() {
128         return _source;
129     } //-- getSource
130     
131     /**
132      * Removes the given Object from this Annotation item.
133      *
134      * @param object the Object to remove
135      */
136     public void remove(Object object) {
137         if (object != null) _objects.removeElement(object);
138     } //-- remove
139 
140     /**
141      * Sets the source property for this Annotaion item.
142      *
143      * @param source the value of the source property
144      */
145     public void setSource(String source) {
146         _source = source;
147     } //-- setSource
148     
149     //-------------------------------/
150     //- Implementation of Structure -/
151     //-------------------------------/
152     
153     /**
154      * Returns the type of this Schema Structure
155      *
156      * @return the type of this Schema Structure
157      */
158     public abstract short getStructureType();
159     
160     /**
161      * Checks the validity of this Schema defintion.
162      * @exception ValidationException when this Schema definition
163      * is invalid.
164     **/
165     public void validate()
166         throws ValidationException 
167     {
168         //-- do nothing
169     } //-- validate
170     
171     /**
172      * Returns the concatenation of all the TEXT nodes in the given
173      * AnyNode in document order
174      *
175      * @param node the AnyNode to return the String value of
176      * @param buffer the StringBuffer to append to.
177      */
178     static final void getStringValue(AnyNode node, StringBuffer buffer) {
179         switch(node.getNodeType()) {
180             case AnyNode.ELEMENT:
181                 AnyNode child = node.getFirstChild();
182                 while (child != null) {
183                     getStringValue(child, buffer);
184                     child = child.getNextSibling();
185                 }
186                 break;
187             case AnyNode.TEXT:
188                 buffer.append(node.getStringValue());
189                 break;
190             default:
191                 break;
192         }
193     } //-- getStringValue
194     
195 } //-- AnnotationItem