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  
39  /**
40   * A class which holds the names for many of the Schema related components.
41   * 
42   * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
43   * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
44   **/
45  public class SchemaNames {
46  
47    // -- packages
48    public static final String SCHEMA_PACKAGE = "org.exolab.castor.xml.schema";
49  
50    // -- element definitions
51    public static final String ALL = "all";
52    public static final String ANNOTATION = "annotation";
53    public static final String ANY = "any";
54    public static final String ANYTYPE = "anyType";
55    public static final String ANY_ATTRIBUTE = "anyAttribute";
56    public static final String APPINFO = "appinfo";
57    public static final String ATTRIBUTE = "attribute";
58    public static final String ATTRIBUTE_GROUP = "attributeGroup";
59    public static final String CHOICE = "choice";
60    public static final String COMPLEX_CONTENT = "complexContent";
61    public static final String COMPLEX_TYPE = "complexType";
62    public static final String DOCUMENTATION = "documentation";
63    public static final String ELEMENT = "element";
64    public static final String ENUMERATION = "enumeration";
65    public static final String EXTENSION = "extension";
66    public static final String FIELD = "field";
67    public static final String GROUP = "group";
68    public static final String INCLUDE = "include";
69    public static final String IMPORT = "import";
70    public static final String KEY = "key";
71    public static final String KEYREF = "keyref";
72    public static final String LIST = "list";
73    public static final String MAX_EXCLUSIVE = "maxExclusive";
74    public static final String MAX_INCLUSIVE = "maxInclusive";
75    public static final String MIN_EXCLUSIVE = "minExclusive";
76    public static final String MIN_INCLUSIVE = "minInclusive";
77    public static final String REDEFINE = "redefine";
78    public static final String RESTRICTION = "restriction";
79    public static final String SCHEMA = "schema";
80    public static final String SELECTOR = "selector";
81    public static final String SEQUENCE = "sequence";
82    public static final String SIMPLETYPE_REF = "simpletypeRef";
83    public static final String SIMPLE_CONTENT = "simpleContent";
84    public static final String SIMPLE_TYPE = "simpleType";
85    public static final String UNION = "union";
86    public static final String UNIQUE = "unique";
87  
88    // -- Attr name definitions
89    public static final String ABSTRACT = "abstract";
90    public static final String ATTR_FORM_DEFAULT_ATTR = "attributeFormDefault";
91    public static final String BASE_ATTR = "base";
92    public static final String BLOCK_ATTR = "block";
93    public static final String BLOCK_DEFAULT_ATTR = "blockDefault";
94    public static final String DEFAULT_ATTR = "default";
95    public static final String ELEM_FORM_DEFAULT_ATTR = "elementFormDefault";
96    public static final String ID_ATTR = "id";
97    public static final String ITEM_TYPE_ATTR = "itemType";
98    public static final String FINAL_ATTR = "final";
99    public static final String FINAL_DEFAULT_ATTR = "finalDefault";
100   public static final String FIXED_ATTR = "fixed";
101   public static final String FORM = "form";
102   public static final String MAX_OCCURS_ATTR = "maxOccurs";
103   public static final String MEMBER_TYPES_ATTR = "memberTypes";
104   public static final String MIN_OCCURS_ATTR = "minOccurs";
105   public static final String MIXED = "mixed";
106   public static final String NAME_ATTR = "name";
107   public static final String NAMESPACE = "namespace";
108   public static final String NILLABLE_ATTR = "nillable";
109   public static final String ORDER_ATTR = "order";
110   public static final String PROCESS_CONTENTS = "processContents";
111   public static final String REF_ATTR = "ref";
112   public static final String REFER_ATTR = "refer";
113   public static final String SCHEMALOCATION_ATTR = "schemaLocation";
114   public static final String SOURCE_ATTR = "source";
115   public static final String SUBSTITUTION_GROUP_ATTR = "substitutionGroup";
116   public static final String TARGET_NS_ATTR = "targetNamespace";
117   public static final String TYPE_ATTR = "type";
118   public static final String USE_ATTR = "use";
119   public static final String VALUE_ATTR = "value";
120   public static final String VERSION_ATTR = "version";
121   public static final String XPATH_ATTR = "xpath";
122 
123   // -- data types
124   public static final String INTEGER_TYPE = "integer";
125   public static final String INT_TYPE = "int";
126   public static final String STRING_TYPE = "string";
127 
128   // -- namespaces
129   public static final String NAMESPACE_ANY = "##any";
130   public static final String NAMESPACE_LOCAL = "##local";
131   public static final String NAMESPACE_OTHER = "##other";
132   public static final String NAMESPACE_TARGET = "##targetNamespace";
133 
134   // -- processContents
135   public static final String LAX = "lax";
136   public static final String SKIP = "skip";
137   public static final String STRICT = "strict";
138 
139   // -- Wildcard name
140   public static final String WILDCARD = "wildcard";
141 
142 
143   /**
144    * Returns the name for the Schema Structure.
145    *
146    * @param structure the Structure to return the name for
147    * @return the Structure name
148    */
149   public static String getStructureName(Structure structure) {
150 
151     if (structure == null)
152       return null;
153 
154     switch (structure.getStructureType()) {
155       case Structure.ANYTYPE:
156         return ANYTYPE;
157       case Structure.ANNOTATION:
158         return ANNOTATION;
159       case Structure.APPINFO:
160         return APPINFO;
161       case Structure.ATTRIBUTE:
162         return ATTRIBUTE;
163       case Structure.ATTRIBUTE_GROUP:
164         return ATTRIBUTE_GROUP;
165       case Structure.COMPLEX_CONTENT:
166         return COMPLEX_CONTENT;
167       case Structure.COMPLEX_TYPE:
168         return COMPLEX_TYPE;
169       case Structure.DOCUMENTATION:
170         return DOCUMENTATION;
171       case Structure.ELEMENT:
172         return ELEMENT;
173       case Structure.FACET:
174         Facet facet = (Facet) structure;
175         return facet.getName();
176       case Structure.GROUP:
177         Group group = (Group) structure;
178         Order order = group.getOrder();
179         return order.toString();
180       case Structure.IDENTITY_FIELD:
181         return FIELD;
182       case Structure.IDENTITY_SELECTOR:
183         return SELECTOR;
184       case Structure.KEY:
185         return KEY;
186       case Structure.KEYREF:
187         return KEYREF;
188       case Structure.LIST:
189         return LIST;
190       case Structure.MODELGROUP:
191         return GROUP;
192       case Structure.MODELGROUP_REF:
193         return GROUP;
194       case Structure.REDEFINE:
195         return REDEFINE;
196       case Structure.SCHEMA:
197         return SCHEMA;
198       case Structure.SIMPLE_CONTENT:
199         return SIMPLE_CONTENT;
200       case Structure.SIMPLE_TYPE:
201         return SIMPLE_TYPE;
202       case Structure.UNION:
203         return UNION;
204       case Structure.UNIQUE:
205         return UNIQUE;
206       case Structure.WILDCARD:
207         return ANY;
208       default:
209         break;
210     }
211     return null;
212   } // -- getStructureName
213 
214   /**
215    * Determines whether or not the given name is the name of an XML Schema group structure.
216    * 
217    * @param name the name to test
218    * @return true if the given name is the name of a schema group
219    **/
220   public static boolean isGroupName(String name) {
221     return (SchemaNames.GROUP.equals(name) || SchemaNames.SEQUENCE.equals(name)
222         || SchemaNames.CHOICE.equals(name) || SchemaNames.ALL.equals(name));
223   } // -- isGroupName
224 
225   /**
226    * Determines whether or not the given name is the name of an XML Schema namespace attributes.
227    * Note: it assumes that the URI used are valid URL TODO: change the above restriction
228    * 
229    * @param name the name to test
230    * @return true if the given name is the name of a schema group
231    **/
232   public static boolean isNamespaceName(String name) {
233     boolean result = (SchemaNames.NAMESPACE_ANY.equals(name)
234         || SchemaNames.NAMESPACE_LOCAL.equals(name) || SchemaNames.NAMESPACE_OTHER.equals(name)
235         || SchemaNames.NAMESPACE_TARGET.equals(name));
236     if (result)
237       return result;
238     try {
239       new java.net.URL(name);
240       result = true;
241     } catch (java.net.MalformedURLException e) {
242       // invalid URL
243       result = false;
244     }
245     return result;
246   } // -- isNamespaceName
247 
248   /**
249    * Determines whether or not the given name is the name of an XML Schema Wildcard processContents
250    * attribute.
251    * 
252    * @param name the name to test
253    * @return true if the given name is a valid name of a processContents attribute
254    **/
255   public static boolean isProcessName(String name) {
256     return (SchemaNames.LAX.equals(name) || SchemaNames.SKIP.equals(name)
257         || SchemaNames.STRICT.equals(name));
258   } // -- isProcessName
259 
260 
261 } // -- SchemaNames