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