Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 176416 | Differences between
and this patch

Collapse All | Expand All

(-)src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java (-2769 / +2638 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.xsd.contentmodel.internal;
11
package org.eclipse.wst.xsd.contentmodel.internal;
12
12
import java.io.IOException;
13
import java.io.IOException;
13
import java.io.InputStream;
14
import java.io.InputStream;
14
import java.util.ArrayList;
15
import java.util.ArrayList;
Lines 65-70 Link Here
65
import org.eclipse.xsd.XSDEnumerationFacet;
66
import org.eclipse.xsd.XSDEnumerationFacet;
66
import org.eclipse.xsd.XSDForm;
67
import org.eclipse.xsd.XSDForm;
67
import org.eclipse.xsd.XSDImport;
68
import org.eclipse.xsd.XSDImport;
69
//import org.eclipse.xsd.XSDInclude;
68
import org.eclipse.xsd.XSDModelGroup;
70
import org.eclipse.xsd.XSDModelGroup;
69
import org.eclipse.xsd.XSDModelGroupDefinition;
71
import org.eclipse.xsd.XSDModelGroupDefinition;
70
import org.eclipse.xsd.XSDParticle;
72
import org.eclipse.xsd.XSDParticle;
Lines 89-2861 Link Here
89
 * 
91
 * 
90
 * TODO: getNamespaceURI()currently always returns '##any'.
92
 * TODO: getNamespaceURI()currently always returns '##any'.
91
 */
93
 */
92
public class XSDImpl
94
public class XSDImpl {
93
{
95
	/*
94
  /*
96
	 * properties common to all cmnodes the following properties defined in
95
   * properties common to all cmnodes the following properties defined in
97
	 * CMNodeImpl class: PROPERTY_DOCUMENTATION PROPERTY_DOCUMENTATION_SOURCE
96
   * CMNodeImpl class: PROPERTY_DOCUMENTATION PROPERTY_DOCUMENTATION_SOURCE
98
	 * PROPERTY_DOCUMENTATION_LANGUAGE PROPERTY_MOF_NOTIFIER
97
   * PROPERTY_DOCUMENTATION_LANGUAGE PROPERTY_MOF_NOTIFIER
99
	 * PROPERTY_DEFINITION_INFO PROPERTY_DEFINITION
98
   * PROPERTY_DEFINITION_INFO PROPERTY_DEFINITION
100
	 * 
99
   * 
101
	 * the following properties defined in this class, XSDImpl:
100
   * the following properties defined in this class, XSDImpl:
102
	 * PROPERTY_CMDOCUMENT PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS
101
   * PROPERTY_CMDOCUMENT PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS
103
	 * PROPERTY_IS_NAME_SPACE_AWARE PROPERTY_NS_PREFIX_QUALIFICATION
102
   * PROPERTY_IS_NAME_SPACE_AWARE PROPERTY_NS_PREFIX_QUALIFICATION
104
	 * PROPERTY_NILLABLE PROPERTY_SPEC
103
   * PROPERTY_NILLABLE PROPERTY_SPEC
105
	 */
104
   */
106
	public static final String PROPERTY_CMDOCUMENT = "CMDocument";
105
  public static final String PROPERTY_CMDOCUMENT = "CMDocument";
107
106
  public static final String PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS = "http://org.eclipse.wst/cm/properties/usesLocalElementDeclarations";
108
	public static final String PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS = "http://org.eclipse.wst/cm/properties/usesLocalElementDeclarations";
107
  public static final String PROPERTY_IS_NAME_SPACE_AWARE = "http://org.eclipse.wst/cm/properties/isNameSpaceAware";
109
108
  public static final String PROPERTY_NS_PREFIX_QUALIFICATION = "http://org.eclipse.wst/cm/properties/nsPrefixQualification";
110
	public static final String PROPERTY_IS_NAME_SPACE_AWARE = "http://org.eclipse.wst/cm/properties/isNameSpaceAware";
109
  public static final String PROPERTY_NILLABLE = "http://org.eclipse.wst/cm/properties/nillable";
111
110
  public static final String PROPERTY_SPEC = "spec";
112
	public static final String PROPERTY_NS_PREFIX_QUALIFICATION = "http://org.eclipse.wst/cm/properties/nsPrefixQualification";
111
  /*
113
112
   * properties common to all CMDocument nodes: PROPERTY_TARGET_NAMESPACE_URI
114
	public static final String PROPERTY_NILLABLE = "http://org.eclipse.wst/cm/properties/nillable";
113
   * PROPERTY_IMPORTED_NAMESPACE_INFO PROPERTY_NAMESPACE_INFO
115
114
   * PROPERTY_ELEMENT_FORM_DEFAULT PROPERTY_ANNOTATION_MAP
116
	public static final String PROPERTY_SPEC = "spec";
115
   */
117
116
  public static final String PROPERTY_TARGET_NAMESPACE_URI = "http://org.eclipse.wst/cm/properties/targetNamespaceURI";
118
	/*
117
  public static final String PROPERTY_IMPORTED_NAMESPACE_INFO = "http://org.eclipse.wst/cm/properties/importedNamespaceInfo";
119
	 * properties common to all CMDocument nodes: PROPERTY_TARGET_NAMESPACE_URI
118
  public static final String PROPERTY_NAMESPACE_INFO = "http://org.eclipse.wst/cm/properties/namespaceInfo";
120
	 * PROPERTY_IMPORTED_NAMESPACE_INFO PROPERTY_NAMESPACE_INFO
119
  public static final String PROPERTY_ELEMENT_FORM_DEFAULT = "http://org.eclipse.wst/cm/properties/elementFormDefault";
121
	 * PROPERTY_ELEMENT_FORM_DEFAULT PROPERTY_ANNOTATION_MAP
120
  public static final String PROPERTY_ANNOTATION_MAP = "annotationMap";
122
	 */
121
  /*
123
	public static final String PROPERTY_TARGET_NAMESPACE_URI = "http://org.eclipse.wst/cm/properties/targetNamespaceURI";
122
   * properties common to all CMElementDeclaration nodes: PROPERTY_XSITYPES
124
123
   * PROPERTY_DERIVED_ELEMENT_DECLARATION PROPERTY_SUBSTITUTION_GROUP
125
	public static final String PROPERTY_IMPORTED_NAMESPACE_INFO = "http://org.eclipse.wst/cm/properties/importedNamespaceInfo";
124
   * PROPERTY_ABSTRACT
126
125
   */
127
	public static final String PROPERTY_NAMESPACE_INFO = "http://org.eclipse.wst/cm/properties/namespaceInfo";
126
  public static final String PROPERTY_XSITYPES = "XSITypes";
128
127
  public static final String PROPERTY_DERIVED_ELEMENT_DECLARATION = "DerivedElementDeclaration";
129
	public static final String PROPERTY_ELEMENT_FORM_DEFAULT = "http://org.eclipse.wst/cm/properties/elementFormDefault";
128
  public static final String PROPERTY_SUBSTITUTION_GROUP = "SubstitutionGroup";
130
129
  public static final String PROPERTY_ABSTRACT = "Abstract";
131
	public static final String PROPERTY_ANNOTATION_MAP = "annotationMap";
130
  /**
132
131
   * Definition info for element declarations.
133
	/*
132
   */
134
	 * properties common to all CMElementDeclaration nodes: PROPERTY_XSITYPES
133
  public static final String DEFINITION_INFO_GLOBAL = "global";
135
	 * PROPERTY_DERIVED_ELEMENT_DECLARATION PROPERTY_SUBSTITUTION_GROUP
134
  public static final String DEFINITION_INFO_LOCAL = "local";
136
	 * PROPERTY_ABSTRACT
135
  public static final String XML_LANG_ATTRIBUTE = "xml:lang";
137
	 */
136
  public static final String PLATFORM_PROTOCOL = "platform:";
138
	public static final String PROPERTY_XSITYPES = "XSITypes";
137
  protected static XSDAdapterFactoryImpl xsdAdapterFactoryImpl = new XSDAdapterFactoryImpl();
139
138
  protected static XSIDocument xsiDocument = new XSIDocument();
140
	public static final String PROPERTY_DERIVED_ELEMENT_DECLARATION = "DerivedElementDeclaration";
139
141
140
  /**
142
	public static final String PROPERTY_SUBSTITUTION_GROUP = "SubstitutionGroup";
141
   * Given uri for an XML Schema document, parse the document and build
143
142
   * corresponding CMDocument node.
144
	public static final String PROPERTY_ABSTRACT = "Abstract";
143
   * 
145
144
   * @param uri -
146
	/**
145
   *          the uri for an XML Schema document
147
	 * Definition info for element declarations.
146
   * @param grammarErrorChecking -
148
	 */
147
   *          grammar error checking flag
149
	public static final String DEFINITION_INFO_GLOBAL = "global";
148
   * @param errorList -
150
149
   *          the resulting error list
151
	public static final String DEFINITION_INFO_LOCAL = "local";
150
   * @return the corresponding CMDocument node.
152
151
   * @deprecated -- use buildCMDocument(String uri)
153
	public static final String XML_LANG_ATTRIBUTE = "xml:lang";
152
   */
154
153
  public static CMDocument buildCMDocument(String uri, int grammarErrorChecking, List errorList)
155
	public static final String PLATFORM_PROTOCOL = "platform:";
154
  {
156
155
    return buildCMDocument(uri);
157
	protected static XSDAdapterFactoryImpl xsdAdapterFactoryImpl = new XSDAdapterFactoryImpl();
156
  }
158
157
159
	protected static XSIDocument xsiDocument = new XSIDocument();
158
  /**
160
159
   * Given uri for an XML Schema document, parse the document and build
161
	/**
160
   * corresponding CMDocument node.
162
	 * Given uri for an XML Schema document, parse the document and build
161
   * 
163
	 * corresponding CMDocument node.
162
   * @param uri -
164
	 * 
163
   *          the uri for an XML Schema document
165
	 * @param uri -
164
   * @return the corresponding CMDocument node.
166
	 *            the uri for an XML Schema document
165
   */
167
	 * @param grammarErrorChecking -
166
  public static CMDocument buildCMDocument(String uri)
168
	 *            grammar error checking flag
167
  {
169
	 * @param errorList -
168
    CMDocument cmDocument = null;
170
	 *            the resulting error list
169
    XSDSchema xsdSchema = buildXSDModel(uri);
171
	 * @return the corresponding CMDocument node.
170
    if (xsdSchema != null)
172
	 * @deprecated -- use buildCMDocument(String uri)
171
    {
173
	 */
172
      cmDocument = (CMDocument) getAdapter(xsdSchema);
174
	public static CMDocument buildCMDocument(String uri,
173
    }
175
			int grammarErrorChecking, List errorList) {
174
    return cmDocument;
176
		return buildCMDocument(uri);
175
  }
177
	}
176
178
177
  /**
179
	/**
178
   * Given uri for an XML Schema document, parse the document and build
180
	 * Given uri for an XML Schema document, parse the document and build
179
   * corresponding CMDocument node.
181
	 * corresponding CMDocument node.
180
   * 
182
	 * 
181
   * @param uri -
183
	 * @param uri -
182
   *          the uri for an XML Schema document
184
	 *            the uri for an XML Schema document
183
   * @return the corresponding CMDocument node.
185
	 * @return the corresponding CMDocument node.
184
   */
186
	 */
185
  public static XSDSchema buildXSDModel(String uriString)
187
	public static CMDocument buildCMDocument(String uri) {
186
  {
188
		CMDocument cmDocument = null;
187
    XSDSchema xsdSchema = null;
189
		XSDSchema xsdSchema = buildXSDModel(uri);
188
 
190
		if (xsdSchema != null) {
189
    try
191
			cmDocument = (CMDocument) getAdapter(xsdSchema);
190
    {
192
		}
191
      // if XML Schema for Schema is requested, get it through schema model 
193
		return cmDocument;
192
      if (uriString.endsWith("2001/XMLSchema.xsd"))
194
	}
193
      {
195
194
      	xsdSchema = XSDSchemaImpl.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);			
196
	/**
195
      }
197
	 * Given uri for an XML Schema document, parse the document and build
196
      else
198
	 * corresponding CMDocument node.
197
      { 	
199
	 * 
198
        ResourceSet resourceSet = new ResourceSetImpl();
200
	 * @param uri -
199
        //resourceSet.getAdapterFactories().add(new XSDSchemaLocationResolverAdapterFactory());
201
	 *            the uri for an XML Schema document
200
        resourceSet.getAdapterFactories().add(new XSDSchemaLocatorAdapterFactory());
202
	 * @return the corresponding CMDocument node.
201
          
203
	 */
202
        URI uri = createURI(uriString);   
204
	public static XSDSchema buildXSDModel(String uriString) {
203
        
205
		XSDSchema xsdSchema = null;
204
        // CS : bug 113537 ensure we perform physical resolution before opening a stream for the resource
206
205
        //
207
		try {
206
        String physicalLocation = URIResolverPlugin.createResolver().resolvePhysicalLocation("", "", uriString);       
208
			// if XML Schema for Schema is requested, get it through schema
207
        InputStream inputStream = resourceSet.getURIConverter().createInputStream(URI.createURI(physicalLocation));
209
			// model
208
        XSDResourceImpl resource = (XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd"));
210
			if (uriString.endsWith("2001/XMLSchema.xsd")) {
209
        resource.setURI(uri);
211
				xsdSchema = XSDSchemaImpl
210
        resource.load(inputStream, null);         
212
						.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
211
        xsdSchema = resource.getSchema();      
213
			} else {
212
      }
214
				ResourceSet resourceSet = new ResourceSetImpl();
213
    }
215
				// resourceSet.getAdapterFactories().add(new
214
    catch (Exception e)
216
				// XSDSchemaLocationResolverAdapterFactory());
215
    {
217
				resourceSet.getAdapterFactories().add(
216
    }
218
						new XSDSchemaLocatorAdapterFactory());
217
    return xsdSchema;
219
218
  }
220
				URI uri = createURI(uriString);
219
  
221
220
  // TODO ... looks like we can remove this class?
222
				// CS : bug 113537 ensure we perform physical resolution before
221
  //
223
				// opening a stream for the resource
222
  static class InternalURIConverter extends URIConverterImpl
224
				//
223
  {
225
				String physicalLocation = URIResolverPlugin.createResolver()
224
    protected InputStream createURLInputStream(URI uri) throws IOException
226
						.resolvePhysicalLocation("", "", uriString);
225
    {
227
				InputStream inputStream = resourceSet.getURIConverter()
226
      if ("http".equals(uri.scheme()))
228
						.createInputStream(URI.createURI(physicalLocation));
227
      {
229
				XSDResourceImpl resource = (XSDResourceImpl) resourceSet
228
        String theURI = uri.toString();
230
						.createResource(URI.createURI("*.xsd"));
229
        String mapped = URIResolverPlugin.createResolver().resolve(theURI, theURI, theURI);
231
				resource.setURI(uri);
230
        if (mapped != null)
232
				resource.load(inputStream, null);
231
        {
233
				xsdSchema = resource.getSchema();
232
          uri = createURI(mapped);
234
			}
233
        }
235
		} catch (Exception e) {
234
      }
236
		}
235
      return super.createURLInputStream(uri);
237
		return xsdSchema;
236
    }
238
	}
237
  }
239
238
240
	// TODO ... looks like we can remove this class?
239
  /**
241
	//
240
   * Returns an appropriate URI based on a uri string.
242
	static class InternalURIConverter extends URIConverterImpl {
241
   * 
243
		protected InputStream createURLInputStream(URI uri) throws IOException {
242
   * @param uriString -
244
			if ("http".equals(uri.scheme())) {
243
   *          a uri string.
245
				String theURI = uri.toString();
244
   * @return an appropriate URI based on a uri string.
246
				String mapped = URIResolverPlugin.createResolver().resolve(
245
   */
247
						theURI, theURI, theURI);
246
  public static URI createURI(String uriString)
248
				if (mapped != null) {
247
  {
249
					uri = createURI(mapped);
248
    if (hasProtocol(uriString))
250
				}
249
      return URI.createURI(uriString);
251
			}
250
    else
252
			return super.createURLInputStream(uri);
251
      return URI.createFileURI(uriString);
253
		}
252
  }
254
	}
253
255
254
  private static boolean hasProtocol(String uri)
256
	/**
255
  {
257
	 * Returns an appropriate URI based on a uri string.
256
    boolean result = false;
258
	 * 
257
    if (uri != null)
259
	 * @param uriString -
258
    {
260
	 *            a uri string.
259
      int index = uri.indexOf(":");
261
	 * @return an appropriate URI based on a uri string.
260
      if (index != -1 && index > 2) // assume protocol with be length 3 so that
262
	 */
261
                                    // the'C' in 'C:/' is not interpreted as a
263
	public static URI createURI(String uriString) {
262
                                    // protocol
264
		if (hasProtocol(uriString))
263
      {
265
			return URI.createURI(uriString);
264
        result = true;
266
		else
265
      }
267
			return URI.createFileURI(uriString);
266
    }
268
	}
267
    return result;
269
268
  }
270
	private static boolean hasProtocol(String uri) {
269
271
		boolean result = false;
270
  /**
272
		if (uri != null) {
271
   * Returns true if string begins with platform protocol.
273
			int index = uri.indexOf(":");
272
   * 
274
			if (index != -1 && index > 2) // assume protocol with be length 3
273
   * @param uriString -
275
											// so that
274
   *          a uri string.
276
			// the'C' in 'C:/' is not interpreted as a
275
   * @return true if string begins with platform protocol.
277
			// protocol
276
   */
278
			{
277
  public static boolean withPlatformProtocol(String uriString)
279
				result = true;
278
  {
280
			}
279
    return uriString.startsWith(PLATFORM_PROTOCOL);
281
		}
280
  }
282
		return result;
281
283
	}
282
  /**
284
283
   * Returns the value of the 'Min Occurs' attribute. The default value is "1".
285
	/**
284
   * 
286
	 * Returns true if string begins with platform protocol.
285
   * @param component -
287
	 * 
286
   *          a concrete component.
288
	 * @param uriString -
287
   * @return the value of the 'Min Occurs' attribute.
289
	 *            a uri string.
288
   */
290
	 * @return true if string begins with platform protocol.
289
  public static int getMinOccurs(XSDConcreteComponent component)
291
	 */
290
  {
292
	public static boolean withPlatformProtocol(String uriString) {
291
    int minOccur = 1;
293
		return uriString.startsWith(PLATFORM_PROTOCOL);
292
    if (component != null)
294
	}
293
    {
295
294
      Object o = component.getContainer();
296
	/**
295
      if (o instanceof XSDParticle)
297
	 * Returns the value of the 'Min Occurs' attribute. The default value is
296
      {
298
	 * "1".
297
        if (((XSDParticle) o).isSetMinOccurs())
299
	 * 
298
        {
300
	 * @param component -
299
          try
301
	 *            a concrete component.
300
          {
302
	 * @return the value of the 'Min Occurs' attribute.
301
            minOccur = ((XSDParticle) o).getMinOccurs();
303
	 */
302
          }
304
	public static int getMinOccurs(XSDConcreteComponent component) {
303
          catch (Exception e)
305
		int minOccur = 1;
304
          {
306
		if (component != null) {
305
            minOccur = 1;
307
			Object o = component.getContainer();
306
          }
308
			if (o instanceof XSDParticle) {
307
        }
309
				if (((XSDParticle) o).isSetMinOccurs()) {
308
      }
310
					try {
309
    }
311
						minOccur = ((XSDParticle) o).getMinOccurs();
310
    return minOccur;
312
					} catch (Exception e) {
311
  }
313
						minOccur = 1;
312
314
					}
313
  /**
315
				}
314
   * Returns the value of the 'Max Occurs' attribute. The default value is "1".
316
			}
315
   * 
317
		}
316
   * @param component -
318
		return minOccur;
317
   *          a concrete component.
319
	}
318
   * @return the value of the 'Max Occurs' attribute.
320
319
   */
321
	/**
320
  public static int getMaxOccurs(XSDConcreteComponent component)
322
	 * Returns the value of the 'Max Occurs' attribute. The default value is
321
  {
323
	 * "1".
322
    int maxOccur = 1;
324
	 * 
323
    if (component != null)
325
	 * @param component -
324
    {
326
	 *            a concrete component.
325
      Object o = component.getContainer();
327
	 * @return the value of the 'Max Occurs' attribute.
326
      if (o instanceof XSDParticle)
328
	 */
327
      {
329
	public static int getMaxOccurs(XSDConcreteComponent component) {
328
        if (((XSDParticle) o).isSetMaxOccurs())
330
		int maxOccur = 1;
329
        {
331
		if (component != null) {
330
          try
332
			Object o = component.getContainer();
331
          {
333
			if (o instanceof XSDParticle) {
332
            maxOccur = ((XSDParticle) o).getMaxOccurs();
334
				if (((XSDParticle) o).isSetMaxOccurs()) {
333
          }
335
					try {
334
          catch (Exception e)
336
						maxOccur = ((XSDParticle) o).getMaxOccurs();
335
          {
337
					} catch (Exception e) {
336
            maxOccur = 1;
338
						maxOccur = 1;
337
          }
339
					}
338
        }
340
				}
339
      }
341
			}
340
    }
342
		}
341
    return maxOccur;
343
		return maxOccur;
342
  }
344
	}
343
345
344
  /**
346
	/**
345
   * Returns the enumerated values for the given type.
347
	 * Returns the enumerated values for the given type.
346
   * 
348
	 * 
347
   * @param type -
349
	 * @param type -
348
   *          a type definition.
350
	 *            a type definition.
349
   * @return the enumerated values for the given type.
351
	 * @return the enumerated values for the given type.
350
   */
352
	 */
351
  private final static String TYPE_NAME_BOOLEAN = "boolean"; //$NON-NLS-1$
353
	private final static String TYPE_NAME_BOOLEAN = "boolean"; //$NON-NLS-1$
352
  private final static String TYPE_VALUE_TRUE = "true"; //$NON-NLS-1$
354
353
  private final static String TYPE_VALUE_FALSE= "false"; //$NON-NLS-1$  
355
	private final static String TYPE_VALUE_TRUE = "true"; //$NON-NLS-1$
354
  
356
355
  public static String[] getEnumeratedValuesForType(XSDTypeDefinition type)
357
	private final static String TYPE_VALUE_FALSE = "false"; //$NON-NLS-1$  
356
  {
358
357
    List result = new ArrayList();
359
	public static String[] getEnumeratedValuesForType(XSDTypeDefinition type) {
358
    if (type instanceof XSDSimpleTypeDefinition)
360
		List result = new ArrayList();
359
    {         
361
		if (type instanceof XSDSimpleTypeDefinition) {
360
      if (TYPE_NAME_BOOLEAN.equals(type.getName()) && type.getSchema().getSchemaForSchema() == type.getSchema())
362
			if (TYPE_NAME_BOOLEAN.equals(type.getName())
361
      {
363
					&& type.getSchema().getSchemaForSchema() == type
362
        result.add(TYPE_VALUE_TRUE);
364
							.getSchema()) {
363
        result.add(TYPE_VALUE_FALSE);
365
				result.add(TYPE_VALUE_TRUE);
364
      } 
366
				result.add(TYPE_VALUE_FALSE);
365
      else
367
			} else {
366
      {        
368
				List enumerationFacets = ((XSDSimpleTypeDefinition) type)
367
        List enumerationFacets = ((XSDSimpleTypeDefinition) type).getEnumerationFacets();
369
						.getEnumerationFacets();
368
        for (Iterator i = enumerationFacets.iterator(); i.hasNext();)
370
				for (Iterator i = enumerationFacets.iterator(); i.hasNext();) {
369
        {
371
					XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i
370
          XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i.next();
372
							.next();
371
          List values = enumFacet.getValue();
373
					List values = enumFacet.getValue();
372
          for (Iterator j = values.iterator(); j.hasNext();)
374
					for (Iterator j = values.iterator(); j.hasNext();) {
373
          {
375
						Object o = j.next();
374
            Object o = j.next();
376
						if (o != null) {
375
            if (o != null)
377
							result.add(o.toString());
376
            {
378
						}
377
              result.add(o.toString());
379
					}
378
            }  
380
				}
379
          }
381
			}
380
        }
382
		}
381
      }
383
		String[] array = new String[result.size()];
382
    }  
384
		result.toArray(array);
383
    String[] array = new String[result.size()];
385
		return array;
384
    result.toArray(array);
386
	}
385
    return array;
387
386
  }
