summaryrefslogtreecommitdiffstats
path: root/sdo-java/branches/sdo-1.1-incubating/sdo-api/src/main/java/commonj/sdo/helper/XSDHelper.java
blob: af4f0026908e9f1a49126185736450496923ffac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
 * <copyright>
 *
 * Service Data Objects
 * Version 2.1.0
 * Licensed Materials
 *
 * (c) Copyright BEA Systems, Inc., International Business Machines Corporation, 
 * Oracle Corporation, Primeton Technologies Ltd., Rogue Wave Software, SAP AG., 
 * Software AG., Sun Microsystems, Sybase Inc., Xcalia, Zend Technologies, 
 * 2005, 2006. All rights reserved.
 *
 * </copyright>
 * 
 */

package commonj.sdo.helper;

import java.io.InputStream;
import java.io.Reader;
import java.util.List;
import java.util.Map;

import commonj.sdo.Property;
import commonj.sdo.Type;
import commonj.sdo.impl.HelperProvider;

/**
 * Provides access to additional information when the 
 * Type or Property is defined by an XML Schema (XSD).
 * Methods return null/false otherwise or if the information is unavailable.
 * Defines Types from an XSD.
*/
public interface XSDHelper
{
  /**
   * Returns the local name as declared in the XSD.
   * @param type to return local name for.
   * @return the local name as declared in the XSD.
   */
  String getLocalName(Type type);

  /**
   * Returns the local name as declared in the XSD.
   * @param property to return local name for.
   * @return the local name as declared in the XSD.
   */
  String getLocalName(Property property);
  
  /**
   * Returns the namespace URI as declared in the XSD.
   * @param property to return namespace URI for.
   * @return the namespace URI as declared in the XSD.
   */
  String getNamespaceURI(Property property);

  /**
   * Returns true if the property is declared as an attribute in the XSD.
   * Returns false if not known or for advanced cases.
   * It is possible for both isAttribute and isElement to return false
   * but they will not both return true.
   * @param property to identify if an attribute.
   * @return true if the property is declared as an attribute in the XSD.
   */
  boolean isAttribute(Property property);
  
  /**
   * Returns true if the property is declared as an element in the XSD.
   * Returns false if not known or for advanced cases.
   * It is possible for both isAttribute and isElement to return false
   * but they will not both return true.
   * @param property to identify if an element.
   * @return true if the property is declared as an element in the XSD.
   */
  boolean isElement(Property property);

  /**
   * Returns true if the Type is declared to contain mixed content.  
   * A DataObject's mixed content values are typically accessed via a Sequence.
   * @param type to identify if mixed content.
   * @return true if the Type is declared to contain mixed content.
   */
  boolean isMixed(Type type);

  /**
   * Indicates if this helper contains XSD information for the specified type.
   * @param type the type.
   * @return true if this helper contains XSD information for the specified type.
   */
  boolean isXSD(Type type);
  
  /**
   * Returns the Property defined by the named global element or attribute 
   *   in the targetNamespace uri, or null if not found.
   * @param uri The uri of the targetNamespace.
   * @param propertyName The name of the global property.
   * @param isElement is true for global elements, false for global attributes.
   * @return the Property defined by the named global element or attribute
   *   in the targetNamespace uri, or null if not found.
   */
  Property getGlobalProperty(String uri, String propertyName, boolean isElement);
  
  /**
   * Return the appinfo declared for this Type and source.
   * The appinfo start and end tags and content are returned.
   * The xml namespace context is preserved in the appinfo element.
   * If more than one appinfo with the same source is declared on the same
   * Type their contents are concatenated.
   * @param type the type with the appinfo declaration
   * @param source the source of the appinfo declaration.
   * @return the appinfo declared for this Type and source.
   */
  String getAppinfo(Type type, String source);

  /**
   * Return the content of the appinfo declared for this Property and source.
   * If the property is defined by ref= the appinfo of the referenced
   * element or attribute is included.
   * The appinfo start and end tags and content are returned.
   * The xml namespace context is preserved in the appinfo element.
   * If more than one appinfo with the same source is declared on the same
   * Type their contents are concatenated.
   * @param property the Property with the appinfo declaration
   * @param source the source of the appinfo declaration.
   * @return the appinfo declared for this Property and source.
   */
  String getAppinfo(Property property, String source);

  /**
   * Define the XML Schema as Types.
   * The Types are available through TypeHelper and DataGraph getType() methods.
   * Same as define(new StringReader(xsd), null)
   * @param xsd the XML Schema.
   * @return the defined Types.
   * @throws IllegalArgumentException if the Types could not be defined.
   */
  List /*Type*/ define(String xsd);
  
  /**
   * Define XML Schema as Types.
   * The Types are available through TypeHelper and DataGraph getType() methods.
   * @param xsdReader reader to an XML Schema.
   * @param schemaLocation the URI of the location of the schema, used 
   *   for processing relative imports and includes.  May be null if not used.
   * @return the defined Types.
   * @throws IllegalArgumentException if the Types could not be defined.
   */
  List /*Type*/ define(Reader xsdReader, String schemaLocation);

  /**
   * Define XML Schema as Types.
   * The Types are available through TypeHelper and DataGraph getType() methods.
   * @param xsdInputStream input stream to an XML Schema.
   * @param schemaLocation the URI of the location of the schema, used 
   *   for processing relative imports and includes.  May be null if not used.
   * @return the defined Types.
   * @throws IllegalArgumentException if the Types could not be defined.
   */
  List /*Type*/ define(InputStream xsdInputStream, String schemaLocation);

  /**
   * Generate an XML Schema Declaration (XSD) from Types.
   * Same as generate(types, null);
   * @param types a List containing the Types
   * @return a String containing the generated XSD. 
   * @throws IllegalArgumentException if the XSD could not be generated.
   */
  String generate(List /*Type*/ types);
  
  /**
   * Generate an XML Schema Declaration (XSD) from Types.
   * Round trip from SDO to XSD to SDO is supported.
   * Round trip from XSD to SDO to XSD is not supported.
   *  Use the original schema if one exists instead of generating a new one, as
   *  the generated XSD validates a different set of documents than the original XSD.
   * Generating an XSD does not affect the XSDHelper or the Types.
   * The Types must all have the same URI.
   * The result is a String containing the generated XSD. 
   * All Types referenced with the same URI will be generated in the XSD
   *  and the list will be expanded to include all types generated.
   * Any Types referenced with other URIs will cause 
   *  imports to be produced as appropriate.
   * Imports will include a schemaLocation if a Map is provided with an entry
   *  of the form key=import target namespace, value=schemaLocation
   * @param types a List containing the Types
   * @param namespaceToSchemaLocation map of target namespace to schema locations or null
   * @return a String containing the generated XSD. 
   * @throws IllegalArgumentException if the XSD could not be generated.
   */
  String generate(List /*Type*/ types, Map /*String, String*/ namespaceToSchemaLocation);

  /**
   * The default XSDHelper.
   */
  XSDHelper INSTANCE = HelperProvider.getXSDHelper();
}