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-2004 (C) Intalio, Inc. All Rights Reserved.
32   *
33   * $Id$
34   */
35  package org.exolab.castor.xml.descriptors;
36  
37  import org.exolab.castor.mapping.AccessMode;
38  import org.exolab.castor.mapping.ClassDescriptor;
39  import org.exolab.castor.mapping.FieldDescriptor;
40  import org.exolab.castor.xml.NodeType;
41  import org.exolab.castor.xml.TypeValidator;
42  import org.exolab.castor.xml.XMLFieldDescriptor;
43  import org.exolab.castor.xml.validators.StringValidator;
44  
45  /**
46   * The default String class descriptor.
47   * 
48   * @author <a href="mailto:kvisco-at-intalio.com">Keith Visco</a>
49   * @version $Revision$ $Date: 2004-12-16 22:49:25 -0700 (Thu, 16 Dec 2004) $
50   */
51  public class StringClassDescriptor extends BaseDescriptor {
52  
53    /** The set of element descriptors. */
54    private static final XMLFieldDescriptor[] NO_ELEMENTS = new XMLFieldDescriptor[0];
55    /** The set of attribute descriptors. */
56    private static final XMLFieldDescriptor[] NO_ATTRIBUTES = new XMLFieldDescriptor[0];
57    /** The content descriptor. */
58    private static final XMLFieldDescriptor NO_CONTENT = null;
59    /** Our field descriptor array. Lists the fields we describe. */
60    private static final FieldDescriptor[] NO_FIELDS = new FieldDescriptor[0];
61  
62    // --------------------/
63    // - Member Variables -/
64    // --------------------/
65  
66    /** The XML name for the described object. */
67    private String _xmlName = null;
68    /** The desired namespace for the described object. */
69    private String _nsURI = null;
70    /** Type validator to use to validate an instance of this type. */
71    private StringValidator _validator = null;
72  
73    // ----------------/
74    // - Constructors -/
75    // ----------------/
76  
77    /**
78     * No-arg constructor.
79     */
80    public StringClassDescriptor() {
81      super();
82    } // -- StringClassDescriptor()
83  
84    // -----------/
85    // - Methods -/
86    // -----------/
87  
88    /**
89     * Returns the set of attribute XMLFieldDescriptors.
90     *
91     * @return an array of XMLFieldDescriptors for all members that should be marshaled as attributes
92     */
93    public XMLFieldDescriptor[] getAttributeDescriptors() {
94      return NO_ATTRIBUTES;
95    } // -- getAttributeDescriptors()
96  
97    /**
98     * Returns the Class that this ClassDescriptor describes.
99     * 
100    * @return the Class that this ClassDescriptor describes.
101    */
102   public Class getJavaClass() {
103     return java.lang.String.class;
104   } // -- getClassType()
105 
106   /**
107    * Returns the set of element MarshalDescriptors.
108    *
109    * @return an array of MarshalDescriptors for all members that should be marshaled as Elements
110    */
111   public XMLFieldDescriptor[] getElementDescriptors() {
112     return NO_ELEMENTS;
113   } // -- getElementDescriptors()
114 
115   /**
116    * Returns the class descriptor of the class extended by this class.
117    *
118    * @return The extended class descriptor
119    */
120   public ClassDescriptor getExtends() {
121     return null;
122   } // -- getExtends
123 
124   /**
125    * Returns a list of fields represented by this descriptor.
126    *
127    * @return A list of fields
128    */
129   public FieldDescriptor[] getFields() {
130     return NO_FIELDS;
131   } // -- getFields
132 
133   /**
134    * Returns the descriptor for dealing with Text content.
135    * 
136    * @return the XMLFieldDescriptor for dealing with Text content
137    */
138   public XMLFieldDescriptor getContentDescriptor() {
139     return NO_CONTENT;
140   } // -- getContentDescriptor()
141 
142   /**
143    * Returns the XML field descriptor matching the given xml name and nodeType. If NodeType is null,
144    * then either an AttributeDescriptor, or ElementDescriptor may be returned. Null is returned if
145    * no matching descriptor is available.
146    *
147    * @param name the xml name to match against
148    * @param namespace the namespace uri
149    * @param nodeType the NodeType to match against, or null if the node type is not known.
150    * @return the matching descriptor, or null if no matching descriptor is available.
151    */
152   public XMLFieldDescriptor getFieldDescriptor(final String name, final String namespace,
153       final NodeType nodeType) {
154     return null;
155   } // -- getFieldDescriptor
156 
157   /**
158    * @return the namespace prefix to use when marshaling as XML.
159    */
160   public String getNameSpacePrefix() {
161     return null;
162   } // -- getNameSpacePrefix
163 
164   /**
165    * @return the namespace URI used when marshaling and unmarshaling as XML.
166    */
167   public String getNameSpaceURI() {
168     return _nsURI;
169   } // -- getNameSpaceURI
170 
171   /**
172    * Returns the identity field, null if this class has no identity.
173    *
174    * @return The identity field
175    */
176   public FieldDescriptor getIdentity() {
177     return null;
178   } // -- getIdentity
179 
180   /**
181    * Returns the access mode specified for this class.
182    *
183    * @return The access mode
184    */
185   public AccessMode getAccessMode() {
186     return null;
187   } // -- getAccessMode
188 
189   /**
190    * Returns a specific validator for the class described by this ClassDescriptor. A null value may
191    * be returned if no specific validator exists.
192    *
193    * @return the type validator for the class described by this ClassDescriptor.
194    */
195   public TypeValidator getValidator() {
196     return _validator;
197   } // -- getValidator
198 
199   /**
200    * Returns the XML Name for the Class being described.
201    *
202    * @return the XML name.
203    */
204   public String getXMLName() {
205     return _xmlName;
206   } // -- getXMLName
207 
208   /**
209    * Sets the type validator to use to validate an instance of this type.
210    * 
211    * @param validator the type validator to use.
212    */
213   public void setValidator(final StringValidator validator) {
214     this._validator = validator;
215   } // -- setValidator
216 
217   /**
218    * Sets the XML Name for the described object.
219    *
220    * @param xmlName the XML name to use for the described object.
221    */
222   public void setXMLName(final String xmlName) {
223     this._xmlName = xmlName;
224   } // -- setXMLName
225 
226   /**
227    * Sets the desired namespace URI for the described object.
228    *
229    * @param nsURI is the desired namespace URI
230    */
231   public void setNameSpaceURI(final String nsURI) {
232     this._nsURI = nsURI;
233   } // -- setNameSpaceURI
234 
235 } // -- StringMarshalInfo