388
	/**
387
389
	 * Return a list of documentation elements from the given annotation.
388
  /**
390
	 * Working with documentation elements requires dropping down into the DOM
389
   * Return a list of documentation elements from the given annotation. Working
391
	 * model.
390
   * with documentation elements requires dropping down into the DOM model.
392
	 * 
391
   * 
393
	 * @param annotation -
392
   * @param annotation -
394
	 *            an XSDAnnotation node.
393
   *          an XSDAnnotation node.
395
	 * @return a list of documentation elements.
394
   * @return a list of documentation elements.
396
	 */
395
   */
397
	public static CMNodeList getDocumentations(XSDAnnotation annotation) {
396
  public static CMNodeList getDocumentations(XSDAnnotation annotation)
398
		CMNodeListImpl documentations = new CMNodeListImpl();
397
  {
399
		if (annotation != null) {
398
    CMNodeListImpl documentations = new CMNodeListImpl();
400
			List documentationsElements = annotation.getUserInformation();
399
    if (annotation != null)
401
			for (Iterator i = documentationsElements.iterator(); i.hasNext();) {
400
    {
402
				documentations.getList().add(
401
      List documentationsElements = annotation.getUserInformation();
403
						new DocumentationImpl((Element) i.next()));
402
      for (Iterator i = documentationsElements.iterator(); i.hasNext();)
404
			}
403
      {
405
		}
404
        documentations.getList().add(new DocumentationImpl((Element) i.next()));
406
		return documentations;
405
      }
407
	}
406
    }
408
407
    return documentations;
409
	/**
408
  }
410
	 * Adapted from public static List findTypesDerivedFrom(XSDSchema schema,
409
411
	 * String namespace, String localName) in class XSDSchemaQueryTools found in
410
  /**
412
	 * org.eclipse.xsd plugin.
411
   * Adapted from public static List findTypesDerivedFrom(XSDSchema schema,
413
	 * 
412
   * String namespace, String localName) in class XSDSchemaQueryTools found in
414
	 * Find typeDefinitions that derive from a given type.
413
   * org.eclipse.xsd plugin.
415
	 * 
414
   * 
416
	 * @param type
415
   * Find typeDefinitions that derive from a given type.
417
	 *            the type derived from
416
   * 
418
	 * @return List of any XSDTypeDefinitions found
417
   * @param type
419
	 */
418
   *          the type derived from
420
	public static List findTypesDerivedFrom(XSDTypeDefinition type) {
419
   * @return List of any XSDTypeDefinitions found
421
		ArrayList typesDerivedFrom = new ArrayList();
420
   */
422
		if (type != null) {
421
  public static List findTypesDerivedFrom(XSDTypeDefinition type)
423
			XSDSchema schema = type.getSchema();
422
  {
424
			String localName = type.getName();
423
    ArrayList typesDerivedFrom = new ArrayList();
425
			if ((null != schema) && (null != localName)) {
424
    if (type != null)
426
				String namespace = schema.getTargetNamespace();
425
    {
427
				// A handy convenience method quickly gets all
426
      XSDSchema schema = type.getSchema();
428
				// typeDefinitions within our schema; note that
427
      String localName = type.getName();
429
				// whether or not this returns types in included,
428
      if ((null != schema) && (null != localName))
430
				// imported, or redefined schemas is subject to change
429
      {
431
				List typedefs = schema.getTypeDefinitions();
430
        String namespace = schema.getTargetNamespace();
432
				for (Iterator iter = typedefs.iterator(); iter.hasNext();) {
431
        // A handy convenience method quickly gets all
433
					XSDTypeDefinition typedef = (XSDTypeDefinition) iter.next();
432
        // typeDefinitions within our schema; note that
434
					if (typedef instanceof XSDComplexTypeDefinition) {
433
        // whether or not this returns types in included,
435
						// Walk the baseTypes from this typedef seeing if any
434
        // imported, or redefined schemas is subject to change
436
						// of them match the requested one
435
        List typedefs = schema.getTypeDefinitions();
437
						if (isTypeDerivedFrom(typedef, namespace, localName)) {
436
        for (Iterator iter = typedefs.iterator(); iter.hasNext();)
438
							// We found it, return the original one and continue
437
        {
439
							typesDerivedFrom.add(typedef);
438
          XSDTypeDefinition typedef = (XSDTypeDefinition) iter.next();
440
							continue;
439
          if (typedef instanceof XSDComplexTypeDefinition)
441
						}
440
          {
442
					}
441
            // Walk the baseTypes from this typedef seeing if any
443
				}
442
            // of them match the requested one
444
			}
443
            if (isTypeDerivedFrom(typedef, namespace, localName))
445
		}
444
            {
446
		return typesDerivedFrom;
445
              // We found it, return the original one and continue
447
	}
446
              typesDerivedFrom.add(typedef);
448
447
              continue;
449
	/**
448
            }
450
	 * Adapted from protected static boolean isTypeDerivedFrom(XSDTypeDefinition
449
          }
451
	 * typedef, String namespace, String localName) in class XSDSchemaQueryTools
450
        }
452
	 * found in org.eclipse.xsd plugin.
451
      }
453
	 * 
452
    }
454
	 * Recursive worker method to find typeDefinitions that derive from a named
453
    return typesDerivedFrom;
455
	 * type.
454
  }
456
	 * 
455
457
	 * @see #findTypesDerivedFrom(XSDSchema, String, String)
456
  /**
458
	 * @param typeDef
457
   * Adapted from protected static boolean isTypeDerivedFrom(XSDTypeDefinition
459
	 *            to see if it's derived from
458
   * typedef, String namespace, String localName) in class XSDSchemaQueryTools
460
	 * @param namespace
459
   * found in org.eclipse.xsd plugin.
461
	 *            for the type derived from
460
   * 
462
	 * @param localName
461
   * Recursive worker method to find typeDefinitions that derive from a named
463
	 *            for the type derived from
462
   * type.
464
	 * @return true if it is; false otherwise
463
   * 
465
	 */
464
   * @see #findTypesDerivedFrom(XSDSchema, String, String)
466
	protected static boolean isTypeDerivedFrom(XSDTypeDefinition typedef,
465
   * @param typeDef
467
			String namespace, String localName) {
466
   *          to see if it's derived from
468
		// Walk the baseTypes from this typedef seeing if any
467
   * @param namespace
469
		// of them match the requested one
468
   *          for the type derived from
470
		XSDTypeDefinition baseType = typedef.getBaseType();
469
   * @param localName
471
		if (baseType == null) {
470
   *          for the type derived from
472
			// typedef is a root type like xsd:anyType, so it has no base
471
   * @return true if it is; false otherwise
473
			return false;
472
   */
474
		}
473
  protected static boolean isTypeDerivedFrom(XSDTypeDefinition typedef, String namespace, String localName)
475
		// As this convenience method if our parameters match
474
  {
476
		if (baseType.hasNameAndTargetNamespace(localName, namespace)) {
475
    // Walk the baseTypes from this typedef seeing if any
477
			return true;
476
    // of them match the requested one
478
		}
477
    XSDTypeDefinition baseType = typedef.getBaseType();
479
		XSDTypeDefinition rootType = typedef.getRootType();
478
    if (baseType == null)
480
		if (rootType == baseType) {
479
   	{
481
			// If we've hit the root, we aren't derived from it
480
      // typedef is a root type like xsd:anyType, so it has no base
482
			return false;
481
      return false;
483
		} else {
482
    }
484
			// Otherwise continue to traverse upwards
483
    // As this convenience method if our parameters match
485
			return isTypeDerivedFrom(baseType, namespace, localName);
484
    if (baseType.hasNameAndTargetNamespace(localName, namespace))
486
		}
485
    {
487
	}
486
      return true;
488
487
    }
489
	/**
488
    XSDTypeDefinition rootType = typedef.getRootType();
490
	 * Returns the corresponding cmnode of the specified XML Schema node.
489
    if (rootType == baseType)
491
	 * 
490
    {
492
	 * @param target -
491
      // If we've hit the root, we aren't derived from it
493
	 *            an XML Schema node
492
      return false;
494
	 * @return the corresponding cmnode.
493
    }
495
	 */
494
    else
496
	public static CMNode getAdapter(Notifier o) {
495
    {
497
		return (CMNode) xsdAdapterFactoryImpl.adapt(o);
496
      // Otherwise continue to traverse upwards
498
	}
497
      return isTypeDerivedFrom(baseType, namespace, localName);
499
498
    }
500
	/**
499
  }
501
	 * Adapted from public String getPrefix(String ns, boolean withColon) in
500
502
	 * class TypesHelper found in org.eclipse.wst.xsd.editor plugin.
501
  /**
503
	 * 
502
   * Returns the corresponding cmnode of the specified XML Schema node.
504
	 * @param schema -
503
   * 
505
	 *            the relevant schema
504
   * @param target -
506
	 * @param ns -
505
   *          an XML Schema node
507
	 *            the relevant namespace
506
   * @return the corresponding cmnode.
508
	 */
507
   */
509
	public static String getPrefix(XSDSchema schema, String ns) {
508
  public static CMNode getAdapter(Notifier o)
510
		String key = "";
509
  {
511
		if ((schema != null) && (ns != null)) {
510
    return (CMNode) xsdAdapterFactoryImpl.adapt(o);
512
			Map map = schema.getQNamePrefixToNamespaceMap();
511
  }
513
			Iterator iter = map.keySet().iterator();
512
514
			while (iter.hasNext()) {
513
  /**
515
				Object keyObj = iter.next();
514
   * Adapted from public String getPrefix(String ns, boolean withColon) in class
516
				Object value = map.get(keyObj);
515
   * TypesHelper found in org.eclipse.wst.xsd.editor plugin.
517
				if (value != null && value.toString().equals(ns)) {
516
   * 
518
					if (keyObj != null) {
517
   * @param schema -
519
						key = keyObj.toString();
518
   *          the relevant schema
520
					} else {
519
   * @param ns -
521
						key = "";
520
   *          the relevant namespace
522
					}
521
   */
523
					break;
522
  public static String getPrefix(XSDSchema schema, String ns)
524
				}
523
  {
525
			}
524
    String key = "";
526
		}
525
    if ((schema != null) && (ns != null))
527
		return key;
526
    {
528
	}
527
      Map map = schema.getQNamePrefixToNamespaceMap();
529
528
      Iterator iter = map.keySet().iterator();
530
	/**
529
      while (iter.hasNext())
531
	 * The Factory for the XSD adapter model. It provides a create method for
530
      {
532
	 * each non-abstract class of the model.
531
        Object keyObj = iter.next();
533
	 */
532
        Object value = map.get(keyObj);
534
	public static class XSDAdapterFactoryImpl extends AdapterFactoryImpl {
533
        if (value != null && value.toString().equals(ns))
535
		public Adapter createAdapter(Notifier target) {
534
        {
536
			XSDSwitch xsdSwitch = new XSDSwitch() {
535
          if (keyObj != null)
537
				public Object caseXSDWildcard(XSDWildcard object) {
536
          {
538
					return new XSDWildcardAdapter(object);
537
            key = keyObj.toString();
539
				}
538
          }
540
539
          else
541
				public Object caseXSDModelGroupDefinition(
540
          {
542
						XSDModelGroupDefinition object) {
541
            key = "";
543
					return new XSDModelGroupDefinitionAdapter(object);
542
          }
544
				}
543
          break;
545
544
        }
546
				public Object caseXSDAttributeUse(XSDAttributeUse object) {
545
      }
547
					return new XSDAttributeUseAdapter(object);
546
    }
548
				}
547
    return key;
549
548
  }
550
				public Object caseXSDElementDeclaration(
549
  /**
551
						XSDElementDeclaration object) {
550
   * The Factory for the XSD adapter model. It provides a create method for each
552
					return new XSDElementDeclarationAdapter(object);
551
   * non-abstract class of the model.
553
				}
552
   */
554
553
  public static class XSDAdapterFactoryImpl extends AdapterFactoryImpl
555
				public Object caseXSDModelGroup(XSDModelGroup object) {
554
  {
556
					return new XSDModelGroupAdapter(object);
555
    public Adapter createAdapter(Notifier target)
557
				}
556
    {
558
557
      XSDSwitch xsdSwitch = new XSDSwitch()
559
				public Object caseXSDSchema(XSDSchema object) {
558
      {
560
					return new XSDSchemaAdapter(object);
559
        public Object caseXSDWildcard(XSDWildcard object)
561
				}
560
        {
562
			};
561
          return new XSDWildcardAdapter(object);
563
			Object o = xsdSwitch.doSwitch((EObject) target);
562
        }
564
			Adapter result = null;
563
565
			if (o instanceof Adapter) {
564
        public Object caseXSDModelGroupDefinition(XSDModelGroupDefinition object)
566
				result = (Adapter) o;
565
        {
567
			} else {
566
          return new XSDModelGroupDefinitionAdapter(object);
568
				Thread.dumpStack();
567
        }
569
			}
568
570
			return result;
569
        public Object caseXSDAttributeUse(XSDAttributeUse object)
571
		}
570
        {
572
571
          return new XSDAttributeUseAdapter(object);
573
		public Adapter adapt(Notifier target) {
572
        }
574
			return adapt(target, this);
573
575
		}
574
        public Object caseXSDElementDeclaration(XSDElementDeclaration object)
576
	}
575
        {
577
576
          return new XSDElementDeclarationAdapter(object);
578
	/**
577
        }
579
	 * XSDBaseAdapter -- an abstract base node in the model. All other model
578
580
	 * nodes are derived from it.
579
        public Object caseXSDModelGroup(XSDModelGroup object)
581
	 */
580
        {
582
	public static abstract class XSDBaseAdapter extends CMNodeImpl {
581
          return new XSDModelGroupAdapter(object);
583
		protected CMNodeListImpl documentation = new CMNodeListImpl();
582
        }
584
583
585
		/**
584
        public Object caseXSDSchema(XSDSchema object)
586
		 * Returns the name of the node. The default value is an empty string
585
        {
587
		 * value. All derived classes must override this method if they do not
586
          return new XSDSchemaAdapter(object);
588
		 * want the default value.
587
        }
589
		 * 
588
      };
590
		 * @return the name of the node.
589
      Object o = xsdSwitch.doSwitch((EObject) target);
591
		 */
590
      Adapter result = null;
592
		public String getNodeName() {
591
      if (o instanceof Adapter)
593
			return "";
592
      {
594
		}
593
        result = (Adapter) o;
595
594
      }
596
		/**
595
      else
597
		 * Returns true of the given factory is the factory for this XSD adapter
596
      {
598
		 * model.
597
        Thread.dumpStack();
599
		 * 
598
      }
600
		 * @param type -
599
      return result;
601
		 *            a factory
600
    }
602
		 * @return true if the type is the adapter factory for this model.
601
603
		 */
602
    public Adapter adapt(Notifier target)
604
		public boolean isAdapterForType(Object type) {
603
    {
605
			return type == xsdAdapterFactoryImpl;
604
      return adapt(target, this);
606
		}
605
    }
607
606
  }
608
		/**
607
  /**
609
		 * Returns true if the property is supported for this class.
608
   * XSDBaseAdapter -- an abstract base node in the model. All other model nodes
610
		 * 
609
   * are derived from it.
611
		 * @param propertyName -
610
   */
612
		 *            name of a property
611
  public static abstract class XSDBaseAdapter extends CMNodeImpl
613
		 * @return true if the property is supported.
612
  {
614
		 */
613
    protected CMNodeListImpl documentation = new CMNodeListImpl();
615
		public boolean supports(String propertyName) {
614
616
			return propertyName.equals(PROPERTY_NS_PREFIX_QUALIFICATION)
615
    /**
617
					|| propertyName.equals(PROPERTY_NILLABLE)
616
     * Returns the name of the node. The default value is an empty string value.
618
					|| propertyName
617
     * All derived classes must override this method if they do not want the
619
							.equals(PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS)
618
     * default value.
620
					|| propertyName.equals(PROPERTY_DOCUMENTATION)
619
     * 
621
					|| propertyName.equals(PROPERTY_DOCUMENTATION_SOURCE)
620
     * @return the name of the node.
622
					|| propertyName.equals(PROPERTY_DOCUMENTATION_LANGUAGE)
621
     */
623
					|| propertyName.equals(PROPERTY_MOF_NOTIFIER)
622
    public String getNodeName()
624
					|| propertyName.equals(PROPERTY_DEFINITION_INFO)
623
    {
625
					|| propertyName.equals(PROPERTY_DEFINITION)
624
      return "";
626
					|| propertyName.equals(PROPERTY_CMDOCUMENT)
625
    }
627
					|| propertyName.equals(PROPERTY_IS_NAME_SPACE_AWARE)
626
628
					|| propertyName.equals(PROPERTY_SPEC)
627
    /**
629
					|| super.supports(propertyName);
628
     * Returns true of the given factory is the factory for this XSD adapter
630
		}
629
     * model.
631
630
     * 
632
		/**
631
     * @param type -
633
		 * Returns the value of the 'Nillable' attribute. This represents the
632
     *          a factory
634
		 * nillable infoset property. The default value is false. All derived
633
     * @return true if the type is the adapter factory for this model.
635
		 * classes must override this method if they do not want the default
634
     */
636
		 * value.
635
    public boolean isAdapterForType(Object type)
637
		 * 
636
    {
638
		 * @return the value of the 'Nillable' attribute.
637
      return type == xsdAdapterFactoryImpl;
639
		 */
638
    }
640
		public boolean isNillable() {
639
641
			return false;
640
    /**
642
		}
641
     * Returns true if the property is supported for this class.
643
642
     * 
644
		/**
643
     * @param propertyName -
645
		 * Returns the cmdocument that is the owner of this cmnode. The default
644
     *          name of a property
646
		 * value is null; All derived classes must override this method if they
645
     * @return true if the property is supported.
647
		 * do not want the default value.
646
     */
648
		 * 
647
    public boolean supports(String propertyName)
649
		 * @return the cmdocument corresponding to this cmnode.
648
    {
650
		 */
649
      return propertyName.equals(PROPERTY_NS_PREFIX_QUALIFICATION) || propertyName.equals(PROPERTY_NILLABLE) || propertyName.equals(PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS)
651
		public CMDocument getCMDocument() {
650
          || propertyName.equals(PROPERTY_DOCUMENTATION) || propertyName.equals(PROPERTY_DOCUMENTATION_SOURCE) || propertyName.equals(PROPERTY_DOCUMENTATION_LANGUAGE)
652
			return null;
651
          || propertyName.equals(PROPERTY_MOF_NOTIFIER) || propertyName.equals(PROPERTY_DEFINITION_INFO) || propertyName.equals(PROPERTY_DEFINITION) || propertyName.equals(PROPERTY_CMDOCUMENT)
653
		}
652
          || propertyName.equals(PROPERTY_IS_NAME_SPACE_AWARE) || propertyName.equals(PROPERTY_SPEC) || super.supports(propertyName);
654
653
    }
655
		/**
654
656
		 * Return a list of documentation elements. The default value is an
655
    /**
657
		 * empty CMNodeList; All derived classes must override this method if
656
     * Returns the value of the 'Nillable' attribute. This represents the
658
		 * they do not want the default value.
657
     * nillable infoset property. The default value is false. All derived
659
		 * 
658
     * classes must override this method if they do not want the default value.
660
		 * @return a list of documentation elements.
659
     * 
661
		 */
660
     * @return the value of the 'Nillable' attribute.
662
		protected CMNodeList getDocumentation() {
661
     */
663
			return documentation;
662
    public boolean isNillable()
664
		}
663
    {
665
664
      return false;
666
		/**
665
    }
667
		 * Returns the property value for the property name. Returns null if the
666
668
		 * property is not supported.
667
    /**
669
		 * 
668
     * Returns the cmdocument that is the owner of this cmnode. The default
670
		 * @param propertyName -
669
     * value is null; All derived classes must override this method if they do
671
		 *            name of a property
670
     * not want the default value.
672
		 * @return the property value for the property name.
671
     * 
673
		 */
672
     * @return the cmdocument corresponding to this cmnode.
674
		public Object getProperty(String propertyName) {
673
     */
675
			Object result = null;
674
    public CMDocument getCMDocument()
676
			if (propertyName.equals(PROPERTY_CMDOCUMENT)) {
675
    {
677
				result = getCMDocument();
676
      return null;
678
			} else if (propertyName.equals(PROPERTY_DOCUMENTATION)) {
677
    }
679
				result = getDocumentation();
678
680
			} else if (propertyName
679
    /**
681
					.equals(PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS)) {
680
     * Return a list of documentation elements. The default value is an empty
682
				result = Boolean.TRUE;
681
     * CMNodeList; All derived classes must override this method if they do not
683
			} else if (propertyName.equals(PROPERTY_IS_NAME_SPACE_AWARE)) {
682
     * want the default value.
684
				result = Boolean.TRUE;
683
     * 
685
			} else if (propertyName.equals(PROPERTY_NS_PREFIX_QUALIFICATION)) {
684
     * @return a list of documentation elements.
686
				result = getNSPrefixQualification();
685
     */
687
			} else if (propertyName.equals(PROPERTY_NILLABLE)) {
686
    protected CMNodeList getDocumentation()
688
				result = isNillable() ? xsiDocument.nilAttribute : null;
687
    {
689
			} else if (propertyName.equals(PROPERTY_MOF_NOTIFIER)) {
688
      return documentation;
690
				result = getKey();
689
    }
691
			} else if (propertyName.equals(PROPERTY_SPEC)) {
690
692
				result = getSpec();
691
    /**
693
			} else {
692
     * Returns the property value for the property name. Returns null if the
694
				result = super.getProperty(propertyName);
693
     * property is not supported.
695
				{
694
     * 
696
					CMDocument cmDocument = getCMDocument();
695
     * @param propertyName -
697
					if (cmDocument instanceof XSDSchemaAdapter) {
696
     *          name of a property
698
						AnnotationMap map = ((XSDSchemaAdapter) cmDocument).annotationMap;
697
     * @return the property value for the property name.
699
						if (map != null) {
698
     */
700
							String spec = getSpec();
699
    public Object getProperty(String propertyName)
701
							if (spec != null) {
700
    {
702
								result = map.getProperty(getSpec(),
701
      Object result = null;
703
										propertyName);
702
      if (propertyName.equals(PROPERTY_CMDOCUMENT))
704
							}
703
      {
705
						}
704
        result = getCMDocument();
706
					}
705
      }
707
				}
706
      else if (propertyName.equals(PROPERTY_DOCUMENTATION))
708
			}
707
      {
709
			return result;
708
        result = getDocumentation();
710
		}
709
      }
711
710
      else if (propertyName.equals(PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS))
712
		/*
711
      {
713
		 * Returns the value of the form [attribute] which affects the target
712
        result = Boolean.TRUE;
714
		 * namespace of locally scoped features. The default value is null. All
713
      }
715
		 * derived classes must override this method if they do not want the
714
      else if (propertyName.equals(PROPERTY_IS_NAME_SPACE_AWARE))
716
		 * default value. @return the value of the form [attribute].
715
      {
717
		 */
716
        result = Boolean.TRUE;
718
		public Object getNSPrefixQualification() {
717
      }
719
			return null;
718
      else if (propertyName.equals(PROPERTY_NS_PREFIX_QUALIFICATION))
720
		}
719
      {
721
720
        result = getNSPrefixQualification();
722
		/**
721
      }
723
		 * Returns a general XPath expression for the node.
722
      else if (propertyName.equals(PROPERTY_NILLABLE))
724
		 * 
723
      {
725
		 * @return a general XPath expression for the node.
724
        result = isNillable() ? xsiDocument.nilAttribute : null;
726
		 */
725
      }
727
		public String getSpec() {
726
      else if (propertyName.equals(PROPERTY_MOF_NOTIFIER))
728
			return "//" + getNodeName();
727
      {
729
		}
728
        result = getKey();
730
	}
729
      }
731
730
      else if (propertyName.equals(PROPERTY_SPEC))
732
	/**
731
      {
733
	 * XSDSchemaAdapter implements CMDocument. A representation of the model
732
        result = getSpec();
734
	 * object 'Schema'.
733
      }
735
	 */
734
      else
736
	public static class XSDSchemaAdapter extends XSDBaseAdapter implements
735
      {
737
			CMDocument {
736
        result = super.getProperty(propertyName);
738
		protected XSDSchema xsdSchema;
737
        {
739
738
          CMDocument cmDocument = getCMDocument();
740
		protected CMNamedNodeMapImpl namedNodeMap;
739
          if (cmDocument instanceof XSDSchemaAdapter)
741
740
          {
742
		protected CMNamedNodeMapImpl entityNodeMap;
741
            AnnotationMap map = ((XSDSchemaAdapter) cmDocument).annotationMap;
743
742
            if (map != null)
744
		protected AnnotationMap annotationMap = new AnnotationMap();
743
            {
745
744
              String spec = getSpec();
746
		protected Hashtable substitutionGroupTable;
745
              if (spec != null)
747
746
              {
748
		/**
747
                result = map.getProperty(getSpec(), propertyName);
749
		 * Constructor.
748
              }
750
		 * 
749
            }
751
		 * @param xsdSchema -
750
          }
752
		 *            the schema node.
751
        }
753
		 */
752
      }
754
		public XSDSchemaAdapter(XSDSchema xsdSchema) {
753
      return result;
755
			this.xsdSchema = xsdSchema;
754
    }
756
		}
755
       
757
756
758
		/**
757
759
		 * Returns the key for this cmnode which is the corresponding XML Schema
758
    /*
760
		 * node.
759
     * Returns the value of the form [attribute] which affects the target
761
		 * 
760
     * namespace of locally scoped features. The default value is null. All
762
		 * @return the key for this cmnode.
761
     * derived classes must override this method if they do not want the default
763
		 */
762
     * value. @return the value of the form [attribute].
764
		public Object getKey() {
763
     */
765
			return xsdSchema;
764
    public Object getNSPrefixQualification()
766
		}
765
    {
767
766
      return null;
768
		/**
767
    }
769
		 * Returns the filename.
768
770
		 * 
769
    /**
771
		 * @return the filename.
770
     * Returns a general XPath expression for the node.
772
		 */
771
     * 
773
		public String getNodeName() {
772
     * @return a general XPath expression for the node.
774
			// See buildCMDocument() above.
773
     */
775
			return xsdSchema.getSchemaLocation();
774
    public String getSpec()
776
		}
775
    {
777
776
      return "//" + getNodeName();
778
		/**
777
    }
779
		 * Returns true if the property is supported for this class.
778
  }
780
		 * 
779
  /**
781
		 * @param propertyName -
780
   * XSDSchemaAdapter implements CMDocument. A representation of the model
782
		 *            name of a property
781
   * object 'Schema'.
783
		 * @return true if the property is supported.
782
   */
784
		 */
783
  public static class XSDSchemaAdapter extends XSDBaseAdapter implements CMDocument
785
		public boolean supports(String propertyName) {
784
  {
786
			return propertyName.equals(PROPERTY_TARGET_NAMESPACE_URI)
785
    protected XSDSchema xsdSchema;
787
					|| propertyName.equals(PROPERTY_IMPORTED_NAMESPACE_INFO)
786
    protected CMNamedNodeMapImpl namedNodeMap;
788
					|| propertyName.equals(PROPERTY_NAMESPACE_INFO)
787
    protected CMNamedNodeMapImpl entityNodeMap;
789
					|| propertyName.equals(PROPERTY_ELEMENT_FORM_DEFAULT)
788
    protected AnnotationMap annotationMap = new AnnotationMap();
790
					|| propertyName.equals(PROPERTY_ANNOTATION_MAP)
789
    protected Hashtable substitutionGroupTable;
791
					|| super.supports(propertyName);
790
792
		}
791
    /**
793
792
     * Constructor.
794
		/**
793
     * 
795
		 * Returns true if a prefix is globally required for elements.
794
     * @param xsdSchema -
796
		 * 
795
     *          the schema node.
797
		 * @param xsdSchema -
796
     */
798
		 *            the corresponding schema node.
797
    public XSDSchemaAdapter(XSDSchema xsdSchema)
799
		 * @return true if a prefix is globally required for elements.
798
    {
800
		 */
799
      this.xsdSchema = xsdSchema;
801
		protected boolean isPrefixRequired(XSDSchema xsdSchema) {
800
    }
802
			boolean result = true;
801
803
			if (xsdSchema.isSetElementFormDefault())
802
    /**
804
				result = !(xsdSchema.getElementFormDefault().getValue() == XSDForm.QUALIFIED);
803
     * Returns the key for this cmnode which is the corresponding XML Schema
805
			return result;
804
     * node.
806
		}
805
     * 
807
806
     * @return the key for this cmnode.
808
		/**
807
     */
809
		 * Returns the property value for the property name. Returns null if the
808
    public Object getKey()
810
		 * property is not supported.
809
    {
811
		 * 
810
      return xsdSchema;
812
		 * @param propertyName -
811
    }
813
		 *            name of a property
812
814
		 * @return the property value for the property name.
813
    /**
815
		 */
814
     * Returns the filename.
816
		public Object getProperty(String propertyName) {
815
     * 
817
			Object result = null;
816
     * @return the filename.
818
			if (propertyName.equals(PROPERTY_TARGET_NAMESPACE_URI)) {
817
     */
819
				result = xsdSchema.getTargetNamespace();
818
    public String getNodeName()
820
			} else if (propertyName.equals(PROPERTY_IMPORTED_NAMESPACE_INFO)) {
819
    {
821
				List list = new Vector();
820
      // See buildCMDocument() above.
822
				getImportedNamespaceInfo(xsdSchema, list);
821
      return xsdSchema.getSchemaLocation();
823
				result = list;
822
    }
824
			} else if (propertyName.equals(PROPERTY_NAMESPACE_INFO)) {
823
825
				List list = new Vector();
824
    /**
826
				NamespaceInfo info = new NamespaceInfo();
825
     * Returns true if the property is supported for this class.
827
				info.uri = xsdSchema.getTargetNamespace();
826
     * 
828
				info.prefix = getPrefix(xsdSchema, info.uri);
827
     * @param propertyName -
829
				info.locationHint = null; // note that this locationHint info
828
     *          name of a property
830
											// is null
829
     * @return true if the property is supported.
831
				// for the root xsd file
830
     */
832
				info.isPrefixRequired = isPrefixRequired(xsdSchema);
831
    public boolean supports(String propertyName)
833
				list.add(info);
832
    {
834
				getImportedNamespaceInfo(xsdSchema, list);
833
      return propertyName.equals(PROPERTY_TARGET_NAMESPACE_URI) || propertyName.equals(PROPERTY_IMPORTED_NAMESPACE_INFO) || propertyName.equals(PROPERTY_NAMESPACE_INFO)
835
				getAllNamespacesInfo(xsdSchema, list);
834
          || propertyName.equals(PROPERTY_ELEMENT_FORM_DEFAULT) || propertyName.equals(PROPERTY_ANNOTATION_MAP) || super.supports(propertyName);
836
				result = list;
835
    }
837
			} else if (propertyName.equals(PROPERTY_ELEMENT_FORM_DEFAULT)) {
836
838
				result = xsdSchema.getElementFormDefault().getName();
837
    /**
839
			} else if (propertyName.equals(PROPERTY_ANNOTATION_MAP)) {
838
     * Returns true if a prefix is globally required for elements.
840
				result = annotationMap;
839
     * 
841
			} else if (propertyName.equals("allElements")) {
840
     * @param xsdSchema -
842
				result = getAllElements();
841
     *          the corresponding schema node.
843
			} else if (propertyName.startsWith("getElementForType#")) {
842
     * @return true if a prefix is globally required for elements.
844
				int index = propertyName.indexOf("#");
843
     */
845
				String typeName = propertyName.substring(index + 1,
844
    protected boolean isPrefixRequired(XSDSchema xsdSchema)
846
						propertyName.length());
845
    {
847
				//
846
      boolean result = true;
848
				//
847
      if (xsdSchema.isSetElementFormDefault())
849
				XSDTypeDefinition td = xsdSchema
848
        result = !(xsdSchema.getElementFormDefault().getValue() == XSDForm.QUALIFIED);
850
						.resolveTypeDefinition(typeName);
849
      return result;
851
				if (td != null) {
850
    }
852
					LocalElementVisitor localElementVisitor = new LocalElementVisitor();
851
853
					localElementVisitor.visitTypeDefinition(td);
852
    /**
854
					result = localElementVisitor.getCMNamedNodeMap();
853
     * Returns the property value for the property name. Returns null if the
855
				}
854
     * property is not supported.
856
			} else {
855
     * 
857
				result = super.getProperty(propertyName);
856
     * @param propertyName -
858
			}
857
     *          name of a property
859
			return result;
858
     * @return the property value for the property name.
860
		}
859
     */
861
860
    public Object getProperty(String propertyName)
862
		/**
861
    {
863
		 * Gather information on namespaces used in external references.
862
      Object result = null;
864
		 * 
863
      if (propertyName.equals(PROPERTY_TARGET_NAMESPACE_URI))
865
		 * @param theXSDSchema -
864
      {
866
		 *            the corresponding schema node
865
        result = xsdSchema.getTargetNamespace();
867
		 * @param list -
866
      }
868
		 *            the list of imported namespaces.
867
      else if (propertyName.equals(PROPERTY_IMPORTED_NAMESPACE_INFO))
869
		 */
868
      {
870
		public void getImportedNamespaceInfo(XSDSchema theXSDSchema, List list)
869
        List list = new Vector();
871
		{
870
        getImportedNamespaceInfo(xsdSchema, list);
872
871
        result = list;
873
			for (Iterator iterator = theXSDSchema.getContents().iterator(); iterator
872
      }
874
					.hasNext();) {
873
      else if (propertyName.equals(PROPERTY_NAMESPACE_INFO))
875
874
      {
876
				XSDSchemaContent content = (XSDSchemaContent) iterator.next();
875
        List list = new Vector();
877
				if (content instanceof XSDImport) {
876
        NamespaceInfo info = new NamespaceInfo();
878
					XSDImport xImport = (XSDImport) content;
877
        info.uri = xsdSchema.getTargetNamespace();
879
					XSDSchema importedXSDSchema = xImport.getResolvedSchema();
878
        info.prefix = getPrefix(xsdSchema, info.uri);
880
					NamespaceInfo info = new NamespaceInfo();
879
        info.locationHint = null; // note that this locationHint info is null
881
					info.uri = xImport.getNamespace();
880
                                  // for the root xsd file
882
					info.prefix = getPrefix(importedXSDSchema, info.uri);
881
        info.isPrefixRequired = isPrefixRequired(xsdSchema);
883
					info.locationHint = xImport.getSchemaLocation();
882
        list.add(info);
884
					if (importedXSDSchema != null) {
883
        getImportedNamespaceInfo(xsdSchema, list);
885
						info.isPrefixRequired = isPrefixRequired(importedXSDSchema);
884
        result = list;
886
					}
885
      }
887
					list.add(info);
886
      else if (propertyName.equals(PROPERTY_ELEMENT_FORM_DEFAULT))
888
				}
887
      {
889
			}
888
        result = xsdSchema.getElementFormDefault().getName();
890
         
889
      }
891
		}
890
      else if (propertyName.equals(PROPERTY_ANNOTATION_MAP))
892
		
891
      {
893
		/**
892
        result = annotationMap;
894
		 * Retrieve a list of all the namespaces that have been defined with the use of xmlns
893
      }
895
		 * in the schema.  This may or may not be more accurate than searching on the XSDImports
894
      else if (propertyName.equals("allElements"))
896
		 * 
895
      {
897
		 * @param theXSDSchema
896
        result = getAllElements();
898
		 * @param list
897
      }  
899
		 */
898
      else if (propertyName.startsWith("getElementForType#"))
900
		public void getAllNamespacesInfo(XSDSchema theXSDSchema, List list) {
899
      {
901
			org.w3c.dom.Document document = theXSDSchema.getDocument();
900
        int index = propertyName.indexOf("#");
902
			org.w3c.dom.Node rootNode = document.getFirstChild();
901
        String typeName = propertyName.substring(index + 1, propertyName.length());
903
			
902
        //
904
			org.w3c.dom.NamedNodeMap attributeList = rootNode.getAttributes();
903
        //
905
			
904
        XSDTypeDefinition td = xsdSchema.resolveTypeDefinition(typeName);
906
			for (int index = 0; index < attributeList.getLength(); index++) {
905
        if (td != null)
907
				org.w3c.dom.Attr attribute = (org.w3c.dom.Attr) attributeList.item(index);			
906
        {
908
				if (attribute.getNamespaceURI() != null) {
907
          LocalElementVisitor localElementVisitor = new LocalElementVisitor();
909
					if (checkNamespace(list, attribute.getNodeValue()) == false) {
908
          localElementVisitor.visitTypeDefinition(td);
910
						NamespaceInfo info = new NamespaceInfo();
909
          result = localElementVisitor.getCMNamedNodeMap();
911
						info.uri = attribute.getNodeValue();
910
        }
912
						info.prefix = attribute.getLocalName();
911
      }
913
						info.isPrefixRequired = true;
912
      else
914
						list.add(info);
913
      {
915
					}
914
        result = super.getProperty(propertyName);
916
					
915
      }
917
					//info.locationHint = xImport.getSchemaLocation();
916
      return result;
918
					//if (importedXSDSchema != null) {
917
    }
919
					//	info.isPrefixRequired = isPrefixRequired(importedXSDSchema);
918
920
					//}
919
    /**
921
				}
920
     * Gather information on namespaces used in external references.
922
			}
921
     * 
923
		}
922
     * @param theXSDSchema -
924
923
     *          the corresponding schema node
925
		private boolean checkNamespace(List list, String namespace) {
924
     * @param list -
926
			boolean returnSW = false;
925
     *          the list of imported namespaces.
927
			for (Iterator iterator = list.iterator(); iterator.hasNext();) {
926
     */
928
				NamespaceInfo info = (NamespaceInfo) iterator.next();
927
    public void getImportedNamespaceInfo(XSDSchema theXSDSchema, List list)
929
				if (info.uri.contentEquals(new StringBuffer(namespace))) {
928
    {
930
					returnSW = true;
929
      for (Iterator iterator = theXSDSchema.getContents().iterator(); iterator.hasNext();)
931
				}
930
      {
932
			}
931
        XSDSchemaContent content = (XSDSchemaContent) iterator.next();
933
932
        if (content instanceof XSDImport)
934
			return returnSW;
933
        {
935
		}
934
          XSDImport xImport = (XSDImport) content;
936
935
          XSDSchema importedXSDSchema = xImport.getResolvedSchema();
937
		/**
936
          NamespaceInfo info = new NamespaceInfo();
938
		 * Returns set of named (top-level) element declarations for this schema
937
          info.uri = xImport.getNamespace();
939
		 * node.
938
          info.prefix = getPrefix(importedXSDSchema, info.uri);
940
		 * 
939
          info.locationHint = xImport.getSchemaLocation();
941
		 * @return a set of named (top-level) element declarations.
940
          if (importedXSDSchema != null)
942
		 */
941
          {
943
		public CMNamedNodeMap getElements() {
942
            info.isPrefixRequired = isPrefixRequired(importedXSDSchema);
944
			if (namedNodeMap == null) {
943
          }
945
				namedNodeMap = new CMNamedNodeMapImpl();
944
          list.add(info);
946
945
        }
947
				// Note that if we call xsdSchema.getElementDeclarations()
946
      }
948
				// we get 'more' elements than we really want since we also
947
    }
949
				// get 'imported' elements. Below we test to ensure the elements
948
950
				// actually have the same target namespace as the schema.
949
    /**
951
				String targetNamespace = xsdSchema.getTargetNamespace();
950
     * Returns set of named (top-level) element declarations for this schema
952
				for (Iterator i = xsdSchema.getElementDeclarations().iterator(); i
951
     * node.
953
						.hasNext();) {
952
     * 
954
					XSDElementDeclaration ed = (XSDElementDeclaration) i.next();
953
     * @return a set of named (top-level) element declarations.
955
					if (targetNamespace != null ? targetNamespace.equals(ed
954
     */
956
							.getTargetNamespace())
955
    public CMNamedNodeMap getElements()
957
							: ed.getTargetNamespace() == null) {
956
    {
958
						XSDElementDeclarationAdapter adapter = (XSDElementDeclarationAdapter) getAdapter(ed);
957
      if (namedNodeMap == null)
959
						namedNodeMap.getHashtable().put(adapter.getNodeName(),
958
      {
960
								adapter);
959
        namedNodeMap = new CMNamedNodeMapImpl();
961
					}
960
        
962
				}
961
        // Note that if we call xsdSchema.getElementDeclarations()
963
			}
962
        // we get 'more' elements than we really want since we also
964
			return namedNodeMap;
963
        // get 'imported' elements.  Below we test to ensure the elements
965
		}
964
        // actually have the same target namespace as the schema.
966
965
        String targetNamespace = xsdSchema.getTargetNamespace();
967
		/**
966
        for (Iterator i = xsdSchema.getElementDeclarations().iterator(); i.hasNext();)
968
		 * Returns the built-in entity declarations.
967
        {
969
		 * 
968
          XSDElementDeclaration ed = (XSDElementDeclaration) i.next();
970
		 * @return the built-in entity declarations.
969
          if (targetNamespace != null ? targetNamespace.equals(ed.getTargetNamespace()) : ed.getTargetNamespace() == null)
971
		 */
970
          {
972
		public CMNamedNodeMap getEntities() {
971
            XSDElementDeclarationAdapter adapter = (XSDElementDeclarationAdapter) getAdapter(ed);
973
			if (entityNodeMap == null) {
972
            namedNodeMap.getHashtable().put(adapter.getNodeName(), adapter);
974
				entityNodeMap = new CMNamedNodeMapImpl();
973
          }
975
				// add the built in entity declarations
974
        }
976
				entityNodeMap.getHashtable().put("amp",
975
      }
977
						new CMEntityDeclarationImpl("amp", "&"));
976
      return namedNodeMap;
978
				entityNodeMap.getHashtable().put("lt",
977
    }
979
						new CMEntityDeclarationImpl("lt", "<"));
978
980
				entityNodeMap.getHashtable().put("gt",
979
    /**
981
						new CMEntityDeclarationImpl("gt", ">"));
980
     * Returns the built-in entity declarations.
982
				entityNodeMap.getHashtable().put("quot",
981
     * 
983
						new CMEntityDeclarationImpl("quot", "\""));
982
     * @return the built-in entity declarations.
984
				entityNodeMap.getHashtable().put("apos",
983
     */
985
						new CMEntityDeclarationImpl("apos", "'"));
984
    public CMNamedNodeMap getEntities()
986
			}
985
    {
987
			return entityNodeMap;
986
      if (entityNodeMap == null)
988
		}
987
      {
989
988
        entityNodeMap = new CMNamedNodeMapImpl();
990
		/**
989
        // add the built in entity declarations
991
		 * Returns the type of the node. The types are defined in CMNode class
990
        entityNodeMap.getHashtable().put("amp", new CMEntityDeclarationImpl("amp", "&"));
992
		 * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
991
        entityNodeMap.getHashtable().put("lt", new CMEntityDeclarationImpl("lt", "<"));
993
		 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
992
        entityNodeMap.getHashtable().put("gt", new CMEntityDeclarationImpl("gt", ">"));
994
		 * DOCUMENTATION).
993
        entityNodeMap.getHashtable().put("quot", new CMEntityDeclarationImpl("quot", "\""));
995
		 * 
994
        entityNodeMap.getHashtable().put("apos", new CMEntityDeclarationImpl("apos", "'"));
996
		 * @return the type of this node.
995
      }
997
		 */
996
      return entityNodeMap;
998
		public int getNodeType() {
997
    }
999
			return DOCUMENT;
998
1000
		}
999
    /**
1001
1000
     * Returns the type of the node. The types are defined in CMNode class
1002
		/*
1001
     * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1003
		 * Returns null. !!! Why are we not implementing this???? @return null.
1002
     * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1004
		 */
1003
     * DOCUMENTATION).
1005
		public CMNamespace getNamespace() {
1004
     * 
1006
			return null;
1005
     * @return the type of this node.
1007
		}
1006
     */
1008
1007
    public int getNodeType()
1009
		/**
1008
    {
1010
		 * Returns this.
1009
      return DOCUMENT;
1011
		 * 
1010
    }
1012
		 * @return this.
1011
1013
		 */
1012
    /*
1014
		public CMDocument getCMDocument() {
1013
     * Returns null. !!! Why are we not implementing this???? @return null.
1015
			return this;
1014
     */
1016
		}
1015
    public CMNamespace getNamespace()
1017
1016
    {
1018
		public CMNamedNodeMap getAllElements() {
1017
      return null;
1019
			CMNamedNodeMapImpl map = new CMNamedNodeMapImpl();
1018
    }
1020
			for (Iterator i = getElements().iterator(); i.hasNext();) {
1019
1021
				CMElementDeclaration ed = (CMElementDeclaration) i.next();
1020
    /**
1022
				map.put(ed);
1021
     * Returns this.
1023
				addLocalElementDefinitions(map, ed);
1022
     * 
1024
			}
1023
     * @return this.
1025
			return map;
1024
     */
1026
		}
1025
    public CMDocument getCMDocument()
1027
1026
    {
1028
		protected void addLocalElementDefinitions(CMNamedNodeMapImpl map,
1027
      return this;
1029
				CMElementDeclaration parentElementDeclaration) {
1028
    }
1030
			CMNamedNodeMap localElementMap = parentElementDeclaration
1029
    
1031
					.getLocalElements();
1030
    public CMNamedNodeMap getAllElements()
1032
			for (Iterator i = localElementMap.iterator(); i.hasNext();) {
1031
    {
1033
				CMElementDeclaration ed = (CMElementDeclaration) i.next();
1032
      CMNamedNodeMapImpl map = new CMNamedNodeMapImpl();
1034
				if (map.getNamedItem(ed.getNodeName()) == null) {
1033
      for (Iterator i = getElements().iterator(); i.hasNext(); )
1035
					map.put(ed);
1034
      {
1036
					addLocalElementDefinitions(map, ed);
1035
        CMElementDeclaration ed = (CMElementDeclaration)i.next();
1037
				}
1036
        map.put(ed);           
1038
			}
1037
        addLocalElementDefinitions(map, ed);              
1039
		}
1038
      }     
1040
	}
1039
      return map;
1041
1040
    }
1042
	/**
1041
    
1043
	 * XSDAttributeUseAdapter implements CMAttributeDeclaration. A
1042
    protected void addLocalElementDefinitions(CMNamedNodeMapImpl map, CMElementDeclaration parentElementDeclaration)
1044
	 * representation of the model object 'Attribute Use'.
1043
    {
1045
	 */
1044
      CMNamedNodeMap localElementMap = parentElementDeclaration.getLocalElements();
1046
	public static class XSDAttributeUseAdapter extends XSDBaseAdapter implements
1045
      for (Iterator i = localElementMap.iterator(); i.hasNext(); )
1047
			CMAttributeDeclaration {
1046
      {
1048
		// provides access to the XML Schema node
1047
        CMElementDeclaration ed = (CMElementDeclaration)i.next();
1049
		protected XSDAttributeUse xsdAttributeUse;
1048
        if (map.getNamedItem(ed.getNodeName()) == null)
1050
1049
        {  
1051
		// provides access to the type of the attribute
1050
          map.put(ed);        
1052
		protected CMDataType dataType = new DataTypeImpl();
1051
          addLocalElementDefinitions(map, ed);
1053
1052
        }  
1054
		/**
1053
      }               
1055
		 * Constructor.
1054
    }
1056
		 * 
1055
  }
1057
		 * @param xsdAttributeUse -
1056
  /**
1058
		 *            the XML Schema node.
1057
   * XSDAttributeUseAdapter implements CMAttributeDeclaration. A representation
1059
		 */
1058
   * of the model object 'Attribute Use'.
1060
		public XSDAttributeUseAdapter(XSDAttributeUse xsdAttributeUse) {
1059
   */
1061
			this.xsdAttributeUse = xsdAttributeUse;
1060
  public static class XSDAttributeUseAdapter extends XSDBaseAdapter implements CMAttributeDeclaration
1062
		}
1061
  {
1063
1062
    // provides access to the XML Schema node
1064
		/**
1063
    protected XSDAttributeUse xsdAttributeUse;
1065
		 * Returns the key for this cmnode which is the corresponding XML Schema
1064
    // provides access to the type of the attribute
1066
		 * node.
1065
    protected CMDataType dataType = new DataTypeImpl();
1067
		 * 
1066
1068
		 * @return the key for this cmnode.
1067
    /**
1069
		 */
1068
     * Constructor.
1070
		public Object getKey() {
1069
     * 
1071
			return xsdAttributeUse;
1070
     * @param xsdAttributeUse -
1072
		}
1071
     *          the XML Schema node.
1073
1072
     */
1074
		/**
1073
    public XSDAttributeUseAdapter(XSDAttributeUse xsdAttributeUse)
1075
		 * Returns a general XPath expression for the node.
1074
    {
1076
		 * 
1075
      this.xsdAttributeUse = xsdAttributeUse;
1077
		 * @return a general XPath expression for the node.
1076
    }
1078
		 */
1077
1079
		public String getSpec() {
1078
    /**
1080
			return "//@" + getAttrName();
1079
     * Returns the key for this cmnode which is the corresponding XML Schema
1081
		}
1080
     * node.
1082
1081
     * 
1083
		/**
1082
     * @return the key for this cmnode.
1084
		 * Returns the type of the node. The types are defined in CMNode class
1083
     */
1085
		 * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1084
    public Object getKey()
1086
		 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1085
    {
1087
		 * DOCUMENTATION).
1086
      return xsdAttributeUse;
1088
		 * 
1087
    }
1089
		 * @return the type of this node.
1088
1090
		 */
1089
    /**
1091
		public int getNodeType() {
1090
     * Returns a general XPath expression for the node.
1092
			return ATTRIBUTE_DECLARATION;
1091
     * 
1093
		}
1092
     * @return a general XPath expression for the node.
1094
1093
     */
1095
		/**
1094
    public String getSpec()
1096
		 * Returns the name of the node. Similar to getAttrName().
1095
    {
1097
		 * 
1096
      return "//@" + getAttrName();
1098
		 * @return the name of the node.
1097
    }
1099
		 */
1098
1100
		public String getNodeName() {
1099
    /**
1101
			return getAttrName();
1100
     * Returns the type of the node. The types are defined in CMNode class
1102
		}
1101
     * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1103
1102
     * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1104
		/**
1103
     * DOCUMENTATION).
1105
		 * getEnumAttr method
1104
     * 
1106
		 * 
1105
     * @return the type of this node.
1107
		 * @return java.util.Enumeration
1106
     */
1108
		 * @deprecated -- to be replaced in future with additional CMDataType
1107
    public int getNodeType()
1109
		 *             methods (currently found on CMDataTypeHelper)
1108
    {
1110
		 */
1109
      return ATTRIBUTE_DECLARATION;
1111
		public Enumeration getEnumAttr() {
1110
    }
1112
			return Collections.enumeration(Collections.EMPTY_LIST);
1111
1113
		}
1112
    /**
1114
1113
     * Returns the name of the node. Similar to getAttrName().
1115
		/**
1114
     * 
1116
		 * Returns the name of this attribute. Similar to getNodeName().
1115
     * @return the name of the node.
1117
		 * 
1116
     */
1118
		 * @return the name of this attribute.
1117
    public String getNodeName()
1119
		 */
1118
    {
1120
		public String getAttrName() {
1119
      return getAttrName();
1121
			return xsdAttributeUse.getAttributeDeclaration().getName();
1120
    }
1122
		}
1121
1123
1122
    /**
1124
		/**
1123
     * getEnumAttr method
1125
		 * Returns the type of the attribute.
1124
     * 
1126
		 * 
1125
     * @return java.util.Enumeration
1127
		 * @return the type of the attribute.
1126
     * @deprecated -- to be replaced in future with additional CMDataType
1128
		 */
1127
     *             methods (currently found on CMDataTypeHelper)
1129
		public CMDataType getAttrType() {
1128
     */
1130
			return dataType;
1129
    public Enumeration getEnumAttr()
1131
		}
1130
    {
1132
1131
      return Collections.enumeration(Collections.EMPTY_LIST);
1133
		/**
1132
    }
1134
		 * Returns the value of the default or fixed constraint.
1133
1135
		 * 
1134
    /**
1136
		 * @return the value of the default or fixed constraint.
1135
     * Returns the name of this attribute. Similar to getNodeName().
1137
		 */
1136
     * 
1138
		public String getDefaultValue() {
1137
     * @return the name of this attribute.
1139
			return dataType.getImpliedValue();
1138
     */
1140
		}
1139
    public String getAttrName()
1141
1140
    {
1142
		/**
1141
      return xsdAttributeUse.getAttributeDeclaration().getName();
1143
		 * Returns the usage constraint for this attribute. The usages are
1142
    }
1144
		 * defined in CMAttributeDeclaration class (OPTIONAL, REQUIRED, FIXED or
1143
1145
		 * PROHIBITED).
1144
    /**
1146
		 * 
1145
     * Returns the type of the attribute.
1147
		 * @return the usage constraint for this attribute.
1146
     * 
1148
		 */
1147
     * @return the type of the attribute.
1149
		public int getUsage() {
1148
     */
1150
			int useKind = OPTIONAL;
1149
    public CMDataType getAttrType()
1151
			switch (xsdAttributeUse.getUse().getValue()) {
1150
    {
1152
			case XSDAttributeUseCategory.OPTIONAL: {
1151
      return dataType;
1153
				useKind = OPTIONAL;
1152
    }
1154
				break;
1153
1155
			}
1154
    /**
1156
			case XSDAttributeUseCategory.PROHIBITED: {
1155
     * Returns the value of the default or fixed constraint.
1157
				useKind = PROHIBITED;
1156
     * 
1158
				break;
1157
     * @return the value of the default or fixed constraint.
1159
			}
1158
     */
1160
			case XSDAttributeUseCategory.REQUIRED: {
1159
    public String getDefaultValue()
1161
				useKind = REQUIRED;
1160
    {
1162
				break;
1161
      return dataType.getImpliedValue();
1163
			}
1162
    }
1164
			}
1163
1165
			return useKind;
1164
    /**
1166
		}
1165
     * Returns the usage constraint for this attribute. The usages are defined
1167
1166
     * in CMAttributeDeclaration class (OPTIONAL, REQUIRED, FIXED or
1168
		/*
1167
     * PROHIBITED).
1169
		 * Returns the value of the form [attribute] which affects the target
1168
     * 
1170
		 * namespace of locally scoped features. If the form is not set on this
1169
     * @return the usage constraint for this attribute.
1171
		 * attribute, then see if there is a globally defined default. @return
1170
     */
1172
		 * the value of the form [attribute].
1171
    public int getUsage()
1173
		 */
1172
    {
1174
		public Object getNSPrefixQualification() {
1173
      int useKind = OPTIONAL;
1175
			String form = null;
1174
      switch (xsdAttributeUse.getUse().getValue())
1176
			if (xsdAttributeUse.getContent() != xsdAttributeUse
1175
      {
1177
					.getAttributeDeclaration()) {
1176
        case XSDAttributeUseCategory.OPTIONAL : {
1178
				form = "qualified";
1177
          useKind = OPTIONAL;
1179
			} else if (xsdAttributeUse.getContent().isSetForm()) {
1178
          break;
1180
				form = xsdAttributeUse.getContent().getForm().getName();
1179
        }
1181
			} else {
1180
        case XSDAttributeUseCategory.PROHIBITED : {
1182
				XSDSchema schema = xsdAttributeUse.getSchema();
1181
          useKind = PROHIBITED;
1183
				if (schema != null)
1182
          break;
1184
					form = schema.getAttributeFormDefault().getName();
1183
        }
1185
			}
1184
        case XSDAttributeUseCategory.REQUIRED : {
1186
			return form;
1185
          useKind = REQUIRED;
1187
		}
1186
          break;
1188
1187
        }
1189
		/**
1188
      }
1190
		 * Return a list of documentation elements.
1189
      return useKind;
1191
		 * 
1190
    }
1192
		 * @return a list of documentation elements.
1191
1193
		 */
1192
    /*
1194
		protected CMNodeList getDocumentation() {
1193
     * Returns the value of the form [attribute] which affects the target
1195
			XSDAnnotation annotation = xsdAttributeUse
1194
     * namespace of locally scoped features. If the form is not set on this
1196
					.getAttributeDeclaration().getAnnotation();
1195
     * attribute, then see if there is a globally defined default. @return the
1197
			return getDocumentations(annotation);
1196
     * value of the form [attribute].
1198
		}
1197
     */
1199
1198
    public Object getNSPrefixQualification()
1200
		/**
1199
    {
1201
		 * Returns the cmdocument that is the owner of this cmnode.
1200
      String form = null;
1202
		 * 
1201
      if (xsdAttributeUse.getContent() != xsdAttributeUse.getAttributeDeclaration())
1203
		 * @return the cmdocument corresponding to this cmnode.
1202
      {
1204
		 */
1203
      	form =  "qualified";
1205
		public CMDocument getCMDocument() {
1204
      }	
1206
			return (CMDocument) getAdapter(xsdAttributeUse.getSchema());
1205
      else if (xsdAttributeUse.getContent().isSetForm())
1207
		}
1206
      {
1208
1207
        form = xsdAttributeUse.getContent().getForm().getName();
1209
		/**
1208
      }
1210
		 * XSDAttributeUseAdapter.DataTypeImpl An inner class to hold type
1209
      else
1211
		 * information for this attribute.
1210
      {
1212
		 */
1211
        XSDSchema schema = xsdAttributeUse.getSchema();
1213
		public class DataTypeImpl implements CMDataType {
1212
        if (schema != null)
1214
			/**
1213
          form = schema.getAttributeFormDefault().getName();
1215
			 * Returns the type of the node. The types are defined in CMNode
1214
      }
1216
			 * class (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1215
      return form;
1217
			 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1216
    }
1218
			 * DOCUMENTATION).
1217
1219
			 * 
1218
    /**
1220
			 * @return the type of this node.
1219
     * Return a list of documentation elements.
1221
			 */
1220
     * 
1222
			public int getNodeType() {
1221
     * @return a list of documentation elements.
1223
				return CMNode.DATA_TYPE;
1222
     */
1224
			}
1223
    protected CMNodeList getDocumentation()
1225
1224
    {
1226
			/**
1225
      XSDAnnotation annotation = xsdAttributeUse.getAttributeDeclaration().getAnnotation();
1227
			 * Returns the name of the attribute type. Same as
1226
      return getDocumentations(annotation);
1228
			 * getDataTypeName().
1227
    }
1229
			 * 
1228
1230
			 * @return the name of the attribute type.
1229
    /**
1231
			 */
1230
     * Returns the cmdocument that is the owner of this cmnode.
1232
			public String getNodeName() {
1231
     * 
1233
				return getDataTypeName();
1232
     * @return the cmdocument corresponding to this cmnode.
1234
			}
1233
     */
1235
1234
    public CMDocument getCMDocument()
1236
			/**
1235
    {
1237
			 * Returns false. This class does not support any properties.
1236
      return (CMDocument) getAdapter(xsdAttributeUse.getSchema());
1238
			 * 
1237
    }
1239
			 * @param propertyName -
1238
    /**
1240
			 *            name of a property
1239
     * XSDAttributeUseAdapter.DataTypeImpl An inner class to hold type
1241
			 * @return false.
1240
     * information for this attribute.
1242
			 */
1241
     */
1243
			public boolean supports(String propertyName) {
1242
    public class DataTypeImpl implements CMDataType
1244
				return false;
1243
    {
1245
			}
1244
      /**
1246
1245
       * Returns the type of the node. The types are defined in CMNode class
1247
			/**
1246
       * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1248
			 * Returns null. This class does not support any properties.
1247
       * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1249
			 * 
1248
       * DOCUMENTATION).
1250
			 * @param propertyName -
1249
       * 
1251
			 *            name of a property
1250
       * @return the type of this node.
1252
			 * @return null.
1251
       */
1253
			 */
1252
      public int getNodeType()
1254
			public Object getProperty(String propertyName) {
1253
      {
1255
				return null;
1254
        return CMNode.DATA_TYPE;
1256
			}
1255
      }
1257
1256
1258
			/**
1257
      /**
1259
			 * Returns the name of the attribute type. Same as getNodeName().
1258
       * Returns the name of the attribute type. Same as getDataTypeName().
1260
			 * 
1259
       * 
1261
			 * @return the name of the attribute type.
1260
       * @return the name of the attribute type.
1262
			 */
1261
       */
1263
			public String getDataTypeName() {
1262
      public String getNodeName()
1264
				XSDSimpleTypeDefinition sc = xsdAttributeUse
1263
      {
1265
						.getAttributeDeclaration().getTypeDefinition();
1264
        return getDataTypeName();
1266
				String typeName = sc.getName();
1265
      }
1267
				return typeName != null ? typeName : "string";
1266
1268
			}
1267
      /**
1269
1268
       * Returns false. This class does not support any properties.
1270
			/**
1269
       * 
1271
			 * Returns the kind of constraint: none, default or fixed. The kinds
1270
       * @param propertyName -
1272
			 * are defined in CMDataType class (IMPLIED_VALUE_NONE,
1271
       *          name of a property
1273
			 * IMPLIED_VALUE_FIXED or IMPLIED_VALUE_DEFAULT).
1272
       * @return false.
1274
			 * 
1273
       */
1275
			 * @return the kind of constraint: none, default or fixed.
1274
      public boolean supports(String propertyName)
1276
			 */
1275
      {
1277
			public int getImpliedValueKind() {
1276
        return false;
1278
				int result = IMPLIED_VALUE_NONE;
1277
      }
1279
				if (xsdAttributeUse.isSetConstraint()) {
1278
1280
					if (xsdAttributeUse.getConstraint().getValue() == XSDConstraint.DEFAULT)
1279
      /**
1281
						result = IMPLIED_VALUE_DEFAULT;
1280
       * Returns null. This class does not support any properties.
1282
					else if (xsdAttributeUse.getConstraint().getValue() == XSDConstraint.FIXED)
1281
       * 
1283
						result = IMPLIED_VALUE_FIXED;
1282
       * @param propertyName -
1284
				}
1283
       *          name of a property
1285
				return result;
1284
       * @return null.
1286
			}
1285
       */
1287
1286
      public Object getProperty(String propertyName)
1288
			/**
1287
      {
1289
			 * Returns the value of the default or fixed constraint.
1288
        return null;
1290
			 * 
1289
      }
1291
			 * @return the value of the default or fixed constraint.
1290
1292
			 */
1291
      /**
1293
			public String getImpliedValue() {
1292
       * Returns the name of the attribute type. Same as getNodeName().
1294
				String result = null;
1293
       * 
1295
				if (xsdAttributeUse.isSetConstraint()) {
1294
       * @return the name of the attribute type.
1296
					result = xsdAttributeUse.getLexicalValue();
1295
       */
1297
				}
1296
      public String getDataTypeName()
1298
				return result;
1297
      {
1299
			}
1298
        XSDSimpleTypeDefinition sc = xsdAttributeUse.getAttributeDeclaration().getTypeDefinition();
1300
1299
        String typeName = sc.getName();
1301
			/**
1300
        return typeName != null ? typeName : "string";
1302
			 * Returns the enumerated values for the attribute type.
1301
      }
1303
			 * 
1302
1304
			 * @return the enumerated values for the attribute type.
1303
      /**
1305
			 */
1304
       * Returns the kind of constraint: none, default or fixed. The kinds are
1306
			public String[] getEnumeratedValues() {
1305
       * defined in CMDataType class (IMPLIED_VALUE_NONE, IMPLIED_VALUE_FIXED or
1307
				return getEnumeratedValuesForType(getXSDType());
1306
       * IMPLIED_VALUE_DEFAULT).
1308
			}
1307
       * 
1309
1308
       * @return the kind of constraint: none, default or fixed.
1310
			/**
1309
       */
1311
			 * Generate a valid value for the attribute based on its type.
1310
      public int getImpliedValueKind()
1312
			 * 
1311
      {
1313
			 * @return a valid value for the attribute based on its type.
1312
        int result = IMPLIED_VALUE_NONE;
1314
			 */
1313
        if (xsdAttributeUse.isSetConstraint())
1315
			public String generateInstanceValue() {
1314
        {
1316
				XSDAttributeDeclaration attr = xsdAttributeUse
1315
          if (xsdAttributeUse.getConstraint().getValue() == XSDConstraint.DEFAULT)
1317
						.getAttributeDeclaration();
1316
            result = IMPLIED_VALUE_DEFAULT;
1318
				return XSDTypeUtil.getInstanceValue(attr
1317
          else if (xsdAttributeUse.getConstraint().getValue() == XSDConstraint.FIXED)
1319
						.getResolvedAttributeDeclaration().getTypeDefinition());
1318
            result = IMPLIED_VALUE_FIXED;
1320
			}
1319
        }
1321
1320
        return result;
1322
			/**
1321
      }
1323
			 * Returns the corresponding XML Schema type definition.
1322
1324
			 * 
1323
      /**
1325
			 * @return the corresponding XML Schema type definition.
1324
       * Returns the value of the default or fixed constraint.
1326
			 */
1325
       * 
1327
			protected XSDTypeDefinition getXSDType() {
1326
       * @return the value of the default or fixed constraint.
1328
				XSDAttributeDeclaration attr = xsdAttributeUse
1327
       */
1329
						.getAttributeDeclaration();
1328
      public String getImpliedValue()
1330
				return attr.getResolvedAttributeDeclaration()
1329
      {
1331
						.getTypeDefinition();
1330
        String result = null;
1332
			}
1331
        if (xsdAttributeUse.isSetConstraint())
1333
		}
1332
        {
1334
	}
1333
          result = xsdAttributeUse.getLexicalValue();
1335
1334
        }
1336
	/**
1335
        return result;
1337
	 * ElementDeclarationBaseImpl implements CMElementDeclaration. This is the
1336
      }
1338
	 * base class for XSDElementDeclaration and DerivedElementDeclarationImpl.
1337
1339
	 * 
1338
      /**
1340
	 * Abstract methods in this class are: public abstract Object getKey();
1339
       * Returns the enumerated values for the attribute type.
1341
	 * public abstract Object getNSPrefixQualification(); public abstract
1340
       * 
1342
	 * XSDElementDeclaration getXSDElementDeclaration(); public abstract
1341
       * @return the enumerated values for the attribute type.
1343
	 * XSDTypeDefinition getXSDType(); public abstract List getXSITypes();
1342
       */
1344
	 * public abstract CMElementDeclaration getDerivedElementDeclaration(String
1343
      public String[] getEnumeratedValues()
1345
	 * uriQualifiedTypeName); public abstract CMNode getDefinition(); public
1344
      {
1346
	 * abstract String getDefinitionInfo(); public abstract CMNodeListImpl
1345
        return getEnumeratedValuesForType(getXSDType());
1347
	 * getSubstitutionGroup();
1346
      }
1348
	 */
1347
1349
	public static abstract class ElementDeclarationBaseImpl extends
1348
      /**
1350
			XSDBaseAdapter implements CMElementDeclaration {
1349
       * Generate a valid value for the attribute based on its type.
1351
		protected CMDataType dataType = new DataTypeImpl();
1350
       * 
1352
1351
       * @return a valid value for the attribute based on its type.
1353
		protected CMNamedNodeMap namedNodeMap;
1352
       */
1354
1353
      public String generateInstanceValue()
1355
		/**
1354
      {
1356
		 * Returns corresponding XML Schema element declaration.
1355
        XSDAttributeDeclaration attr = xsdAttributeUse.getAttributeDeclaration();
1357
		 * 
1356
        return XSDTypeUtil.getInstanceValue(attr.getResolvedAttributeDeclaration().getTypeDefinition());
1358
		 * @return corresponding XML Schema element declaration.
1357
      }
1359
		 */
1358
1360
		protected abstract XSDElementDeclaration getXSDElementDeclaration();
1359
      /**
1361
1360
       * Returns the corresponding XML Schema type definition.
1362
		/**
1361
       * 
1363
		 * Returns corresponding XML Schema element declaration.
1362
       * @return the corresponding XML Schema type definition.
1364
		 * 
1363
       */
1365
		 * @return corresponding XML Schema element declaration.
1364
      protected XSDTypeDefinition getXSDType()
1366
		 */
1365
      {
1367
		protected abstract XSDElementDeclaration getResolvedXSDElementDeclaration();
1366
        XSDAttributeDeclaration attr = xsdAttributeUse.getAttributeDeclaration();
1368
1367
        return attr.getResolvedAttributeDeclaration().getTypeDefinition();
1369
		/**
1368
      }
1370
		 * Returns the type of the node. The types are defined in CMNode class
1369
    }
1371
		 * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1370
  }
1372
		 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1371
  /**
1373
		 * DOCUMENTATION).
1372
   * ElementDeclarationBaseImpl implements CMElementDeclaration. This is the
1374
		 * 
1373
   * base class for XSDElementDeclaration and DerivedElementDeclarationImpl.
1375
		 * @return the type of this node.
1374
   * 
1376
		 */
1375
   * Abstract methods in this class are: public abstract Object getKey(); public
1377
		public int getNodeType() {
1376
   * abstract Object getNSPrefixQualification(); public abstract
1378
			return ELEMENT_DECLARATION;
1377
   * XSDElementDeclaration getXSDElementDeclaration(); public abstract
1379
		}
1378
   * XSDTypeDefinition getXSDType(); public abstract List getXSITypes(); public
1380
1379
   * abstract CMElementDeclaration getDerivedElementDeclaration(String
1381
		/**
1380
   * uriQualifiedTypeName); public abstract CMNode getDefinition(); public
1382
		 * Returns the name of the node. The same as getElementName().
1381
   * abstract String getDefinitionInfo(); public abstract CMNodeListImpl
1383
		 * 
1382
   * getSubstitutionGroup();
1384
		 * @return the name of the node.
1383
   */
1385
		 */
1384
  public static abstract class ElementDeclarationBaseImpl extends XSDBaseAdapter implements CMElementDeclaration
1386
		public String getNodeName() {
1385
  {
1387
			return getElementName();
1386
    protected CMDataType dataType = new DataTypeImpl();
1388
		}
1387
    protected CMNamedNodeMap namedNodeMap;
1389
1388
1390
		/**
1389
    /**
1391
		 * Returns the name of this element. The same as getNodeName().
1390
     * Returns corresponding XML Schema element declaration.
1392
		 * 
1391
     * 
1393
		 * @return the name of this element.
1392
     * @return corresponding XML Schema element declaration.
1394
		 */
1393
     */
1395
		public String getElementName() {
1394
    protected abstract XSDElementDeclaration getXSDElementDeclaration();
1396
			String result = getResolvedXSDElementDeclaration().getName();
1395
1397
			return result != null ? result : "";
1396
    /**
1398
		}
1397
     * Returns corresponding XML Schema element declaration.
1399
1398
     * 
1400
		/**
1399
     * @return corresponding XML Schema element declaration.
1401
		 * Returns true if the property is supported for this class.
1400
     */
1402
		 * 
1401
    protected abstract XSDElementDeclaration getResolvedXSDElementDeclaration();
1403
		 * @param propertyName -
1402
1404
		 *            name of a property
1403
    /**
1405
		 * @return true if the property is supported.
1404
     * Returns the type of the node. The types are defined in CMNode class
1406
		 */
1405
     * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1407
		public boolean supports(String propertyName) {
1406
     * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1408
			return propertyName.equals(PROPERTY_XSITYPES)
1407
     * DOCUMENTATION).
1409
					|| propertyName
1408
     * 
1410
							.equals(PROPERTY_DERIVED_ELEMENT_DECLARATION)
1409
     * @return the type of this node.
1411
					|| propertyName.equals(PROPERTY_SUBSTITUTION_GROUP)
1410
     */
1412
					|| propertyName.equals(PROPERTY_ABSTRACT)
1411
    public int getNodeType()
1413
					|| super.supports(propertyName);
1412
    {
1414
		}
1413
      return ELEMENT_DECLARATION;
1415
1414
    }
1416
		/**
1415
1417
		 * Returns the key for this cmnode which is the corresponding XML Schema
1416
    /**
1418
		 * node.
1417
     * Returns the name of the node. The same as getElementName().
1419
		 * 
1418
     * 
1420
		 * @return the key for this cmnode.
1419
     * @return the name of the node.
1421
		 */
1420
     */
1422
		public abstract Object getKey();
1421
    public String getNodeName()
1423
1422
    {
1424
		/**
1423
      return getElementName();
1425
		 * Returns the set of attributes defined for this element.
1424
    }
1426
		 * 
1425
1427
		 * @return the set of attributes defined for this element.
1426
    /**
1428
		 */
1427
     * Returns the name of this element. The same as getNodeName().
1429
		public CMNamedNodeMap getAttributes() {
1428
     * 
1430
			CMNamedNodeMapImpl map = new CMNamedNodeMapImpl();
1429
     * @return the name of this element.
1431
			XSDTypeDefinition td = getXSDType();
1430
     */
1432
			getAttributes(map, td);
1431
    public String getElementName()
1433
			addXSITypeAttribute(map);
1432
    {
1434
			return map;
1433
      String result = getResolvedXSDElementDeclaration().getName();
1435
		}
1434
      return result != null ? result : "";
1436
1435
    }
1437
		/**
1436
1438
		 * Gather the set of attributes defined for this element.
1437
    /**
1439
		 * 
1438
     * Returns true if the property is supported for this class.
1440
		 * @param map -
1439
     * 
1441
		 *            used for returning the set of attributes.
1440
     * @param propertyName -
1442
		 * @param xsdTypeDefinition -
1441
     *          name of a property
1443
		 *            the type definition for this element.
1442
     * @return true if the property is supported.
1444
		 */
1443
     */
1445
		public void getAttributes(CMNamedNodeMapImpl map,
1444
    public boolean supports(String propertyName)
1446
				XSDTypeDefinition xsdTypeDefinition) {
1445
    {
1447
			if (xsdTypeDefinition instanceof XSDComplexTypeDefinition) {
1446
      return propertyName.equals(PROPERTY_XSITYPES) || propertyName.equals(PROPERTY_DERIVED_ELEMENT_DECLARATION) || propertyName.equals(PROPERTY_SUBSTITUTION_GROUP)
1448
				XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) xsdTypeDefinition;
1447
          || propertyName.equals(PROPERTY_ABSTRACT) || super.supports(propertyName);
1449
				for (Iterator i = ctd.getAttributeUses().iterator(); i
1448
    }
1450
						.hasNext();) {
1449
1451
					XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) i
1450
    /**
1452
							.next();
1451
     * Returns the key for this cmnode which is the corresponding XML Schema
1453
					XSDAttributeUseAdapter adapter = (XSDAttributeUseAdapter) getAdapter(xsdAttributeUse);
1452
     * node.
1454
					if (adapter != null && adapter.getNodeName() != null) {
1453
     * 
1455
						map.getHashtable().put(adapter.getNodeName(), adapter);
1454
     * @return the key for this cmnode.
1456
					}
1455
     */
1457
				}
1456
    public abstract Object getKey();
1458
			}
1457
1459
		}
1458
    /**
1460
1459
     * Returns the set of attributes defined for this element.
1461
		/**
1460
     * 
1462
		 * Returns the content for this element.
1461
     * @return the set of attributes defined for this element.
1463
		 * 
1462
     */
1464
		 * @return the content for this element.
1463
    public CMNamedNodeMap getAttributes()
1465
		 */
1464
    {
1466
		public CMContent getContent() {
1465
      CMNamedNodeMapImpl map = new CMNamedNodeMapImpl();
1467
			CMContent result = null;
1466
      XSDTypeDefinition td = getXSDType();
1468
			XSDTypeDefinition td = getXSDType();
1467
      getAttributes(map, td);
1469
			if (td instanceof XSDComplexTypeDefinition) {
1468
      addXSITypeAttribute(map);
1470
				DerivedChildVisitor dcv = new DerivedChildVisitor(td);
1469
      return map;
1471
				dcv.visitTypeDefinition(td);
1470
    }
1472
				CMNodeList nodeList = dcv.getChildNodeList();
1471
1473
				if (nodeList.getLength() > 1) {
1472
    /**
1474
					result = new CMGroupImpl(nodeList, CMGroup.SEQUENCE);
1473
     * Gather the set of attributes defined for this element.
1475
				} else if (nodeList.getLength() > 0) {
1474
     * 
1476
					result = (CMContent) nodeList.item(0);
1475
     * @param map -
1477
				}
1476
     *          used for returning the set of attributes.
1478
			}
1477
     * @param xsdTypeDefinition -
1479
			return result;
1478
     *          the type definition for this element.
1480
		}
1479
     */
1481
1480
    public void getAttributes(CMNamedNodeMapImpl map, XSDTypeDefinition xsdTypeDefinition)
1482
		/**
1481
    {
1483
		 * Returns the content type of this element. The content type is defined
1482
      if (xsdTypeDefinition instanceof XSDComplexTypeDefinition)
1484
		 * in CMElementDeclaration (ANY, EMPTY, ELEMENT, MIXED, PCDATA or
1483
      {
1485
		 * CDATA).
1484
        XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) xsdTypeDefinition;
1486
		 * 
1485
        for (Iterator i = ctd.getAttributeUses().iterator(); i.hasNext();)
1487
		 * @return the content type of this element.
1486
        {
1488
		 */
1487
          XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) i.next();
1489
		public int getContentType() {
1488
          XSDAttributeUseAdapter adapter = (XSDAttributeUseAdapter) getAdapter(xsdAttributeUse);
1490
			int contentType = EMPTY;
1489
          if (adapter != null && adapter.getNodeName() != null)
1491
			XSDTypeDefinition td = getXSDType();
1490
          {
1492
			if (td instanceof XSDSimpleTypeDefinition) {
1491
            map.getHashtable().put(adapter.getNodeName(), adapter);
1493
				String typeName = td.getName();
1492
          }
1494
				if (typeName != null && typeName.equals("anyType")) {
1493
        }
1495
					contentType = ANY;
1494
      }
1496
				} else {
1495
    }
1497
					contentType = PCDATA;
1496
1498
				}
1497
    /**
1499
			} else if (td instanceof XSDComplexTypeDefinition) {
1498
     * Returns the content for this element.
1500
				XSDContentTypeCategory category = ((XSDComplexTypeDefinition) td)
1499
     * 
1501
						.getContentTypeCategory();
1500
     * @return the content for this element.
1502
				if (category != null) {
1501
     */
1503
					switch (category.getValue()) {
1502
    public CMContent getContent()
1504
					case XSDContentTypeCategory.ELEMENT_ONLY:
1503
    {
1505
						contentType = ELEMENT;
1504
      CMContent result = null;
1506
						break;
1505
      XSDTypeDefinition td = getXSDType();
1507
					case XSDContentTypeCategory.EMPTY:
1506
      if (td instanceof XSDComplexTypeDefinition)
1508
						contentType = EMPTY;
1507
      {
1509
						break;
1508
        DerivedChildVisitor dcv = new DerivedChildVisitor(td);
1510
					case XSDContentTypeCategory.MIXED:
1509
        dcv.visitTypeDefinition(td);
1511
						contentType = MIXED;
1510
        CMNodeList nodeList = dcv.getChildNodeList();
1512
						break;
1511
        if (nodeList.getLength() > 1)
1513
					case XSDContentTypeCategory.SIMPLE:
1512
        {
1514
						contentType = PCDATA;
1513
          result = new CMGroupImpl(nodeList, CMGroup.SEQUENCE);
1515
						break;
1514
        }
1516
					}
1515
        else if (nodeList.getLength() > 0)
1517
				}
1516
        {
1518
			}
1517
          result = (CMContent) nodeList.item(0);
1519
			return contentType;
1518
        }
1520
		}
1519
      }
1521
1520
      return result;
1522
		/**
1521
    }
1523
		 * Returns the name of the element type.
1522
1524
		 * 
1523
    /**
1525
		 * @return the name of the element type.
1524
     * Returns the content type of this element. The content type is defined in
1526
		 */
1525
     * CMElementDeclaration (ANY, EMPTY, ELEMENT, MIXED, PCDATA or CDATA).
1527
		public CMDataType getDataType() {
1526
     * 
1528
			CMDataType result = null;
1527
     * @return the content type of this element.
1529
			int contentType = getContentType();
1528
     */
1530
			boolean hasDataType = contentType == PCDATA || contentType == MIXED;
1529
    public int getContentType()
1531
			if (hasDataType) {
1530
    {
1532
				result = dataType;
1531
      int contentType = EMPTY;
1533
			}
1532
      XSDTypeDefinition td = getXSDType();
1534
			return result;
1533
      if (td instanceof XSDSimpleTypeDefinition)
1535
		}
1534
      {
1536
1535
        String typeName = td.getName();
1537
		/**
1536
        if (typeName != null && typeName.equals("anyType"))
1538
		 * Returns the value of 'Min Occurs' attribute. The default value is
1537
        {
1539
		 * "1".
1538
          contentType = ANY;
1540
		 * 
1539
        }
1541
		 * @return the value of the 'Min Occurs' attribute.
1540
        else
1542
		 */
1541
        {
1543
		public int getMinOccur() {
1542
          contentType = PCDATA;
1544
			return getMinOccurs(getXSDElementDeclaration());
1543
        }
1545
		}
1544
      }
1546
1545
      else if (td instanceof XSDComplexTypeDefinition)
1547
		/**
1546
      {
1548
		 * Returns the value of the 'Max Occurs' attribute. The default value is
1547
        XSDContentTypeCategory category = ((XSDComplexTypeDefinition) td).getContentTypeCategory();
1549
		 * "1".
1548
        if (category != null)
1550
		 * 
1549
        {
1551
		 * @return the value of the 'Max Occurs' attribute.
1550
          switch (category.getValue())
1552
		 */
1551
          {
1553
		public int getMaxOccur() {
1552
            case XSDContentTypeCategory.ELEMENT_ONLY :
1554
			return getMaxOccurs(getXSDElementDeclaration());
1553
              contentType = ELEMENT;
1555
		}
1554
              break;
1556
1555
            case XSDContentTypeCategory.EMPTY :
1557
		/**
1556
              contentType = EMPTY;
1558
		 * Returns the referenced element declaration if this is an element
1557
              break;
1559
		 * reference. Otherwise it returns itself.
1558
            case XSDContentTypeCategory.MIXED :
1560
		 * 
1559
              contentType = MIXED;
1561
		 * @return an element declaration.
1560
              break;
1562
		 */
1561
            case XSDContentTypeCategory.SIMPLE :
1563
		protected abstract CMNode getDefinition();
1562
              contentType = PCDATA;
1564
1563
              break;
1565
		/**
1564
          }
1566
		 * Returns a string indicating whether the element declaration is global
1565
        }
1567
		 * or local. Returns null if this is an element reference.
1566
      }
1568
		 * 
1567
      return contentType;
1569
		 * @return a string indicating whether the element declaration is global
1568
    }
1570
		 *         or local.
1569
1571
		 */
1570
    /**
1572
		protected abstract String getDefinitionInfo();
1571
     * Returns the name of the element type.
1573
1572
     * 
1574
		/**
1573
     * @return the name of the element type.
1575
		 * Returns the elements local to this element declaration.
1574
     */
1576
		 * 
1575
    public CMDataType getDataType()
1577
		 * @return the elements local to this element declaration.
1576
    {
1578
		 */
1577
      CMDataType result = null;
1579
		public CMNamedNodeMap getLocalElements() {
1578
      int contentType = getContentType();
1580
			if (namedNodeMap == null) {
1579
      boolean hasDataType = contentType == PCDATA || contentType == MIXED;
1581
				LocalElementVisitor localElementVisitor = new LocalElementVisitor();
1580
      if (hasDataType)
1582
				localElementVisitor.visitTypeDefinition(getXSDType());
1581
      {
1583
				namedNodeMap = localElementVisitor.getCMNamedNodeMap();
1582
        result = dataType;
1584
			}
1583
      }
1585
			return namedNodeMap;
1584
      return result;
1586
		}
1585
    }
1587
1586
1588
		/**
1587
    /**
1589
		 * Returns the property value for the property name. Returns null if the
1588
     * Returns the value of 'Min Occurs' attribute. The default value is "1".
1590
		 * property is not supported.
1589
     * 
1591
		 * 
1590
     * @return the value of the 'Min Occurs' attribute.
1592
		 * @param propertyName -
1591
     */
1593
		 *            name of a property
1592
    public int getMinOccur()
1594
		 * @return the property value for the property name.
1593
    {
1595
		 */
1594
      return getMinOccurs(getXSDElementDeclaration());
1596
		public Object getProperty(String propertyName) {
1595
    }
1597
			Object result = null;
1596
1598
			if (propertyName.equals(PROPERTY_DEFINITION_INFO)) {
1597
    /**
1599
				result = getDefinitionInfo();
1598
     * Returns the value of the 'Max Occurs' attribute. The default value is
1600
			} else if (propertyName.equals(PROPERTY_DEFINITION)) {
1599
     * "1".
1601
				result = getDefinition();
1600
     * 
1602
			} else if (propertyName.equals(PROPERTY_XSITYPES)) {
1601
     * @return the value of the 'Max Occurs' attribute.
1603
				result = getXSITypes();
1602
     */
1604
			} else if (propertyName
1603
    public int getMaxOccur()
1605
					.startsWith(PROPERTY_DERIVED_ELEMENT_DECLARATION)) {
1604
    {
1606
				int index = propertyName.indexOf("=");
1605
      return getMaxOccurs(getXSDElementDeclaration());
1607
				if (index != -1) {
1606
    }
1608
					String uriQualifiedTypeName = propertyName
1607
1609
							.substring(index + 1);
1608
    /**
1610
					result = getDerivedElementDeclaration(uriQualifiedTypeName);
1609
     * Returns the referenced element declaration if this is an element
1611
				}
1610
     * reference. Otherwise it returns itself.
1612
			} else if (propertyName.equals(PROPERTY_SUBSTITUTION_GROUP)) {
1611
     * 
1613
				return getSubstitutionGroup();
1612
     * @return an element declaration.
1614
			} else if (propertyName.equals(PROPERTY_ABSTRACT)) {
1613
     */
1615
				return getAbstract();
1614
    protected abstract CMNode getDefinition();
1616
			} else {
1615
1617
				result = super.getProperty(propertyName);
1616
    /**
1618
			}
1617
     * Returns a string indicating whether the element declaration is global or
1619
			return result;
1618
     * local. Returns null if this is an element reference.
1620
		}
1619
     * 
1621
1620
     * @return a string indicating whether the element declaration is global or
1622
		/**
1621
     *         local.
1623
		 * Returns the value of the 'Nillable' attribute. This represents the
1622
     */
1624
		 * nillable infoset property. The default value is false.
1623
    protected abstract String getDefinitionInfo();
1625
		 * 
1624
1626
		 * @return the value of the 'Nillable' attribute.
1625
    /**
1627
		 */
1626
     * Returns the elements local to this element declaration.
1628
		public boolean isNillable() {
1627
     * 
1629
			if (getXSDElementDeclaration().isSetNillable())
1628
     * @return the elements local to this element declaration.
1630
				return getXSDElementDeclaration().isNillable();
1629
     */
1631
			else
1630
    public CMNamedNodeMap getLocalElements()
1632
				return false;
1631
    {
1633
		}
1632
      if (namedNodeMap == null)
1634
1633
      {
1635
		/**
1634
        LocalElementVisitor localElementVisitor = new LocalElementVisitor();
1636
		 * Returns whether the element is 'Abstract'.
1635
        localElementVisitor.visitTypeDefinition(getXSDType());
1637
		 * 
1636
        namedNodeMap = localElementVisitor.getCMNamedNodeMap();
1638
		 * @return true if the element is 'Abstract'.
1637
      }
1639
		 */
1638
      return namedNodeMap;
1640
		public Boolean getAbstract() {
1639
    }
1641
			boolean result = getResolvedXSDElementDeclaration().isAbstract();
1640
1642
			// TODO... how do we handle elements with abstract type's ?
1641
    /**
1643
			return result ? Boolean.TRUE : Boolean.FALSE;
1642
     * Returns the property value for the property name. Returns null if the
1644
		}
1643
     * property is not supported.
1645
1644
     * 
1646
		/**
1645
     * @param propertyName -
1647
		 * Returns a list of documentation elements.
1646
     *          name of a property
1648
		 * 
1647
     * @return the property value for the property name.
1649
		 * @return a list of documentation elements.
1648
     */
1650
		 */
1649
    public Object getProperty(String propertyName)
1651
		protected CMNodeList getDocumentation() {
1650
    {
1652
			XSDAnnotation annotation = getXSDElementDeclaration()
1651
      Object result = null;
1653
					.getAnnotation();
1652
      if (propertyName.equals(PROPERTY_DEFINITION_INFO))
1654
			return getDocumentations(annotation);
1653
      {
1655
		}
1654
        result = getDefinitionInfo();
1656
1655
      }
1657
		/**
1656
      else if (propertyName.equals(PROPERTY_DEFINITION))
1658
		 * Returns the corresponding XML Schema type definition.
1657
      {
1659
		 * 
1658
        result = getDefinition();
1660
		 * @return the corresponding XML Schema type definition.
1659
      }
1661
		 */
1660
      else if (propertyName.equals(PROPERTY_XSITYPES))
1662
		protected abstract XSDTypeDefinition getXSDType();
1661
      {
1663
1662
        result = getXSITypes();
1664
		/**
1663
      }
1665
		 * Returns a list of type names.
1664
      else if (propertyName.startsWith(PROPERTY_DERIVED_ELEMENT_DECLARATION))
1666
		 * 
1665
      {
1667
		 * @return a list of type names.
1666
        int index = propertyName.indexOf("=");
1668
		 */
1667
        if (index != -1)
1669
		protected abstract List getXSITypes();
1668
        {
1670
1669
          String uriQualifiedTypeName = propertyName.substring(index + 1);
1671
		/**
1670
          result = getDerivedElementDeclaration(uriQualifiedTypeName);
1672
		 * Return the element declaration corresponding to the given uri
1671
        }
1673
		 * qualified type name.
1672
      }
1674
		 * 
1673
      else if (propertyName.equals(PROPERTY_SUBSTITUTION_GROUP))
1675
		 * @param uriQualifiedTypeName -
1674
      {
1676
		 *            a uri qualified type name
1675
        return getSubstitutionGroup();
1677
		 * @return corresponding element declaration.
1676
      }
1678
		 */
1677
      else if (propertyName.equals(PROPERTY_ABSTRACT))
1679
		protected abstract CMElementDeclaration getDerivedElementDeclaration(
1678
      {
1680
				String uriQualifiedTypeName);
1679
        return getAbstract();
1681
1680
      }
1682
		/**
1681
      else
1683
		 * Returns a list of documentation elements.
1682
      {
1684
		 * 
1683
        result = super.getProperty(propertyName);
1685
		 * @return a list of documentation elements.
1684
      }
1686
		 */
1685
      return result;
1687
		protected void addXSITypeAttribute(CMNamedNodeMapImpl map) {
1686
    }
1688
			List list = getXSITypes();
1687
1689
			int listSize = list.size();
1688
    /**
1690
			if (listSize > 1) {
1689
     * Returns the value of the 'Nillable' attribute. This represents the
1691
				CMDataType dataType = new CMDataTypeImpl("typeNames",
1690
     * nillable infoset property. The default value is false.
1692
						(String) null);
1691
     * 
1693
				CMAttributeDeclarationImpl attribute = new CMAttributeDeclarationImpl(
1692
     * @return the value of the 'Nillable' attribute.
1694
						"type", CMAttributeDeclaration.OPTIONAL, dataType);
1693
     */
1695
				attribute.setCMDocument(xsiDocument);
1694
    public boolean isNillable()
1696
				attribute.setPrefixQualification(true);
1695
    {
1697
				attribute.setXSITypes(list);
1696
      if (getXSDElementDeclaration().isSetNillable())
1698
				map.getHashtable().put(attribute.getNodeName(), attribute);
1697
        return getXSDElementDeclaration().isNillable();
1699
			}
1698
      else
1700
		}
1699
        return false;
1701
1700
    }
1702
		/**
1701
1703
		 * Returns the cmdocument that is the owner of this cmnode.
1702
    /**
1704
		 * 
1703
     * Returns whether the element is 'Abstract'.
1705
		 * @return the cmdocument corresponding to this cmnode.
1704
     * 
1706
		 */
1705
     * @return true if the element is 'Abstract'.
1707
		public CMDocument getCMDocument() {
1706
     */
1708
			XSDSchema schema = getResolvedXSDElementDeclaration().getSchema();
1707
    public Boolean getAbstract()
1709
			if (schema == null)
1708
    {
1710
				return null;
1709
      boolean result = getResolvedXSDElementDeclaration().isAbstract();
1711
			else
1710
      // TODO... how do we handle elements with abstract type's ?
1712
				return (CMDocument) getAdapter(schema);
1711
      return result ? Boolean.TRUE : Boolean.FALSE;
1713
		}
1712
    }
1714
1713
1715
		/**
1714
    /**
1716
		 * Returns the substitution group for this element. The group consists
1715
     * Returns a list of documentation elements.
1717
		 * of: 1. the element declaration itself 2. and any element declaration
1716
     * 
1718
		 * that has a {substitution group affiliation} in the group
1717
     * @return a list of documentation elements.
1719
		 * 
1718
     */
1720
		 * @return the substitution group for this element.
1719
    protected CMNodeList getDocumentation()
1721
		 */
1720
    {
1722
		protected abstract CMNodeListImpl getSubstitutionGroup();
1721
      XSDAnnotation annotation = getXSDElementDeclaration().getAnnotation();
1723
1722
      return getDocumentations(annotation);
1724
		/*
1723
    }
1725
		 * XSDElementDeclarationAdapter.DataTypeImpl An inner class to hold type
1724
1726
		 * information for this element.
1725
    /**
1727
		 */
1726
     * Returns the corresponding XML Schema type definition.
1728
		public class DataTypeImpl implements CMDataType {
1727
     * 
1729
			/**
1728
     * @return the corresponding XML Schema type definition.
1730
			 * Returns the type of the node. The types are defined in CMNode
1729
     */
1731
			 * class (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1730
    protected abstract XSDTypeDefinition getXSDType();
1732
			 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1731
1733
			 * DOCUMENTATION).
1732
    /**
1734
			 * 
1733
     * Returns a list of type names.
1735
			 * @return the type of this node.
1734
     * 
1736
			 */
1735
     * @return a list of type names.
1737
			public int getNodeType() {
1736
     */
1738
				return CMNode.DATA_TYPE;
1737
    protected abstract List getXSITypes();
1739
			}
1738
1740
1739
    /**
1741
			/**
1740
     * Return the element declaration corresponding to the given uri qualified
1742
			 * Returns the name of the element type. Same as getDataTypeName().
1741
     * type name.
1743
			 * 
1742
     * 
1744
			 * @return the name of the element type.
1743
     * @param uriQualifiedTypeName -
1745
			 */
1744
     *          a uri qualified type name
1746
			public String getNodeName() {
1745
     * @return corresponding element declaration.
1747
				return getDataTypeName();
1746
     */
1748
			}
1747
    protected abstract CMElementDeclaration getDerivedElementDeclaration(String uriQualifiedTypeName);
1749
1748
1750
			/**
1749
    /**
1751
			 * Returns false. This class does not support any properties.
1750
     * Returns a list of documentation elements.
1752
			 * 
1751
     * 
1753
			 * @param propertyName -
1752
     * @return a list of documentation elements.
1754
			 *            name of a property
1753
     */
1755
			 * @return false.
1754
    protected void addXSITypeAttribute(CMNamedNodeMapImpl map)
1756
			 */
1755
    {
1757
			public boolean supports(String propertyName) {
1756
      List list = getXSITypes();
1758
				return false;
1757
      int listSize = list.size();
1759
			}
1758
      if (listSize > 1)
1760
1759
      {
1761
			/**
1760
        CMDataType dataType = new CMDataTypeImpl("typeNames", (String) null);
1762
			 * Returns null. This class does not support any properties.
1761
        CMAttributeDeclarationImpl attribute = new CMAttributeDeclarationImpl("type", CMAttributeDeclaration.OPTIONAL, dataType);
1763
			 * 
1762
        attribute.setCMDocument(xsiDocument);
1764
			 * @param propertyName -
1763
        attribute.setPrefixQualification(true);
1765
			 *            name of a property
1764
        attribute.setXSITypes(list);
1766
			 * @return null.
1765
        map.getHashtable().put(attribute.getNodeName(), attribute);
1767
			 */
1766
      }
1768
			public Object getProperty(String propertyName) {
1767
    }
1769
				return null;
1768
1770
			}
1769
    /**
1771
1770
     * Returns the cmdocument that is the owner of this cmnode.
1772
			/**
1771
     * 
1773
			 * Returns the name of the element type. Same as getNodeName().
1772
     * @return the cmdocument corresponding to this cmnode.
1774
			 * 
1773
     */
1775
			 * @return the name of the element type.
1774
    public CMDocument getCMDocument()
1776
			 */
1775
    {      
1777
			public String getDataTypeName() {
1776
      XSDSchema schema = getResolvedXSDElementDeclaration().getSchema();
1778
				String typeName = null;
1777
      if (schema == null)
1779
				XSDSimpleTypeDefinition std = getXSDType().getSimpleType();
1778
        return null;
1780
				if (std != null)
1779
      else  
1781
					typeName = std.getName();
1780
        return (CMDocument) getAdapter(schema);
1782
				return typeName != null ? typeName : "string";
1781
    }
1783
			}
1782
1784
1783
    /**
1785
			/**
1784
     * Returns the substitution group for this element. The group consists of:
1786
			 * Returns the kind of constraint: none, default or fixed. The kinds
1785
     * 1. the element declaration itself 2. and any element declaration that has
1787
			 * are defined in CMDataType class (IMPLIED_VALUE_NONE,
1786
     * a {substitution group affiliation} in the group
1788
			 * IMPLIED_VALUE_FIXED or IMPLIED_VALUE_DEFAULT).
1787
     * 
1789
			 * 
1788
     * @return the substitution group for this element.
1790
			 * @return the kind of constraint: none, default or fixed.
1789
     */
1791
			 */
1790
    protected abstract CMNodeListImpl getSubstitutionGroup();
1792
			public int getImpliedValueKind() {
1791
    /*
1793
				int result = IMPLIED_VALUE_NONE;
1792
     * XSDElementDeclarationAdapter.DataTypeImpl An inner class to hold type
1794
				if (getXSDElementDeclaration().isSetConstraint()) {
1793
     * information for this element.
1795
					if (getXSDElementDeclaration().getConstraint().getValue() == XSDConstraint.DEFAULT)
1794
     */
1796
						result = IMPLIED_VALUE_DEFAULT;
1795
    public class DataTypeImpl implements CMDataType
1797
					else if (getXSDElementDeclaration().getConstraint()
1796
    {
1798
							.getValue() == XSDConstraint.FIXED)
1797
      /**
1799
						result = IMPLIED_VALUE_FIXED;
1798
       * Returns the type of the node. The types are defined in CMNode class
1800
				}
1799
       * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
1801
				return result;
1800
       * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
1802
			}
1801
       * DOCUMENTATION).
1803
1802
       * 
1804
			/**
1803
       * @return the type of this node.
1805
			 * Returns the value of the default or fixed constraint.
1804
       */
1806
			 * 
1805
      public int getNodeType()
1807
			 * @return the value of the default or fixed constraint.
1806
      {
1808
			 */
1807
        return CMNode.DATA_TYPE;
1809
			public String getImpliedValue() {
1808
      }
1810
				String result = null;
1809
1811
				if (getXSDElementDeclaration().isSetConstraint()) {
1810
      /**
1812
					result = getXSDElementDeclaration().getLexicalValue();
1811
       * Returns the name of the element type. Same as getDataTypeName().
1813
				}
1812
       * 
1814
				return result;
1813
       * @return the name of the element type.
1815
			}
1814
       */
1816
1815
      public String getNodeName()
1817
			/**
1816
      {
1818
			 * Returns the enumerated values for the attribute type.
1817
        return getDataTypeName();
1819
			 * 
1818
      }
1820
			 * @return the enumerated values for the attribute type.
1819
1821
			 */
1820
      /**
1822
			public String[] getEnumeratedValues() {
1821
       * Returns false. This class does not support any properties.
1823
				return getEnumeratedValuesForType(getXSDType());
1822
       * 
1824
			}
1823
       * @param propertyName -
1825
1824
       *          name of a property
1826
			public String generateInstanceValue() {
1825
       * @return false.
1827
				return XSDTypeUtil.getInstanceValue(getXSDType());
1826
       */
1828
			}
1827
      public boolean supports(String propertyName)
1829
1828
      {
1830
			/**
1829
        return false;
1831
			 * Returns the cmdocument that is the owner of this cmnode.
1830
      }
1832
			 * 
1831
1833
			 * @return the cmdocument corresponding to this cmnode.
1832
      /**
1834
			 */
1833
       * Returns null. This class does not support any properties.
1835
			public CMDocument getCMDocument() {
1834
       * 
1836
				return (CMDocument) getAdapter(getXSDElementDeclaration()
1835
       * @param propertyName -
1837
						.getSchema());
1836
       *          name of a property
1838
			}
1837
       * @return null.
1839
		}
1838
       */
1840
	}
1839
      public Object getProperty(String propertyName)
1841
1840
      {
1842
	/**
1841
        return null;
1843
	 * XSDElementDeclarationAdapter implements CMElementDeclaration. A
1842
      }
1844
	 * representation of the model object 'Element Declaration'.
1843
1845
	 */
1844
      /**
1846
	public static class XSDElementDeclarationAdapter extends
1845
       * Returns the name of the element type. Same as getNodeName().
1847
			ElementDeclarationBaseImpl {
1846
       * 
1848
		protected List derivedElementDeclarations = null;
1847
       * @return the name of the element type.
1849
1848
       */
1850
		protected List xsiTypes = null;
1849
      public String getDataTypeName()
1851
1850
      {
1852
		protected XSDElementDeclaration xsdElementDeclaration;
1851
        String typeName = null;
1853
1852
        XSDSimpleTypeDefinition std = getXSDType().getSimpleType();
1854
		protected CMNodeListImpl substitutionGroup;
1853
        if (std != null)
1855
1854
          typeName = std.getName();
1856
		/**
1855
        return typeName != null ? typeName : "string";
1857
		 * Constructor.
1856
      }
1858
		 * 
1857
1859
		 * @param xsdElementDeclaration -
1858
      /**
1860
		 *            the XML Schema node.
1859
       * Returns the kind of constraint: none, default or fixed. The kinds are
1861
		 */
1860
       * defined in CMDataType class (IMPLIED_VALUE_NONE, IMPLIED_VALUE_FIXED or
1862
		public XSDElementDeclarationAdapter(
1861
       * IMPLIED_VALUE_DEFAULT).
1863
				XSDElementDeclaration xsdElementDeclaration) {
1862
       * 
1864
			this.xsdElementDeclaration = xsdElementDeclaration;
1863
       * @return the kind of constraint: none, default or fixed.
1865
		}
1864
       */
1866
1865
      public int getImpliedValueKind()
1867
		/**
1866
      {
1868
		 * Returns corresponding XML Schema element declaration.
1867
        int result = IMPLIED_VALUE_NONE;
1869
		 * 
1868
        if (getXSDElementDeclaration().isSetConstraint())
1870
		 * @return corresponding XML Schema element declaration.
1869
        {
1871
		 */
1870
          if (getXSDElementDeclaration().getConstraint().getValue() == XSDConstraint.DEFAULT)
1872
		protected XSDElementDeclaration getXSDElementDeclaration() {
1871
            result = IMPLIED_VALUE_DEFAULT;
1873
			return xsdElementDeclaration;
1872
          else if (getXSDElementDeclaration().getConstraint().getValue() == XSDConstraint.FIXED)
1874
		}
1873
            result = IMPLIED_VALUE_FIXED;
1875
1874
        }
1876
		/**
1875
        return result;
1877
		 * Returns corresponding XML Schema element declaration.
1876
      }
1878
		 * 
1877
1879
		 * @return corresponding XML Schema element declaration.
1878
      /**
1880
		 */
1879
       * Returns the value of the default or fixed constraint.
1881
		protected XSDElementDeclaration getResolvedXSDElementDeclaration() {
1880
       * 
1882
			return xsdElementDeclaration.getResolvedElementDeclaration();
1881
       * @return the value of the default or fixed constraint.
1883
		}
1882
       */
1884
1883
      public String getImpliedValue()
1885
		/**
1884
      {
1886
		 * Returns the key for this cmnode which is the corresponding XML Schema
1885
        String result = null;
1887
		 * node.
1886
        if (getXSDElementDeclaration().isSetConstraint())
1888
		 * 
1887
        {
1889
		 * @return the key for this cmnode.
1888
          result = getXSDElementDeclaration().getLexicalValue();
1890
		 */
1889
        }
1891
		public Object getKey() {
1890
        return result;
1892
			return xsdElementDeclaration;
1891
      }
1893
		}
1892
1894
1893
      /**
1895
		/**
1894
       * Returns the enumerated values for the attribute type.
1896
		 * Returns the referenced element declaration if this is an element
1895
       * 
1897
		 * reference. Otherwise it returns itself.
1896
       * @return the enumerated values for the attribute type.
1898
		 * 
1897
       */
1899
		 * @return an element declaration.
1898
      public String[] getEnumeratedValues()
1900
		 */
1899
      {
1901
		public CMNode getDefinition() {
1900
        return getEnumeratedValuesForType(getXSDType());
1902
			return getAdapter(xsdElementDeclaration
1901
      }
1903
					.getResolvedElementDeclaration());
1902
1904
		}
1903
      public String generateInstanceValue()
1905
1904
      {
1906
		/**
1905
        return XSDTypeUtil.getInstanceValue(getXSDType());
1907
		 * Returns a string indicating whether the element declaration is global
1906
      }
1908
		 * or local. Returns null if this is an element reference.
1907
1909
		 * 
1908
      /**
1910
		 * @return a string indicating whether the element declaration is global
1909
       * Returns the cmdocument that is the owner of this cmnode.
1911
		 *         or local.
1910
       * 
1912
		 */
1911
       * @return the cmdocument corresponding to this cmnode.
1913
		protected String getDefinitionInfo() {
1912
       */
1914
			if (xsdElementDeclaration.isElementDeclarationReference())
1913
      public CMDocument getCMDocument()
1915
				return null;
1914
      {
1916
			else if (xsdElementDeclaration.isGlobal())
1915
        return (CMDocument) getAdapter(getXSDElementDeclaration().getSchema());
1917
				return DEFINITION_INFO_GLOBAL;
1916
      }
1918
			else
1917
    }
1919
				return DEFINITION_INFO_LOCAL;
1918
  }
1920
		}
1919
  /**
1921
1920
   * XSDElementDeclarationAdapter implements CMElementDeclaration. A
1922
		public Object getNSPrefixQualification() {
1921
   * representation of the model object 'Element Declaration'.
1923
			String form = null;
1922
   */
1924
			if (xsdElementDeclaration.isElementDeclarationReference()) {
1923
  public static class XSDElementDeclarationAdapter extends ElementDeclarationBaseImpl
1925
				form = "qualified";
1924
  {
1926
			} else {
1925
    protected List derivedElementDeclarations = null;
1927
				if (xsdElementDeclaration.isSetForm()) {
1926
    protected List xsiTypes = null;
1928
					form = xsdElementDeclaration.getForm().getName();
1927
    protected XSDElementDeclaration xsdElementDeclaration;
1929
				} else {
1928
    protected CMNodeListImpl substitutionGroup;
1930
					XSDSchema schema = xsdElementDeclaration.getSchema();
1929
1931
					if (schema != null)
1930
    /**
1932
						form = schema.getElementFormDefault().getName();
1931
     * Constructor.
1933
				}
1932
     * 
1934
			}
1933
     * @param xsdElementDeclaration -
1935
			return form;
1934
     *          the XML Schema node.
1936
		}
1935
     */
1937
1936
    public XSDElementDeclarationAdapter(XSDElementDeclaration xsdElementDeclaration)
1938
		/**
1937
    {
1939
		 * Returns the corresponding XML Schema type definition.
1938
      this.xsdElementDeclaration = xsdElementDeclaration;
1940
		 * 
1939
    }
1941
		 * @return the corresponding XML Schema type definition.
1940
1942
		 */
1941
    /**
1943
		protected XSDTypeDefinition getXSDType() {
1942
     * Returns corresponding XML Schema element declaration.
1944
			return xsdElementDeclaration.getResolvedElementDeclaration()
1943
     * 
1945
					.getTypeDefinition();
1944
     * @return corresponding XML Schema element declaration.
1946
		}
1945
     */
1947
1946
    protected XSDElementDeclaration getXSDElementDeclaration()
1948
		/**
1947
    {
1949
		 * Returns a list of type names.
1948
      return xsdElementDeclaration;
1950
		 * 
1949
    }
1951
		 * @return a list of type names.
1950
1952
		 */
1951
    /**
1953
		protected List getXSITypes() {
1952
     * Returns corresponding XML Schema element declaration.
1954
			if (xsiTypes == null) {
1953
     * 
1955
				computeDerivedTypeInfo();
1954
     * @return corresponding XML Schema element declaration.
1956
			}
1955
     */
1957
			return xsiTypes;
1956
    protected XSDElementDeclaration getResolvedXSDElementDeclaration()
1958
		}
1957
    {
1959
1958
      return xsdElementDeclaration.getResolvedElementDeclaration();
1960
		protected void computeDerivedTypeInfo() {
1959
    }
1961
			xsiTypes = new Vector();
1960
1962
			derivedElementDeclarations = new Vector();
1961
    /**
1963
			computeDerivedTypeInfoHelper(getXSDType(), xsiTypes,
1962
     * Returns the key for this cmnode which is the corresponding XML Schema
1964
					derivedElementDeclarations);
1963
     * node.
1965
		}
1964
     * 
1966
1965
     * @return the key for this cmnode.
1967
		protected void computeDerivedTypeInfoHelper(XSDTypeDefinition type,
1966
     */
1968
				List typeNameList, List edList) {
1967
    public Object getKey()
1969
			if (type instanceof XSDComplexTypeDefinition) {
1968
    {
1970
				List derivedTypes = findTypesDerivedFrom(type);
1969
      return xsdElementDeclaration;
1971
				ArrayList inclusiveDerivedTypes = new ArrayList();
1970
    }
1972
				inclusiveDerivedTypes.add(type);
1971
1973
				if ((derivedTypes != null) && (derivedTypes.size() > 0)) {
1972
    /**
1974
					inclusiveDerivedTypes.addAll(derivedTypes);
1973
     * Returns the referenced element declaration if this is an element
1975
				}
1974
     * reference. Otherwise it returns itself.
1976
				for (Iterator i = inclusiveDerivedTypes.iterator(); i.hasNext();) {
1975
     * 
1977
					XSDTypeDefinition derivedType = (XSDTypeDefinition) i
1976
     * @return an element declaration.
1978
							.next();
1977
     */
1979
					XSDSchema schema = derivedType.getSchema();
1978
    public CMNode getDefinition()
1980
					if (schema != null) {
1979
    {
1981
						String uri = schema.getTargetNamespace();
1980
      return getAdapter(xsdElementDeclaration.getResolvedElementDeclaration());
1982
						String name = derivedType.getName();
1981
    }
1983
						if (name != null) {
1982
1984
							name = uri != null ? ("[" + uri + "]" + name)
1983
    /**
1985
									: name;
1984
     * Returns a string indicating whether the element declaration is global or
1986
							typeNameList.add(name);
1985
     * local. Returns null if this is an element reference.
1987
							DerivedElementDeclarationImpl ed = new DerivedElementDeclarationImpl(
1986
     * 
1988
									this, derivedType, name);
1987
     * @return a string indicating whether the element declaration is global or
1989
							edList.add(ed);
1988
     *         local.
1990
						}
1989
     */
1991
					}
1990
    protected String getDefinitionInfo()
1992
				}
1991
    {
1993
			}
1992
      if (xsdElementDeclaration.isElementDeclarationReference())
1994
		}
1993
        return null;
1995
1994
      else if (xsdElementDeclaration.isGlobal())
1996
		/**
1995
        return DEFINITION_INFO_GLOBAL;
1997
		 * Return the element declaration corresponding to the given uri
1996
      else
1998
		 * qualified type name.
1997
        return DEFINITION_INFO_LOCAL;
1999
		 * 
1998
    }
2000
		 * @param uriQualifiedTypeName -
1999
2001
		 *            a uri qualified type name
2000
    public Object getNSPrefixQualification()
2002
		 * @return corresponding element declaration.
2001
    {
2003
		 */
2002
      String form = null;
2004
		protected CMElementDeclaration getDerivedElementDeclaration(
2003
      if (xsdElementDeclaration.isElementDeclarationReference())
2005
				String uriQualifiedTypeName) {
2004
      {
2006
			CMElementDeclaration result = null;
2005
        form = "qualified";
2007
			if (derivedElementDeclarations == null) {
2006
      }
2008
				computeDerivedTypeInfo();
2007
      else
2009
			}
2008
      {
2010
			for (Iterator i = derivedElementDeclarations.iterator(); i
2009
        if (xsdElementDeclaration.isSetForm())
2011
					.hasNext();) {
2010
        {
2012
				DerivedElementDeclarationImpl ed = (DerivedElementDeclarationImpl) i
2011
          form = xsdElementDeclaration.getForm().getName();
2013
						.next();
2012
        }
2014
				if ((ed != null) && (ed.uriQualifiedTypeName != null)) {
2013
        else
2015
					if (ed.uriQualifiedTypeName.equals(uriQualifiedTypeName)) {
2014
        {
2016
						result = ed;
2015
          XSDSchema schema = xsdElementDeclaration.getSchema();
2017
						break;
2016
          if (schema != null)
2018
					}
2017
            form = schema.getElementFormDefault().getName();
2019
				}
2018
        }
2020
			}
2019
      }
2021
			return result;
2020
      return form;
2022
		}
2021
    }
2023
2022
2024
		/**
2023
    /**
2025
		 * Returns the substitution group for this element. The group consists
2024
     * Returns the corresponding XML Schema type definition.
2026
		 * of: 1. the element declaration itself 2. and any element declaration
2025
     * 
2027
		 * that has a {substitution group affiliation} in the group
2026
     * @return the corresponding XML Schema type definition.
2028
		 * 
2027
     */
2029
		 * @return the substitution group for this element.
2028
    protected XSDTypeDefinition getXSDType()
2030
		 */
2029
    {
2031
		protected CMNodeListImpl getSubstitutionGroup() {
2030
      return xsdElementDeclaration.getResolvedElementDeclaration().getTypeDefinition();
2032
			if (substitutionGroup == null) {
2031
    }
2033
				substitutionGroup = new CMNodeListImpl();
2032
2034
				List sgroup = getResolvedXSDElementDeclaration()
2033
    /**
2035
						.getSubstitutionGroup();
2034
     * Returns a list of type names.
2036
				for (Iterator i = sgroup.iterator(); i.hasNext();) {
2035
     * 
2037
					XSDElementDeclaration ed = (XSDElementDeclaration) i.next();
2036
     * @return a list of type names.
2038
					substitutionGroup.add(getAdapter(ed));
2037
     */
2039
				}
2038
    protected List getXSITypes()
2040
			}
2039
    {
2041
			return substitutionGroup;
2040
      if (xsiTypes == null)
2042
		}
2041
      {
2043
	}
2042
        computeDerivedTypeInfo();
2044
2043
      }
2045
	/**
2044
      return xsiTypes;
2046
	 * DerivedElementDeclarationImpl extends ElementDeclarationBaseImpl
2045
    }
2047
	 * 
2046
2048
	 */
2047
    protected void computeDerivedTypeInfo()
2049
	public static class DerivedElementDeclarationImpl extends
2048
    {
2050
			ElementDeclarationBaseImpl {
2049
      xsiTypes = new Vector();
2051
		protected XSDElementDeclarationAdapter owner;
2050
      derivedElementDeclarations = new Vector();
2052
2051
      computeDerivedTypeInfoHelper(getXSDType(), xsiTypes, derivedElementDeclarations);
2053
		protected XSDTypeDefinition xsdType;
2052
    }
2054
2053
2055
		public String uriQualifiedTypeName;
2054
    protected void computeDerivedTypeInfoHelper(XSDTypeDefinition type, List typeNameList, List edList)
2056
2055
    {
2057
		/**
2056
      if (type instanceof XSDComplexTypeDefinition)
2058
		 * Constructor.
2057
      {
2059
		 * 
2058
        List derivedTypes = findTypesDerivedFrom(type);
2060
		 * @param owner -
2059
        ArrayList inclusiveDerivedTypes = new ArrayList();
2061
		 * @param xsdType -
2060
        inclusiveDerivedTypes.add(type);
2062
		 * @param uriQualifiedTypeName -
2061
        if ((derivedTypes != null) && (derivedTypes.size() > 0))
2063
		 */
2062
        {
2064
		public DerivedElementDeclarationImpl(
2063
          inclusiveDerivedTypes.addAll(derivedTypes);
2065
				XSDElementDeclarationAdapter owner, XSDTypeDefinition xsdType,
2064
        }
2066
				String uriQualifiedTypeName) {
2065
        for (Iterator i = inclusiveDerivedTypes.iterator(); i.hasNext();)
2067
			this.owner = owner;
2066
        {
2068
			this.xsdType = xsdType;
2067
          XSDTypeDefinition derivedType = (XSDTypeDefinition) i.next();
2069
			this.uriQualifiedTypeName = uriQualifiedTypeName;
2068
          XSDSchema schema = derivedType.getSchema();
2070
		}
2069
          if (schema != null)
2071
2070
          {
2072
		/**
2071
            String uri = schema.getTargetNamespace();
2073
		 * Returns corresponding XML Schema element declaration.
2072
            String name = derivedType.getName();
2074
		 * 
2073
            if (name != null)
2075
		 * @return corresponding XML Schema element declaration.
2074
            {
2076
		 */
2075
              name = uri != null ? ("[" + uri + "]" + name) : name;
2077
		protected XSDElementDeclaration getXSDElementDeclaration() {
2076
              typeNameList.add(name);
2078
			return (XSDElementDeclaration) owner.getKey();
2077
              DerivedElementDeclarationImpl ed = new DerivedElementDeclarationImpl(this, derivedType, name);
2079
		}
2078
              edList.add(ed);
2080
2079
            }
2081
		/**
2080
          }
2082
		 * Returns corresponding XML Schema element declaration.
2081
        }
2083
		 * 
2082
      }
2084
		 * @return corresponding XML Schema element declaration.
2083
    }
2085
		 */
2084
2086
		protected XSDElementDeclaration getResolvedXSDElementDeclaration() {
2085
    /**
2087
			return ((XSDElementDeclaration) owner.getKey())
2086
     * Return the element declaration corresponding to the given uri qualified
2088
					.getResolvedElementDeclaration();
2087
     * type name.
2089
		}
2088
     * 
2090
2089
     * @param uriQualifiedTypeName -
2091
		/**
2090
     *          a uri qualified type name
2092
		 * Returns the key for this cmnode which is the corresponding XML Schema
2091
     * @return corresponding element declaration.
2093
		 * node.
2092
     */
2094
		 * 
2093
    protected CMElementDeclaration getDerivedElementDeclaration(String uriQualifiedTypeName)
2095
		 * @return the key for this cmnode.
2094
    {
2096
		 */
2095
      CMElementDeclaration result = null;
2097
		public Object getKey() {
2096
      if (derivedElementDeclarations == null)
2098
			return owner.getKey();
2097
      {
2099
		}
2098
        computeDerivedTypeInfo();
2100
2099
      }
2101
		/**
2100
      for (Iterator i = derivedElementDeclarations.iterator(); i.hasNext();)
2102
		 * Returns the corresponding XML Schema type definition.
2101
      {
2103
		 * 
2102
        DerivedElementDeclarationImpl ed = (DerivedElementDeclarationImpl) i.next();
2104
		 * @return the corresponding XML Schema type definition.
2103
        if ((ed != null) && (ed.uriQualifiedTypeName != null))
2105
		 */
2104
        {
2106
		protected XSDTypeDefinition getXSDType() {
2105
          if (ed.uriQualifiedTypeName.equals(uriQualifiedTypeName))
2107
			return xsdType;
2106
          {
2108
		}
2107
            result = ed;
2109
2108
            break;
2110
		/**
2109
          }
2111
		 * Returns a list of type names.
2110
        }
2112
		 * 
2111
      }
2113
		 * @return a list of type names.
2112
      return result;
2114
		 */
2113
    }
2115
		protected List getXSITypes() {
2114
2116
			return owner.getXSITypes();
2115
    /**
2117
		}
2116
     * Returns the substitution group for this element. The group consists of:
2118
2117
     * 1. the element declaration itself 2. and any element declaration that has
2119
		/**
2118
     * a {substitution group affiliation} in the group
2120
		 * Return the element declaration corresponding to the given uri
2119
     * 
2121
		 * qualified type name.
2120
     * @return the substitution group for this element.
2122
		 * 
2121
     */
2123
		 * @param uriQualifiedTypeName -
2122
    protected CMNodeListImpl getSubstitutionGroup()
2124
		 *            a uri qualified type name
2123
    {
2125
		 * @return corresponding element declaration.
2124
      if (substitutionGroup == null)
2126
		 */
2125
      {
2127
		protected CMElementDeclaration getDerivedElementDeclaration(
2126
        substitutionGroup = new CMNodeListImpl();
2128
				String uriQualifiedTypeName) {
2127
        List sgroup = getResolvedXSDElementDeclaration().getSubstitutionGroup();
2129
			return owner.getDerivedElementDeclaration(uriQualifiedTypeName);
2128
        for (Iterator i = sgroup.iterator(); i.hasNext();)
2130
		}
2129
        {
2131
2130
          XSDElementDeclaration ed = (XSDElementDeclaration) i.next();  
2132
		/**
2131
          substitutionGroup.add(getAdapter(ed));
2133
		 * Returns the referenced element declaration if this is an element
2132
        }
2134
		 * reference. Otherwise it returns itself.
2133
      }
2135
		 * 
2134
      return substitutionGroup;
2136
		 * @return an element declaration.
2135
    }
2137
		 */
2136
  }
2138
		protected CMNode getDefinition() {
2137
  /**
2139
			return this;
2138
   * DerivedElementDeclarationImpl extends ElementDeclarationBaseImpl
2140
		}
2139
   *  
2141
2140
   */
2142
		/**
2141
  public static class DerivedElementDeclarationImpl extends ElementDeclarationBaseImpl
2143
		 * Returns a string indicating whether the element declaration is global
2142
  {
2144
		 * or local. Returns null if this is an element reference.
2143
    protected XSDElementDeclarationAdapter owner;
2145
		 * 
2144
    protected XSDTypeDefinition xsdType;
2146
		 * @return a string indicating whether the element declaration is global
2145
    public String uriQualifiedTypeName;
2147
		 *         or local.
2146
2148
		 */
2147
    /**
2149
		protected String getDefinitionInfo() {
2148
     * Constructor.
2150
			return owner.getDefinitionInfo();
2149
     * 
2151
		}
2150
     * @param owner -
2152
2151
     * @param xsdType -
2153
		/*
2152
     * @param uriQualifiedTypeName -
2154
		 * Returns the value of the form [attribute] which affects the target
2153
     */
2155
		 * namespace of locally scoped features. @return the value of the form
2154
    public DerivedElementDeclarationImpl(XSDElementDeclarationAdapter owner, XSDTypeDefinition xsdType, String uriQualifiedTypeName)
2156
		 * [attribute].
2155
    {
2157
		 */
2156
      this.owner = owner;
2158
		public Object getNSPrefixQualification() {
2157
      this.xsdType = xsdType;
2159
			return owner.getNSPrefixQualification();
2158
      this.uriQualifiedTypeName = uriQualifiedTypeName;
2160
		}
2159
    }
2161
2160
2162
		/**
2161
    /**
2163
		 * Returns the substitution group for this element. The group consists
2162
     * Returns corresponding XML Schema element declaration.
2164
		 * of: 1. the element declaration itself 2. and any element declaration
2163
     * 
2165
		 * that has a {substitution group affiliation} in the group
2164
     * @return corresponding XML Schema element declaration.
2166
		 * 
2165
     */
2167
		 * @return the substitution group for this element.
2166
    protected XSDElementDeclaration getXSDElementDeclaration()
2168
		 */
2167
    {
2169
		protected CMNodeListImpl getSubstitutionGroup() {
2168
      return (XSDElementDeclaration) owner.getKey();
2170
			return owner.getSubstitutionGroup();
2169
    }
2171
		}
2170
2172
	}
2171
    /**
2173
2172
     * Returns corresponding XML Schema element declaration.
2174
	/**
2173
     * 
2175
	 * XSDWildcardAdapter
2174
     * @return corresponding XML Schema element declaration.
2176
	 */
2175
     */
2177
	public static class XSDWildcardAdapter extends XSDBaseAdapter implements
2176
    protected XSDElementDeclaration getResolvedXSDElementDeclaration()
2178
			CMAnyElement {
2177
    {
2179
		protected XSDWildcard xsdWildcard;
2178
      return ((XSDElementDeclaration) owner.getKey()).getResolvedElementDeclaration();
2180
2179
    }
2181
		public XSDWildcardAdapter(XSDWildcard xsdWildcard) {
2180
2182
			this.xsdWildcard = xsdWildcard;
2181
    /**
2183
		}
2182
     * Returns the key for this cmnode which is the corresponding XML Schema
2184
2183
     * node.
2185
		/**
2184
     * 
2186
		 * Returns the key for this cmnode which is the corresponding XML Schema
2185
     * @return the key for this cmnode.
2187
		 * node.
2186
     */
2188
		 * 
2187
    public Object getKey()
2189
		 * @return the key for this cmnode.
2188
    {
2190
		 */
2189
      return owner.getKey();
2191
		public Object getKey() {
2190
    }
2192
			return xsdWildcard;
2191
2193
		}
2192
    /**
2194
2193
     * Returns the corresponding XML Schema type definition.
2195
		/**
2194
     * 
2196
		 * Returns the type of the node. The types are defined in CMNode class
2195
     * @return the corresponding XML Schema type definition.
2197
		 * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
2196
     */
2198
		 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
2197
    protected XSDTypeDefinition getXSDType()
2199
		 * DOCUMENTATION).
2198
    {
2200
		 * 
2199
      return xsdType;
2201
		 * @return the type of this node.
2200
    }
2202
		 */
2201
2203
		public int getNodeType() {
2202
    /**
2204
			return ANY_ELEMENT;
2203
     * Returns a list of type names.
2205
		}
2204
     * 
2206
2205
     * @return a list of type names.
2207
		/**
2206
     */
2208
		 * Returns the name of the node. The default value is an empty string
2207
    protected List getXSITypes()
2209
		 * value. All derived classes must override this method if they do not
2208
    {
2210
		 * want the default value.
2209
      return owner.getXSITypes();
2211
		 * 
2210
    }
2212
		 * @return the name of the node.
2211
2213
		 */
2212
    /**
2214
		public String getNodeName() {
2213
     * Return the element declaration corresponding to the given uri qualified
2215
			return "any";
2214
     * type name.
2216
		}
2215
     * 
2217
2216
     * @param uriQualifiedTypeName -
2218
		public String getNamespaceURI() {
2217
     *          a uri qualified type name
2219
			String uri = xsdWildcard.getElement().getAttribute(
2218
     * @return corresponding element declaration.
2220
					XSDConstants.NAMESPACE_ATTRIBUTE);
2219
     */
2221
			return (uri != null && uri.length() > 0) ? uri : "##any";
2220
    protected CMElementDeclaration getDerivedElementDeclaration(String uriQualifiedTypeName)
2222
		}
2221
    {
2223
2222
      return owner.getDerivedElementDeclaration(uriQualifiedTypeName);
2224
		/**
2223
    }
2225
		 * Returns the value of 'Min Occurs' attribute. The default value is
2224
2226
		 * "1".
2225
    /**
2227
		 * 
2226
     * Returns the referenced element declaration if this is an element
2228
		 * @return the value of the 'Min Occurs' attribute.
2227
     * reference. Otherwise it returns itself.
2229
		 */
2228
     * 
2230
		public int getMinOccur() {
2229
     * @return an element declaration.
2231
			return getMinOccurs(xsdWildcard);
2230
     */
2232
		}
2231
    protected CMNode getDefinition()
2233
2232
    {
2234
		/**
2233
      return this;
2235
		 * Returns the value of the 'Max Occurs' attribute. The default value is
2234
    }
2236
		 * "1".
2235
2237
		 * 
2236
    /**
2238
		 * @return the value of the 'Max Occurs' attribute.
2237
     * Returns a string indicating whether the element declaration is global or
2239
		 */
2238
     * local. Returns null if this is an element reference.
2240
		public int getMaxOccur() {
2239
     * 
2241
			return getMaxOccurs(xsdWildcard);
2240
     * @return a string indicating whether the element declaration is global or
2242
		}
2241
     *         local.
2243
2242
     */
2244
		/**
2243
    protected String getDefinitionInfo()
2245
		 * Returns the cmdocument that is the owner of this cmnode.
2244
    {
2246
		 * 
2245
      return owner.getDefinitionInfo();
2247
		 * @return the cmdocument corresponding to this cmnode.
2246
    }
2248
		 */
2247
2249
		public CMDocument getCMDocument() {
2248
    /*
2250
			return (CMDocument) getAdapter(xsdWildcard.getSchema());
2249
     * Returns the value of the form [attribute] which affects the target
2251
		}
2250
     * namespace of locally scoped features. @return the value of the form
2252
2251
     * [attribute].
2253
		/**
2252
     */
2254
		 * Returns a list of documentation elements.
2253
    public Object getNSPrefixQualification()
2255
		 * 
2254
    {
2256
		 * @return a list of documentation elements.
2255
      return owner.getNSPrefixQualification();
2257
		 */
2256
    }
2258
		protected CMNodeList getDocumentation() {
2257
2259
			XSDAnnotation annotation = xsdWildcard.getAnnotation();
2258
    /**
2260
			return getDocumentations(annotation);
2259
     * Returns the substitution group for this element. The group consists of:
2261
		}
2260
     * 1. the element declaration itself 2. and any element declaration that has
2262
	}
2261
     * a {substitution group affiliation} in the group
2263
2262
     * 
2264
	/**
2263
     * @return the substitution group for this element.
2265
	 * XSDModelGroupAdapter
2264
     */
2266
	 */
2265
    protected CMNodeListImpl getSubstitutionGroup()
2267
	public static class XSDModelGroupAdapter extends XSDBaseAdapter implements
2266
    {
2268
			CMGroup {
2267
      return owner.getSubstitutionGroup();
2269
		protected XSDModelGroup xsdModelGroup;
2268
    }
2270
2269
  }
2271
		public XSDModelGroupAdapter() {
2270
  /**
2272
		}
2271
   * XSDWildcardAdapter
2273
2272
   */
2274
		public XSDModelGroupAdapter(XSDModelGroup xsdModelGroup) {
2273
  public static class XSDWildcardAdapter extends XSDBaseAdapter implements CMAnyElement
2275
			this.xsdModelGroup = xsdModelGroup;
2274
  {
2276
		}
2275
    protected XSDWildcard xsdWildcard;
2277
2276
2278
		/**
2277
    public XSDWildcardAdapter(XSDWildcard xsdWildcard)
2279
		 * Returns the type of the node. The types are defined in CMNode class
2278
    {
2280
		 * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
2279
      this.xsdWildcard = xsdWildcard;
2281
		 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
2280
    }
2282
		 * DOCUMENTATION).
2281
2283
		 * 
2282
    /**
2284
		 * @return the type of this node.
2283
     * Returns the key for this cmnode which is the corresponding XML Schema
2285
		 */
2284
     * node.
2286
		public int getNodeType() {
2285
     * 
2287
			return GROUP;
2286
     * @return the key for this cmnode.
2288
		}
2287
     */
2289
2288
    public Object getKey()
2290
		/**
2289
    {
2291
		 * Returns the key for this cmnode which is the corresponding XML Schema
2290
      return xsdWildcard;
2292
		 * node.
2291
    }
2293
		 * 
2292
2294
		 * @return the key for this cmnode.
2293
    /**
2295
		 */
2294
     * Returns the type of the node. The types are defined in CMNode class
2296
		public Object getKey() {
2295
     * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
2297
			return xsdModelGroup;
2296
     * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
2298
		}
2297
     * DOCUMENTATION).
2299
2298
     * 
2300
		/**
2299
     * @return the type of this node.
2301
		 * Returns a list of the children of this group.
2300
     */
2302
		 * 
2301
    public int getNodeType()
2303
		 * @return a list of the children of this group.
2302
    {
2304
		 */
2303
      return ANY_ELEMENT;
2305
		public CMNodeList getChildNodes() {
2304
    }
2306
			CMNodeListImpl nodeList = new CMNodeListImpl();
2305
2307
			if (xsdModelGroup != null) {
2306
    /**
2308
				for (Iterator i = xsdModelGroup.getParticles().iterator(); i
2307
     * Returns the name of the node. The default value is an empty string value.
2309
						.hasNext();) {
2308
     * All derived classes must override this method if they do not want the
2310
					XSDParticle particle = (XSDParticle) i.next();
2309
     * default value.
2311
					XSDParticleContent content = particle.getContent();
2310
     * 
2312
					CMNode adapter = getAdapter(content);
2311
     * @return the name of the node.
2313
					if (adapter != null) {
2312
     */
2314
						nodeList.getList().add(adapter);
2313
    public String getNodeName()
2315
					}
2314
    {
2316
				}
2315
      return "any";
2317
			}
2316
    }
2318
			return nodeList;
2317
2319
		}
2318
    public String getNamespaceURI()
2320
2319
    {
2321
		/**
2320
      String uri = xsdWildcard.getElement().getAttribute(XSDConstants.NAMESPACE_ATTRIBUTE);
2322
		 * Returns the name of the node. The default value is an empty string
2321
      return (uri != null && uri.length() > 0) ? uri : "##any";
2323
		 * value. All derived classes must override this method if they do not
2322
    }
2324
		 * want the default value.
2323
2325
		 * 
2324
    /**
2326
		 * @return the name of the node.
2325
     * Returns the value of 'Min Occurs' attribute. The default value is "1".
2327
		 */
2326
     * 
2328
		public String getNodeName() {
2327
     * @return the value of the 'Min Occurs' attribute.
2329
			CMDescriptionBuilder descriptionBuilder = new CMDescriptionBuilder();
2328
     */
2330
			return descriptionBuilder.buildDescription(this);
2329
    public int getMinOccur()
2331
		}
2330
    {
2332
2331
      return getMinOccurs(xsdWildcard);
2333
		/**
2332
    }
2334
		 * Returns the value of 'Min Occurs' attribute. The default value is
2333
2335
		 * "1".
2334
    /**
2336
		 * 
2335
     * Returns the value of the 'Max Occurs' attribute. The default value is
2337
		 * @return the value of the 'Min Occurs' attribute.
2336
     * "1".
2338
		 */
2337
     * 
2339
		public int getMinOccur() {
2338
     * @return the value of the 'Max Occurs' attribute.
2340
			return getMinOccurs(xsdModelGroup);
2339
     */
2341
		}
2340
    public int getMaxOccur()
2342
2341
    {
2343
		/**
2342
      return getMaxOccurs(xsdWildcard);
2344
		 * Returns the value of the 'Max Occurs' attribute. The default value is
2343
    }
2345
		 * "1".
2344
2346
		 * 
2345
    /**
2347
		 * @return the value of the 'Max Occurs' attribute.
2346
     * Returns the cmdocument that is the owner of this cmnode.
2348
		 */
2347
     * 
2349
		public int getMaxOccur() {
2348
     * @return the cmdocument corresponding to this cmnode.
2350
			return getMaxOccurs(xsdModelGroup);
2349
     */
2351
		}
2350
    public CMDocument getCMDocument()
2352
2351
    {
2353
		/**
2352
      return (CMDocument) getAdapter(xsdWildcard.getSchema());
2354
		 * Return operator of this group -- CHOICE, SEQUENCE or ALL value.
2353
    }
2355
		 * 
2354
2356
		 * @return the operator of this group.
2355
    /**
2357
		 */
2356
     * Returns a list of documentation elements.
2358
		public int getOperator() {
2357
     * 
2359
			int result = 0;
2358
     * @return a list of documentation elements.
2360
			// todo... handle ALONE case by checkig if child count == 1
2359
     */
2361
			if (xsdModelGroup != null) {
2360
    protected CMNodeList getDocumentation()
2362
				switch (xsdModelGroup.getCompositor().getValue()) {
2361
    {
2363
				case XSDCompositor.CHOICE: {
2362
      XSDAnnotation annotation = xsdWildcard.getAnnotation();
2364
					result = CHOICE;
2363
      return getDocumentations(annotation);
2365
					break;
2364
    }
2366
				}
2365
  }
2367
				case XSDCompositor.SEQUENCE: {
2366
  /**
2368
					result = SEQUENCE;
2367
   * XSDModelGroupAdapter
2369
					break;
2368
   */
2370
				}
2369
  public static class XSDModelGroupAdapter extends XSDBaseAdapter implements CMGroup
2371
				case XSDCompositor.ALL: {
2370
  {
2372
					result = ALL;
2371
    protected XSDModelGroup xsdModelGroup;
2373
					break;
2372
2374
				}
2373
    public XSDModelGroupAdapter()
2375
				}
2374
    {
2376
			}
2375
    }
2377
			return result;
2376
2378
		}
2377
    public XSDModelGroupAdapter(XSDModelGroup xsdModelGroup)
2379
2378
    {
2380
		/**
2379
      this.xsdModelGroup = xsdModelGroup;
2381
		 * Returns a list of documentation elements.
2380
    }
2382
		 * 
2381
2383
		 * @return a list of documentation elements.
2382
    /**
2384
		 */
2383
     * Returns the type of the node. The types are defined in CMNode class
2385
		protected CMNodeList getDocumentation() {
2384
     * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
2386
			XSDAnnotation annotation = xsdModelGroup.getAnnotation();
2385
     * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
2387
			return getDocumentations(annotation);
2386
     * DOCUMENTATION).
2388
		}
2387
     * 
2389
2388
     * @return the type of this node.
2390
		/**
2389
     */
2391
		 * Returns the cmdocument that is the owner of this cmnode.
2390
    public int getNodeType()
2392
		 * 
2391
    {
2393
		 * @return the cmdocument corresponding to this cmnode.
2392
      return GROUP;
2394
		 */
2393
    }
2395
		public CMDocument getCMDocument() {
2394
2396
			return (CMDocument) getAdapter(xsdModelGroup.getSchema());
2395
    /**
2397
		}
2396
     * Returns the key for this cmnode which is the corresponding XML Schema
2398
	}
2397
     * node.
2399
2398
     * 
2400
	/**
2399
     * @return the key for this cmnode.
2401
	 * XSDModelGroupDefinitionAdapter
2400
     */
2402
	 */
2401
    public Object getKey()
2403
	public static class XSDModelGroupDefinitionAdapter extends XSDBaseAdapter
2402
    {
2404
			implements CMGroup {
2403
      return xsdModelGroup;
2405
		protected XSDModelGroupDefinition xsdModelGroupDefinition;
2404
    }
2406
2405
2407
		public XSDModelGroupDefinitionAdapter(
2406
    /**
2408
				XSDModelGroupDefinition xsdModelGroupDefinition) {
2407
     * Returns a list of the children of this group.
2409
			this.xsdModelGroupDefinition = xsdModelGroupDefinition;
2408
     * 
2410
		}
2409
     * @return a list of the children of this group.
2411
2410
     */
2412
		/**
2411
    public CMNodeList getChildNodes()
2413
		 * Returns the type of the node. The types are defined in CMNode class
2412
    {
2414
		 * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
2413
      CMNodeListImpl nodeList = new CMNodeListImpl();
2415
		 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
2414
      if (xsdModelGroup != null)
2416
		 * DOCUMENTATION).
2415
      {
2417
		 * 
2416
        for (Iterator i = xsdModelGroup.getParticles().iterator(); i.hasNext();)
2418
		 * @return the type of this node.
2417
        {
2419
		 */
2418
          XSDParticle particle = (XSDParticle) i.next();
2420
		public int getNodeType() {
2419
          XSDParticleContent content = particle.getContent();
2421
			return GROUP;
2420
          CMNode adapter = getAdapter(content);
2422
		}
2421
          if (adapter != null)
2423
2422
          {
2424
		/**
2423
            nodeList.getList().add(adapter);
2425
		 * Returns the key for this cmnode which is the corresponding XML Schema
2424
          }
2426
		 * node.
2425
        }
2427
		 * 
2426
      }
2428
		 * @return the key for this cmnode.
2427
      return nodeList;
2429
		 */
2428
    }
2430
		public Object getKey() {
2429
2431
			return xsdModelGroupDefinition;
2430
    /**
2432
		}
2431
     * Returns the name of the node. The default value is an empty string value.
2433
2432
     * All derived classes must override this method if they do not want the
2434
		/**
2433
     * default value.
2435
		 * Returns a list of the children of this group.
2434
     * 
2436
		 * 
2435
     * @return the name of the node.
2437
		 * @return a list of the children of this group.
2436
     */
2438
		 */
2437
    public String getNodeName()
2439
		public CMNodeList getChildNodes() {
2438
    {
2440
			CMNodeListImpl nodeList = new CMNodeListImpl();
2439
      CMDescriptionBuilder descriptionBuilder = new CMDescriptionBuilder();
2441
			XSDModelGroup modelGroup = xsdModelGroupDefinition
2440
      return descriptionBuilder.buildDescription(this);
2442
					.getResolvedModelGroupDefinition().getModelGroup();
2441
    }
2443
			if (modelGroup != null) {
2442
2444
				CMNode adapter = getAdapter(modelGroup);
2443
    /**
2445
				nodeList.add(adapter);
2444
     * Returns the value of 'Min Occurs' attribute. The default value is "1".
2446
			}
2445
     * 
2447
			return nodeList;
2446
     * @return the value of the 'Min Occurs' attribute.
2448
		}
2447
     */
2449
2448
    public int getMinOccur()
2450
		/**
2449
    {
2451
		 * Returns the name of the node. The default value is an empty string
2450
      return getMinOccurs(xsdModelGroup);
2452
		 * value. All derived classes must override this method if they do not
2451
    }
2453
		 * want the default value.
2452
2454
		 * 
2453
    /**
2455
		 * @return the name of the node.
2454
     * Returns the value of the 'Max Occurs' attribute. The default value is
2456
		 */
2455
     * "1".
2457
		public String getNodeName() {
2456
     * 
2458
			CMDescriptionBuilder descriptionBuilder = new CMDescriptionBuilder();
2457
     * @return the value of the 'Max Occurs' attribute.
2459
			return descriptionBuilder.buildDescription(this);
2458
     */
2460
		}
2459
    public int getMaxOccur()
2461
2460
    {
2462
		/**
2461
      return getMaxOccurs(xsdModelGroup);
2463
		 * Returns the value of 'Min Occurs' attribute. The default value is
2462
    }
2464
		 * "1".
2463
2465
		 * 
2464
    /**
2466
		 * @return the value of the 'Min Occurs' attribute.
2465
     * Return operator of this group -- CHOICE, SEQUENCE or ALL value.
2467
		 */
2466
     * 
2468
		public int getMinOccur() {
2467
     * @return the operator of this group.
2469
			return getMinOccurs(xsdModelGroupDefinition);
2468
     */
2470
		}
2469
    public int getOperator()
2471
2470
    {
2472
		/**
2471
      int result = 0;
2473
		 * Returns the value of the 'Max Occurs' attribute. The default value is
2472
      //todo... handle ALONE case by checkig if child count == 1
2474
		 * "1".
2473
      if (xsdModelGroup != null)
2475
		 * 
2474
      {
2476
		 * @return the value of the 'Max Occurs' attribute.
2475
        switch (xsdModelGroup.getCompositor().getValue())
2477
		 */
2476
        {
2478
		public int getMaxOccur() {
2477
          case XSDCompositor.CHOICE : {
2479
			return getMaxOccurs(xsdModelGroupDefinition);
2478
            result = CHOICE;
2480
		}
2479
            break;
2481
2480
          }
2482
		/**
2481
          case XSDCompositor.SEQUENCE : {
2483
		 * Return operator of this group -- CHOICE, SEQUENCE or ALL value.
2482
            result = SEQUENCE;
2484
		 * 
2483
            break;
2485
		 * @return the operator of this group.
2484
          }
2486
		 */
2485
          case XSDCompositor.ALL : {
2487
		public int getOperator() {
2486
            result = ALL;
2488
			return XSDCompositor.SEQUENCE;
2487
            break;
2489
		}
2488
          }
2490
2489
        }
2491
		/**
2490
      }
2492
		 * Returns a list of documentation elements.
2491
      return result;
2493
		 * 
2492
    }
2494
		 * @return a list of documentation elements.
2493
2495
		 */
2494
    /**
2496
		protected CMNodeList getDocumentation() {
2495
     * Returns a list of documentation elements.
2497
			XSDAnnotation annotation = xsdModelGroupDefinition.getAnnotation();
2496
     * 
2498
			return getDocumentations(annotation);
2497
     * @return a list of documentation elements.
2499
		}
2498
     */
2500
2499
    protected CMNodeList getDocumentation()
2501
		/**
2500
    {
2502
		 * Returns the cmdocument that is the owner of this cmnode.
2501
      XSDAnnotation annotation = xsdModelGroup.getAnnotation();
2503
		 * 
2502
      return getDocumentations(annotation);
2504
		 * @return the cmdocument corresponding to this cmnode.
2503
    }
2505
		 */
2504
2506
		public CMDocument getCMDocument() {
2505
    /**
2507
			return (CMDocument) getAdapter(xsdModelGroupDefinition.getSchema());
2506
     * Returns the cmdocument that is the owner of this cmnode.
2508
		}
2507
     * 
2509
	}
2508
     * @return the cmdocument corresponding to this cmnode.
2510
2509
     */
2511
	/**
2510
    public CMDocument getCMDocument()
2512
	 * DocumentationImpl implements CMDocumentation. A representation of the
2511
    {
2513
	 * documentation element part of the 'User Information' feature. Working
2512
      return (CMDocument) getAdapter(xsdModelGroup.getSchema());
2514
	 * with the documentation element requires dropping down into the DOM model.
2513
    }
2515
	 */
2514
  }
2516
	public static class DocumentationImpl implements CMDocumentation {
2515
  /**
2517
		protected Element documentation;
2516
   * XSDModelGroupDefinitionAdapter
2518
2517
   */
2519
		/**
2518
  public static class XSDModelGroupDefinitionAdapter extends XSDBaseAdapter implements CMGroup
2520
		 * Constructor.
2519
  {
2521
		 * 
2520
    protected XSDModelGroupDefinition xsdModelGroupDefinition;
2522
		 * @param documentation -
2521
2523
		 *            a documentation element.
2522
    public XSDModelGroupDefinitionAdapter(XSDModelGroupDefinition xsdModelGroupDefinition)
2524
		 */
2523
    {
2525
		public DocumentationImpl(Element documentation) {
2524
      this.xsdModelGroupDefinition = xsdModelGroupDefinition;
2526
			this.documentation = documentation;
2525
    }
2527
		}
2526
2528
2527
    /**
2529
		/**
2528
     * Returns the type of the node. The types are defined in CMNode class
2530
		 * Returns the type of the node. The types are defined in CMNode class
2529
     * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
2531
		 * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
2530
     * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
2532
		 * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
2531
     * DOCUMENTATION).
2533
		 * DOCUMENTATION).
2532
     * 
2534
		 * 
2533
     * @return the type of this node.
2535
		 * @return the type of this node.
2534
     */
2536
		 */
2535
    public int getNodeType()
2537
		public int getNodeType() {
2536
    {
2538
			return DOCUMENTATION;
2537
      return GROUP;
2539
		}
2538
    }
2540
2539
2541
		/**
2540
    /**
2542
		 * Returns an empty string value.
2541
     * Returns the key for this cmnode which is the corresponding XML Schema
2543
		 * 
2542
     * node.
2544
		 * @return an empty string value.
2543
     * 
2545
		 */
2544
     * @return the key for this cmnode.
2546
		public String getNodeName() {
2545
     */
2547
			return "";
2546
    public Object getKey()
2548
		}
2547
    {
2549
2548
      return xsdModelGroupDefinition;
2550
		/**
2549
    }
2551
		 * Returns false. This class does not support any properties.
2550
2552
		 * 
2551
    /**
2553
		 * @param propertyName -
2552
     * Returns a list of the children of this group.
2554
		 *            name of a property
2553
     * 
2555
		 * @return false.
2554
     * @return a list of the children of this group.
2556
		 */
2555
     */
2557
		public boolean supports(String propertyName) {
2556
    public CMNodeList getChildNodes()
2558
			return false;
2557
    {
2559
		}
2558
      CMNodeListImpl nodeList = new CMNodeListImpl();
2560
2559
      XSDModelGroup modelGroup = xsdModelGroupDefinition.getResolvedModelGroupDefinition().getModelGroup();
2561
		/**
2560
      if (modelGroup != null)
2562
		 * Returns null. This class does not support any properties.
2561
      {
2563
		 * 
2562
        CMNode adapter = getAdapter(modelGroup);
2564
		 * @param propertyName -
2563
        nodeList.add(adapter);
2565
		 *            name of a property
2564
      }
2566
		 * @return null.
2565
      return nodeList;
2567
		 */
2566
    }
2568
		public Object getProperty(String propertyName) {
2567
2569
			return null;
2568
    /**
2570
		}
2569
     * Returns the name of the node. The default value is an empty string value.
2571
2570
     * All derived classes must override this method if they do not want the
2572
		/**
2571
     * default value.
2573
		 * Returns the content of the documentation element.
2572
     * 
2574
		 * 
2573
     * @return the name of the node.
2575
		 * @return the content of the documentation element.
2574
     */
2576
		 */
2575
    public String getNodeName()
2577
		public String getValue() {
2576
    {
2578
			String content = "";
2577
      CMDescriptionBuilder descriptionBuilder = new CMDescriptionBuilder();
2579
			boolean contentFound = false;
2578
      return descriptionBuilder.buildDescription(this);
2580
			NodeList nodes = documentation.getChildNodes();
2579
    }
2581
			for (int i = 0; i < nodes.getLength(); i++) {
2580
2582
				Node node = nodes.item(i);
2581
    /**
2583
				if (node instanceof Text) {
2582
     * Returns the value of 'Min Occurs' attribute. The default value is "1".
2584
					contentFound = true;
2583
     * 
2585
					content += node.getNodeValue();
2584
     * @return the value of the 'Min Occurs' attribute.
2586
				}
2585
     */
2587
			}
2586
    public int getMinOccur()
2588
			return contentFound ? content : null;
2587
    {
2589
		}
2588
      return getMinOccurs(xsdModelGroupDefinition);
2590
2589
    }
2591
		/**
2590
2592
		 * Returns the xml:lang attribute value of the documentation element.
2591
    /**
2593
		 * 
2592
     * Returns the value of the 'Max Occurs' attribute. The default value is
2594
		 * @return the xml:lang attribute value of the documentation element.
2593
     * "1".
2595
		 */
2594
     * 
2596
		public String getLanguage() {
2595
     * @return the value of the 'Max Occurs' attribute.
2597
			return documentation.hasAttributeNS(
2596
     */
2598
					XSDConstants.XML_NAMESPACE_URI_1998, XML_LANG_ATTRIBUTE) ? documentation
2597
    public int getMaxOccur()
2599
					.getAttributeNS(XSDConstants.XML_NAMESPACE_URI_1998,
2598
    {
2600
							XML_LANG_ATTRIBUTE)
2599
      return getMaxOccurs(xsdModelGroupDefinition);
2601
					: null;
2600
    }
2602
		}
2601
2603
2602
    /**
2604
		/**
2603
     * Return operator of this group -- CHOICE, SEQUENCE or ALL value.
2605
		 * Returns the source attribute value of the documentation element.
2604
     * 
2606
		 * 
2605
     * @return the operator of this group.
2607
		 * @return the source attribute value of the documentation element.
2606
     */
2608
		 */
2607
    public int getOperator()
2609
		public String getSource() {
2608
    {
2610
			return documentation.hasAttributeNS(null,
2609
      return XSDCompositor.SEQUENCE;
2611
					XSDConstants.SOURCE_ATTRIBUTE) ? documentation
2610
    }
2612
					.getAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) : null;
2611
2613
		}
2612
    /**
2614
	}
2613
     * Returns a list of documentation elements.
2615
2614
     * 
2616
	/**
2615
     * @return a list of documentation elements.
2617
	 * XSIDocument extends CMDocumentImpl. This class is used to hold those
2616
     */
2618
	 * attributes that are for direct use in any XML documents. These attributes
2617
    protected CMNodeList getDocumentation()
2619
	 * are in a different namespace, which has the namespace name
2618
    {
2620
	 * http://www.w3.org/2001/XMLSchema-instance. Attributes in this namespace
2619
      XSDAnnotation annotation = xsdModelGroupDefinition.getAnnotation();
2621
	 * include: xsi:type xsi:nil xsi:schemaLocation
2620
      return getDocumentations(annotation);
2622
	 * xsi:noNamespaceSchemaLocation
2621
    }
2623
	 */
2622
2624
	public static class XSIDocument extends CMDocumentImpl {
2623
    /**
2625
		public CMAttributeDeclarationImpl nilAttribute;
2624
     * Returns the cmdocument that is the owner of this cmnode.
2626
2625
     * 
2627
		/**
2626
     * @return the cmdocument corresponding to this cmnode.
2628
		 * Constructor. Creates the 'xsi:nil'
2627
     */
2629
		 */
2628
    public CMDocument getCMDocument()
2630
		public XSIDocument() {
2629
    {
2631
			super(XSDConstants.SCHEMA_INSTANCE_URI_2001);
2630
      return (CMDocument) getAdapter(xsdModelGroupDefinition.getSchema());
2632
			// create the 'nill' attribute
2631
    }
2633
			String[] values = { "false", "true" };
2632
  }
2634
			nilAttribute = new CMAttributeDeclarationImpl("nil",
2633
  /**
2635
					CMAttributeDeclaration.REQUIRED, new CMDataTypeImpl(
2634
   * DocumentationImpl implements CMDocumentation. A representation of the
2636
							"boolean", values));
2635
   * documentation element part of the 'User Information' feature. Working with
2637
			nilAttribute.setPrefixQualification(true);
2636
   * the documentation element requires dropping down into the DOM model.
2638
			nilAttribute.setCMDocument(this);
2637
   */
2639
		}
2638
  public static class DocumentationImpl implements CMDocumentation
2640
	}
2639
  {
2641
2640
    protected Element documentation;
2642
	/**
2641
2643
	 * Note this XSD model visitor differs from the XSD model visitor in
2642
    /**
2644
	 * org.eclipse.wst.xsd.editor plugin. In visitModelGroup method we call
2643
     * Constructor.
2645
	 * getParticles() instead of getContents(). This gathers all of the content
2644
     * 
2646
	 * of a derived type.
2645
     * @param documentation -
2647
	 */
2646
     *          a documentation element.
2648
	public static class XSDCMVisitor extends XSDVisitor {
2647
     */
2649
		public void visitSimpleTypeDefinition(XSDSimpleTypeDefinition type) {
2648
    public DocumentationImpl(Element documentation)
2650
			XSDParticle ctd = type.getComplexType();
2649
    {
2651
			if (ctd != null)
2650
      this.documentation = documentation;
2652
				visitParticle(ctd);
2651
    }
2653
		}
2652
2654
2653
    /**
2655
		public void visitModelGroup(XSDModelGroup modelGroup) {
2654
     * Returns the type of the node. The types are defined in CMNode class
2656
			if (modelGroup.getParticles() != null) {
2655
     * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
2657
				for (Iterator iterator = modelGroup.getParticles().iterator(); iterator
2656
     * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
2658
						.hasNext();) {
2657
     * DOCUMENTATION).
2659
					XSDParticle particle = (XSDParticle) iterator.next();
2658
     * 
2660
					visitParticle(particle);
2659
     * @return the type of this node.
2661
				}
2660
     */
2662
			}
2661
    public int getNodeType()
2663
		}
2662
    {
2664
2663
      return DOCUMENTATION;
2665
		public void visitModelGroupDefinition(
2664
    }
2666
				XSDModelGroupDefinition modelGroupDef) {
2665
2667
			XSDModelGroup modelGroup = modelGroupDef
2666
    /**
2668
					.getResolvedModelGroupDefinition().getModelGroup();
2667
     * Returns an empty string value.
2669
			if (modelGroup != null) {
2668
     * 
2670
				visitModelGroup(modelGroup);
2669
     * @return an empty string value.
2671
			}
2670
     */
2672
		}
2671
    public String getNodeName()
2673
	}
2672
    {
2674
2673
      return "";
2675
	/**
2674
    }
2676
	 * A visitor class that walks the xsd model and computes the list of
2675
2677
	 * children that belong to the initially visited element type.
2676
    /**
2678
	 */
2677
     * Returns false. This class does not support any properties.
2679
	public static class DerivedChildVisitor extends XSDCMVisitor {
2678
     * 
2680
		protected CMNodeListImpl childNodeList = new CMNodeListImpl();
2679
     * @param propertyName -
2681
2680
     *          name of a property
2682
		protected List baseTypeList = new Vector();
2681
     * @return false.
2683
2682
     */
2684
		Object root;
2683
    public boolean supports(String propertyName)
2685
2684
    {
2686
		DerivedChildVisitor(Object root) {
2685
      return false;
2687
			this.root = root;
2686
    }
2688
		}
2687
2689
2688
    /**
2690
		public CMNodeListImpl getChildNodeList() {
2689
     * Returns null. This class does not support any properties.
2691
			return childNodeList;
2690
     * 
2692
		}
2691
     * @param propertyName -
2693
2692
     *          name of a property
2694
		public void visitWildcard(XSDWildcard wildcard) {
2693
     * @return null.
2695
			childNodeList.getList().add(getAdapter(wildcard));
2694
     */
2696
		}
2695
    public Object getProperty(String propertyName)
2697
2696
    {
2698
		public void visitElementDeclaration(XSDElementDeclaration element) {
2697
      return null;
2699
			childNodeList.getList().add(getAdapter(element));
2698
    }
2700
		}
2699
2701
2700
    /**
2702
		public void visitModelGroup(XSDModelGroup modelGroup) {
2701
     * Returns the content of the documentation element.
2703
			childNodeList.getList().add(getAdapter(modelGroup));
2702
     * 
2704
		}
2703
     * @return the content of the documentation element.
2705
2704
     */
2706
		public void visitModelGroupDefinition(
2705
    public String getValue()
2707
				XSDModelGroupDefinition modelGroupDefinition) {
2706
    {
2708
			childNodeList.getList().add(getAdapter(modelGroupDefinition));
2707
      String content = "";
2709
		}
2708
      boolean contentFound = false;
2710
	}
2709
      NodeList nodes = documentation.getChildNodes();
2711
2710
      for (int i = 0; i < nodes.getLength(); i++)
2712
	/**
2711
      {
2713
	 * A visitor class that gathers all of the elements within a type
2712
        Node node = nodes.item(i);
2714
	 * definition.
2713
        if (node instanceof Text)
2715
	 */
2714
        {
2716
	public static class LocalElementVisitor extends XSDCMVisitor {
2715
          contentFound = true;
2717
		protected CMNamedNodeMapImpl namedNodeMap = new CMNamedNodeMapImpl();
2716
          content += node.getNodeValue();
2718
2717
        }
2719
		protected List baseTypeList = new Vector();
2718
      }
2720
2719
      return contentFound ? content : null;
2721
		public void visitElementDeclaration(XSDElementDeclaration element) {
2720
    }
2722
			XSDElementDeclarationAdapter adapter = (XSDElementDeclarationAdapter) getAdapter(element);
2721
2723
			namedNodeMap.getHashtable().put(adapter.getNodeName(), adapter);
2722
    /**
2724
		}
2723
     * Returns the xml:lang attribute value of the documentation element.
2725
2724
     * 
2726
		public CMNamedNodeMap getCMNamedNodeMap() {
2725
     * @return the xml:lang attribute value of the documentation element.
2727
			return namedNodeMap;
2726
     */
2728
		}
2727
    public String getLanguage()
2729
	}
2728
    {
2729
      return documentation.hasAttributeNS(XSDConstants.XML_NAMESPACE_URI_1998, XML_LANG_ATTRIBUTE) ? documentation.getAttributeNS(XSDConstants.XML_NAMESPACE_URI_1998, XML_LANG_ATTRIBUTE) : null;
2730
    }
2731
2732
    /**
2733
     * Returns the source attribute value of the documentation element.
2734
     * 
2735
     * @return the source attribute value of the documentation element.
2736
     */
2737
    public String getSource()
2738
    {
2739
      return documentation.hasAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) ? documentation.getAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) : null;
2740
    }
2741
  }
2742
  /**
2743
   * XSIDocument extends CMDocumentImpl. This class is used to hold those
2744
   * attributes that are for direct use in any XML documents. These attributes
2745
   * are in a different namespace, which has the namespace name
2746
   * http://www.w3.org/2001/XMLSchema-instance. Attributes in this namespace
2747
   * include: xsi:type xsi:nil xsi:schemaLocation xsi:noNamespaceSchemaLocation
2748
   */
2749
  public static class XSIDocument extends CMDocumentImpl
2750
  {
2751
    public CMAttributeDeclarationImpl nilAttribute;
2752
2753
    /**
2754
     * Constructor. Creates the 'xsi:nil'
2755
     */
2756
    public XSIDocument()
2757
    {
2758
      super(XSDConstants.SCHEMA_INSTANCE_URI_2001);
2759
      // create the 'nill' attribute
2760
      String[] values = {"false", "true"};
2761
      nilAttribute = new CMAttributeDeclarationImpl("nil", CMAttributeDeclaration.REQUIRED, new CMDataTypeImpl("boolean", values));
2762
      nilAttribute.setPrefixQualification(true);
2763
      nilAttribute.setCMDocument(this);
2764
    }
2765
  }
2766
  /**
2767
   * Note this XSD model visitor differs from the XSD model visitor in
2768
   * org.eclipse.wst.xsd.editor plugin. In visitModelGroup method we call
2769
   * getParticles() instead of getContents(). This gathers all of the content of
2770
   * a derived type.
2771
   */
2772
  public static class XSDCMVisitor extends XSDVisitor
2773
  {
2774
    public void visitSimpleTypeDefinition(XSDSimpleTypeDefinition type)
2775
    {
2776
      XSDParticle ctd = type.getComplexType();
2777
      if (ctd != null)
2778
        visitParticle(ctd);
2779
    }
2780
2781
    public void visitModelGroup(XSDModelGroup modelGroup)
2782
    {
2783
      if (modelGroup.getParticles() != null)
2784
      {
2785
        for (Iterator iterator = modelGroup.getParticles().iterator(); iterator.hasNext();)
2786
        {
2787
          XSDParticle particle = (XSDParticle) iterator.next();
2788
          visitParticle(particle);
2789
        }
2790
      }
2791
    }
2792
2793
    public void visitModelGroupDefinition(XSDModelGroupDefinition modelGroupDef)
2794
    {
2795
      XSDModelGroup modelGroup = modelGroupDef.getResolvedModelGroupDefinition().getModelGroup();
2796
      if (modelGroup != null)
2797
      {
2798
        visitModelGroup(modelGroup);
2799
      }
2800
    }
2801
  }
2802
  /**
2803
   * A visitor class that walks the xsd model and computes the list of children
2804
   * that belong to the initially visited element type.
2805
   */
2806
  public static class DerivedChildVisitor extends XSDCMVisitor
2807
  {
2808
    protected CMNodeListImpl childNodeList = new CMNodeListImpl();
2809
    protected List baseTypeList = new Vector();
2810
    Object root;
2811
2812
    DerivedChildVisitor(Object root)
2813
    {
2814
      this.root = root;
2815
    }
2816
2817
    public CMNodeListImpl getChildNodeList()
2818
    {
2819
      return childNodeList;
2820
    }
2821
2822
    public void visitWildcard(XSDWildcard wildcard)
2823
    {
2824
      childNodeList.getList().add(getAdapter(wildcard));
2825
    }
2826
2827
    public void visitElementDeclaration(XSDElementDeclaration element)
2828
    {
2829
      childNodeList.getList().add(getAdapter(element));
2830
    }
2831
2832
    public void visitModelGroup(XSDModelGroup modelGroup)
2833
    {
2834
      childNodeList.getList().add(getAdapter(modelGroup));
2835
    }
2836
2837
    public void visitModelGroupDefinition(XSDModelGroupDefinition modelGroupDefinition)
2838
    {
2839
      childNodeList.getList().add(getAdapter(modelGroupDefinition));
2840
    }
2841
  }
2842
  /**
2843
   * A visitor class that gathers all of the elements within a type definition.
2844
   */
2845
  public static class LocalElementVisitor extends XSDCMVisitor
2846
  {
2847
    protected CMNamedNodeMapImpl namedNodeMap = new CMNamedNodeMapImpl();
2848
    protected List baseTypeList = new Vector();
2849
2850
    public void visitElementDeclaration(XSDElementDeclaration element)
2851
    {
2852
      XSDElementDeclarationAdapter adapter = (XSDElementDeclarationAdapter) getAdapter(element);
2853
      namedNodeMap.getHashtable().put(adapter.getNodeName(), adapter);
2854
    }
2855
2856
    public CMNamedNodeMap getCMNamedNodeMap()
2857
    {
2858
      return namedNodeMap;
2859
    }
2860
  }
2861
}
2730
}

Return to bug 176416