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