[88588] Merge org.eclipse.wst.xsd.contentmodel and org.eclipse.wst.xsd.validation into org.eclipse.wst.xsd.core
diff --git a/bundles/org.eclipse.wst.xsd.core/.classpath b/bundles/org.eclipse.wst.xsd.core/.classpath
new file mode 100644
index 0000000..25c68fd
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/.classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src-contentmodel/"/>
+ <classpathentry kind="src" path="src-validation/"/>
+ <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/org.eclipse.wst.xsd.core/.cvsignore b/bundles/org.eclipse.wst.xsd.core/.cvsignore
new file mode 100644
index 0000000..e4254b1
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/.cvsignore
@@ -0,0 +1,3 @@
+bin
+temp.folder
+build.xml
diff --git a/bundles/org.eclipse.wst.xsd.core/.project b/bundles/org.eclipse.wst.xsd.core/.project
new file mode 100644
index 0000000..a95f8ef
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.xsd.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/bundles/org.eclipse.wst.xsd.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.xsd.core/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..18deb88
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/META-INF/MANIFEST.MF
@@ -0,0 +1,27 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %_UI_PLUGIN_NAME
+Bundle-SymbolicName: org.eclipse.wst.xsd.core; singleton:=true
+Bundle-Version: 0.7.0
+Bundle-Activator: org.eclipse.wst.xsd.core.internal.XSDCorePlugin
+Bundle-Vendor: Eclipse.org
+Bundle-Localization: plugin
+Export-Package: org.eclipse.wst.xsd.contentmodel.internal,
+ org.eclipse.wst.xsd.contentmodel.internal.util,
+ org.eclipse.wst.xsd.core.internal,
+ org.eclipse.wst.xsd.validation.internal,
+ org.eclipse.wst.xsd.validation.internal.ui.eclipse
+Require-Bundle: org.eclipse.core.runtime.compatibility,
+ org.eclipse.emf.ecore,
+ org.eclipse.wst.common.uriresolver,
+ org.eclipse.xsd,
+ org.eclipse.wst.xml.core,
+ org.eclipse.wst.sse.core,
+ org.eclipse.core.resources,
+ org.eclipse.ui,
+ org.eclipse.wst.validation,
+ org.eclipse.wst.xml.validation,
+ org.apache.xerces
+Eclipse-AutoStart: true
+Plugin-Class: org.eclipse.wst.xsd.core.internal.XSDCorePlugin
+
diff --git a/bundles/org.eclipse.wst.xsd.core/build.properties b/bundles/org.eclipse.wst.xsd.core/build.properties
new file mode 100644
index 0000000..c2462f1
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/build.properties
@@ -0,0 +1,22 @@
+###############################################################################
+# Copyright (c) 2001, 2004 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+# Jens Lukowski/Innoopract - initial renaming/restructuring
+#
+###############################################################################
+bin.includes = META-INF/,\
+ plugin.xml,\
+ plugin.properties,\
+ .
+jars.compile.order = .
+src.includes = build.properties
+output.. = bin/
+source.. = src-contentmodel/,\
+ src-validation/,\
+ src/
diff --git a/bundles/org.eclipse.wst.xsd.core/plugin.properties b/bundles/org.eclipse.wst.xsd.core/plugin.properties
new file mode 100644
index 0000000..ad5dd7e
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/plugin.properties
@@ -0,0 +1,35 @@
+###############################################################################
+# Copyright (c) 2001, 2004 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+! Properties file for component: XML Schema Validator
+
+!
+! Plugin
+!
+_UI_PLUGIN_NAME = XSD Core Plugin
+
+!
+! XSDEditor Menu bar contributor
+!
+
+_UI_MENU_VALIDATE_XML = &Validate XML Schema
+
+!
+! Validate Schema
+!
+_UI_DIALOG_XML_SCHEMA_INVALID_TITLE = Validation Failed
+_UI_DIALOG_XML_SCHEMA_VALID_TITLE = Validation Succeeded
+_UI_DIALOG_XML_SCHEMA_VALID_TEXT = The XML schema file is valid.
+_UI_DIALOG_XML_SCHEMA_VALID_WITH_WARNINGS = The XML schema file is valid however warnings have been issued. See the Problems view for the warning messages.
+_UI_DIALOG_XML_SCHEMA_INVALID_TEXT = The XML schema file is not valid. See the Problems view for the error messages.
+_UI_DIALOG_XML_SCHEMA_LIMITE_EXCEEDED = The XML schema file is not valid. The message limit for the Problems view has been exceeded. To see all the messages increase the limit and validate again.
+
+
+_UI_XML_SCHEMA_VALIDATOR = XML Schema Validator
diff --git a/bundles/org.eclipse.wst.xsd.core/plugin.xml b/bundles/org.eclipse.wst.xsd.core/plugin.xml
new file mode 100644
index 0000000..16979c6
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/plugin.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+ <extension point="org.eclipse.core.runtime.contentTypes">
+ <content-type
+ priority="high"
+ name="XSD Content Type "
+ id="xsdsource"
+ base-type="org.eclipse.core.runtime.xml"
+ default-charset="UTF-8"
+ file-extensions="xsd" />
+ </extension>
+
+ <extension point="org.eclipse.wst.xml.core.documentFactories">
+ <factory
+ type="xsd"
+ class="org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD">
+ </factory>
+ </extension>
+
+ <!-- ====================================================== -->
+ <!-- Define Assign Validate action on .xsd file -->
+ <!-- ====================================================== -->
+ <extension point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ objectClass="org.eclipse.core.resources.IFile"
+ nameFilter="*.xsd"
+ id="org.eclipse.wst.xsd.validation.xsdvalidationaction">
+ <action
+ label="%_UI_MENU_VALIDATE_XML"
+ class="org.eclipse.wst.xsd.validation.internal.ui.eclipse.ValidateSchemaActionDelegate"
+ enablesFor="1"
+ id="org.eclipse.wst.xsd.validation.internal.ui.eclipse.ValidateSchemaActionDelegate">
+ </action>
+ </objectContribution>
+ </extension>
+
+ <!-- ====================================================== -->
+ <!-- Register the XSD validator with the validation -->
+ <!-- framework. -->
+ <!-- ====================================================== -->
+ <extension
+ id="xsdValidator"
+ name="%_UI_XML_SCHEMA_VALIDATOR"
+ point="org.eclipse.wst.validation.validator">
+ <validator>
+ <filter
+ objectClass="org.eclipse.core.resources.IFile"
+ caseSensitive="false"
+ nameFilter="*.xsd">
+ </filter>
+ <helper
+ class="org.eclipse.wst.xml.validation.internal.core.Helper">
+ </helper>
+ <run
+ class="org.eclipse.wst.xsd.validation.internal.ui.eclipse.Validator">
+ </run>
+ </validator>
+ </extension>
+
+</plugin>
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentEncodingHelper.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentEncodingHelper.java
new file mode 100644
index 0000000..213a919
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentEncodingHelper.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.wst.sse.core.internal.encoding.EncodingHelper;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
+
+public class CMDocumentEncodingHelper
+{
+ protected static void setEncodingInfo(CMDocument cmDocument, String uri)
+ {
+ if (cmDocument != null)
+ {
+ uri = addImpliedFileProtocol(uri);
+ InputStream inputStream = null;
+ try
+ {
+ URL url = new URL(uri);
+ inputStream = url.openStream();
+ String[] encodingInfo = (String[])cmDocument.getProperty("encodingInfo");
+ if (encodingInfo != null)
+ {
+ //if (Display.getCurrent() != null)
+ //{
+ updateFromEncodingHelper(inputStream, encodingInfo);
+ //}
+ //else
+ // {
+ // encodingInfo[0] = "UTF8";
+ // encodingInfo[1] = "UTF-8";
+ // }
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ finally
+ {
+ if (inputStream != null)
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ private static void updateFromEncodingHelper(InputStream iStream, String[] encodingInfo)
+ {
+ EncodingHelper encodingHelper = new EncodingHelper(iStream);
+ encodingInfo[0] = encodingHelper.getEncoding() != null ? encodingHelper.getEncoding() : EncodingHelper.getDefaultEncoding();
+ encodingInfo[1] = encodingHelper.getEncodingTag() != null ? encodingHelper.getEncodingTag() : EncodingHelper.getDefaultEncodingTag();
+ }
+
+
+ // This code is taken from org.eclipse.wst.xml.uriresolver.util.URIHelper
+ // I didn't want to add this plugin as a dependency this plugin
+ // in order to simplify our xerces dependenies
+ protected static final String FILE_PROTOCOL = "file:";
+ protected static final String PROTOCOL_PATTERN = ":";
+
+ public static String addImpliedFileProtocol(String uri)
+ {
+ if (!hasProtocol(uri))
+ {
+ uri = FILE_PROTOCOL + uri;
+ }
+ return uri;
+ }
+
+ public static boolean hasProtocol(String uri)
+ {
+ boolean result = false;
+ if (uri != null)
+ {
+ int index = uri.indexOf(PROTOCOL_PATTERN);
+ if (index != -1 && index > 2) // assume protocol with be length 3 so that the'C' in 'C:/' is not interpreted as a protocol
+ {
+ result = true;
+ }
+ }
+ return result;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentFactoryXSD.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentFactoryXSD.java
new file mode 100644
index 0000000..bbc9a8f
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentFactoryXSD.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal;
+
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
+import org.eclipse.wst.xml.core.internal.contentmodel.factory.CMDocumentFactory;
+
+/**
+ * This builder handles building .dtd / .xsd grammar files
+ */
+public class CMDocumentFactoryXSD implements CMDocumentFactory
+{
+ public static final String XSD_FILE_TYPE = "XSD";
+
+ public CMDocumentFactoryXSD()
+ {
+ // here we call init on the XSD and DTD packages to avoid strange initialization bugs
+ //
+ org.eclipse.xsd.impl.XSDPackageImpl.init();
+ org.eclipse.xsd.impl.XSDPackageImpl.eINSTANCE.getXSDFactory();
+ }
+
+
+ public CMDocument createCMDocument(String uri)
+ {
+ // work around a bug in our parsers
+ // todo... revist this
+ //
+ String fileProtocol = "file:";
+ if (uri.startsWith(fileProtocol))
+ {
+ uri = uri.substring(fileProtocol.length());
+ }
+
+ // work around a VAJava bug
+ // todo... revist this
+ //
+ String valoaderProtocol = "valoader:/";
+ if (uri.startsWith(valoaderProtocol))
+ {
+ uri = uri.substring(valoaderProtocol.length());
+ }
+
+ // TODO... separate DTD/XSD into separate factories
+ // remove this resourceType variable
+ String resourceType = null;
+
+
+ CMDocument result = null;
+ try
+ {
+ result = XSDImpl.buildCMDocument(uri);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return result;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMNodeImpl.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMNodeImpl.java
new file mode 100644
index 0000000..18fff5a
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMNodeImpl.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal;
+
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
+
+public abstract class CMNodeImpl extends AdapterImpl implements CMNode
+{
+ protected static final String PROPERTY_DOCUMENTATION = "documentation";
+ protected static final String PROPERTY_DOCUMENTATION_SOURCE = "documentationSource";
+ protected static final String PROPERTY_DOCUMENTATION_LANGUAGE = "documentationLanguage";
+ protected static final String PROPERTY_MOF_NOTIFIER = "key";
+ protected static final String PROPERTY_DEFINITION_INFO = "http://org.eclipse.wst/cm/properties/definitionInfo";
+ protected static final String PROPERTY_DEFINITION = "http://org.eclipse.wst/cm/properties/definition";
+
+ public abstract Object getKey();
+
+ public boolean supports(String propertyName)
+ {
+ return propertyName.equals(PROPERTY_MOF_NOTIFIER);
+ }
+
+ public Object getProperty(String propertyName)
+ {
+ return null;
+ }
+
+ public void setProperty(String propertyName, Object object)
+ {
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDCMManager.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDCMManager.java
new file mode 100644
index 0000000..796f45c
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDCMManager.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Plugin;
+
+public class XSDCMManager extends Plugin
+{
+ private static XSDCMManager instance;
+
+ public XSDCMManager()
+ {
+ super();
+ }
+
+ public static XSDCMManager getInstance() {
+ if (instance == null) {
+ instance = new XSDCMManager();
+ }
+ return instance;
+ }
+
+
+ public void startup() throws CoreException
+ {
+ XSDTypeUtil.initialize();
+ //ContentModelManager.getInstance().setInferredGrammarFactory(new InferredGrammarFactoryImpl());
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java
new file mode 100644
index 0000000..2ef86d2
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java
@@ -0,0 +1,2844 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.resource.impl.URIConverterImpl;
+import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMContent;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocumentation;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNamespace;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList;
+import org.eclipse.wst.xml.core.internal.contentmodel.annotation.AnnotationMap;
+import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMAttributeDeclarationImpl;
+import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMDataTypeImpl;
+import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMDocumentImpl;
+import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMEntityDeclarationImpl;
+import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMGroupImpl;
+import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl;
+import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNodeListImpl;
+import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder;
+import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo;
+import org.eclipse.wst.xsd.contentmodel.internal.util.XSDSchemaLocatorAdapterFactory;
+import org.eclipse.xsd.XSDAnnotation;
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDAttributeUse;
+import org.eclipse.xsd.XSDAttributeUseCategory;
+import org.eclipse.xsd.XSDComplexTypeDefinition;
+import org.eclipse.xsd.XSDCompositor;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDConstraint;
+import org.eclipse.xsd.XSDContentTypeCategory;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDEnumerationFacet;
+import org.eclipse.xsd.XSDForm;
+import org.eclipse.xsd.XSDImport;
+import org.eclipse.xsd.XSDModelGroup;
+import org.eclipse.xsd.XSDModelGroupDefinition;
+import org.eclipse.xsd.XSDParticle;
+import org.eclipse.xsd.XSDParticleContent;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDSchemaContent;
+import org.eclipse.xsd.XSDSimpleTypeDefinition;
+import org.eclipse.xsd.XSDTypeDefinition;
+import org.eclipse.xsd.XSDWildcard;
+import org.eclipse.xsd.impl.XSDSchemaImpl;
+import org.eclipse.xsd.util.XSDConstants;
+import org.eclipse.xsd.util.XSDResourceImpl;
+import org.eclipse.xsd.util.XSDSwitch;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * Utility class to build cmnodes from XML Schema nodes. The XML Schema model is
+ * found in the org.eclipse.xsd plugin.
+ *
+ * TODO: getNamespaceURI()currently always returns '##any'.
+ */
+public class XSDImpl
+{
+ /*
+ * properties common to all cmnodes the following properties defined in
+ * CMNodeImpl class: PROPERTY_DOCUMENTATION PROPERTY_DOCUMENTATION_SOURCE
+ * PROPERTY_DOCUMENTATION_LANGUAGE PROPERTY_MOF_NOTIFIER
+ * PROPERTY_DEFINITION_INFO PROPERTY_DEFINITION
+ *
+ * the following properties defined in this class, XSDImpl:
+ * PROPERTY_CMDOCUMENT PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS
+ * PROPERTY_IS_NAME_SPACE_AWARE PROPERTY_NS_PREFIX_QUALIFICATION
+ * PROPERTY_NILLABLE PROPERTY_SPEC
+ */
+ public static final String PROPERTY_CMDOCUMENT = "CMDocument";
+ public static final String PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS = "http://org.eclipse.wst/cm/properties/usesLocalElementDeclarations";
+ public static final String PROPERTY_IS_NAME_SPACE_AWARE = "http://org.eclipse.wst/cm/properties/isNameSpaceAware";
+ public static final String PROPERTY_NS_PREFIX_QUALIFICATION = "http://org.eclipse.wst/cm/properties/nsPrefixQualification";
+ public static final String PROPERTY_NILLABLE = "http://org.eclipse.wst/cm/properties/nillable";
+ public static final String PROPERTY_SPEC = "spec";
+ /*
+ * properties common to all CMDocument nodes: PROPERTY_TARGET_NAMESPACE_URI
+ * PROPERTY_IMPORTED_NAMESPACE_INFO PROPERTY_NAMESPACE_INFO
+ * PROPERTY_ELEMENT_FORM_DEFAULT PROPERTY_ANNOTATION_MAP
+ * PROPERTY_ENCODING_INFO
+ */
+ public static final String PROPERTY_TARGET_NAMESPACE_URI = "http://org.eclipse.wst/cm/properties/targetNamespaceURI";
+ public static final String PROPERTY_IMPORTED_NAMESPACE_INFO = "http://org.eclipse.wst/cm/properties/importedNamespaceInfo";
+ public static final String PROPERTY_NAMESPACE_INFO = "http://org.eclipse.wst/cm/properties/namespaceInfo";
+ public static final String PROPERTY_ELEMENT_FORM_DEFAULT = "http://org.eclipse.wst/cm/properties/elementFormDefault";
+ public static final String PROPERTY_ANNOTATION_MAP = "annotationMap";
+ public static final String PROPERTY_ENCODING_INFO = "encodingInfo";
+ /*
+ * properties common to all CMElementDeclaration nodes: PROPERTY_XSITYPES
+ * PROPERTY_DERIVED_ELEMENT_DECLARATION PROPERTY_SUBSTITUTION_GROUP
+ * PROPERTY_ABSTRACT
+ */
+ public static final String PROPERTY_XSITYPES = "XSITypes";
+ public static final String PROPERTY_DERIVED_ELEMENT_DECLARATION = "DerivedElementDeclaration";
+ public static final String PROPERTY_SUBSTITUTION_GROUP = "SubstitutionGroup";
+ public static final String PROPERTY_ABSTRACT = "Abstract";
+ /**
+ * Definition info for element declarations.
+ */
+ public static final String DEFINITION_INFO_GLOBAL = "global";
+ public static final String DEFINITION_INFO_LOCAL = "local";
+ public static final String XML_LANG_ATTRIBUTE = "xml:lang";
+ public static final String PLATFORM_PROTOCOL = "platform:";
+ protected static XSDAdapterFactoryImpl xsdAdapterFactoryImpl = new XSDAdapterFactoryImpl();
+ protected static XSIDocument xsiDocument = new XSIDocument();
+
+ /**
+ * Given uri for an XML Schema document, parse the document and build
+ * corresponding CMDocument node.
+ *
+ * @param uri -
+ * the uri for an XML Schema document
+ * @param grammarErrorChecking -
+ * grammar error checking flag
+ * @param errorList -
+ * the resulting error list
+ * @return the corresponding CMDocument node.
+ * @deprecated -- use buildCMDocument(String uri)
+ */
+ public static CMDocument buildCMDocument(String uri, int grammarErrorChecking, List errorList)
+ {
+ return buildCMDocument(uri);
+ }
+
+ /**
+ * Given uri for an XML Schema document, parse the document and build
+ * corresponding CMDocument node.
+ *
+ * @param uri -
+ * the uri for an XML Schema document
+ * @return the corresponding CMDocument node.
+ */
+ public static CMDocument buildCMDocument(String uri)
+ {
+ CMDocument cmDocument = null;
+ XSDSchema xsdSchema = buildXSDModel(uri);
+ if (xsdSchema != null)
+ {
+ cmDocument = (CMDocument) getAdapter(xsdSchema);
+ CMDocumentEncodingHelper.setEncodingInfo(cmDocument, uri);
+ }
+ return cmDocument;
+ }
+
+ /**
+ * Given uri for an XML Schema document, parse the document and build
+ * corresponding CMDocument node.
+ *
+ * @param uri -
+ * the uri for an XML Schema document
+ * @return the corresponding CMDocument node.
+ */
+ public static XSDSchema buildXSDModel(String uriString)
+ {
+ XSDSchema xsdSchema = null;
+
+ try
+ {
+ // if XML Schema for Schema is requested, get it through schema model
+ if (uriString.endsWith("2001/XMLSchema.xsd"))
+ {
+ xsdSchema = XSDSchemaImpl.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
+ }
+ else
+ {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ //resourceSet.getAdapterFactories().add(new XSDSchemaLocationResolverAdapterFactory());
+ resourceSet.getAdapterFactories().add(new XSDSchemaLocatorAdapterFactory());
+
+ URI uri = createURI(uriString);
+ XSDResourceImpl resource = (XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd"));
+ resource.setURI(uri);
+ resource.load(null);
+
+ xsdSchema = resource.getSchema();
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ return xsdSchema;
+ }
+
+ // TODO ... looks like we can remove this class?
+ //
+ static class InternalURIConverter extends URIConverterImpl
+ {
+ protected InputStream createURLInputStream(URI uri) throws IOException
+ {
+ if ("http".equals(uri.scheme()))
+ {
+ String theURI = uri.toString();
+ String mapped = URIResolverPlugin.createResolver().resolve(theURI, theURI, theURI);
+ if (mapped != null)
+ {
+ uri = createURI(mapped);
+ }
+ }
+ return super.createURLInputStream(uri);
+ }
+ }
+
+ /**
+ * Returns an appropriate URI based on a uri string.
+ *
+ * @param uriString -
+ * a uri string.
+ * @return an appropriate URI based on a uri string.
+ */
+ public static URI createURI(String uriString)
+ {
+ if (hasProtocol(uriString))
+ return URI.createURI(uriString);
+ else
+ return URI.createFileURI(uriString);
+ }
+
+ private static boolean hasProtocol(String uri)
+ {
+ boolean result = false;
+ if (uri != null)
+ {
+ int index = uri.indexOf(":");
+ if (index != -1 && index > 2) // assume protocol with be length 3 so that
+ // the'C' in 'C:/' is not interpreted as a
+ // protocol
+ {
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns true if string begins with platform protocol.
+ *
+ * @param uriString -
+ * a uri string.
+ * @return true if string begins with platform protocol.
+ */
+ public static boolean withPlatformProtocol(String uriString)
+ {
+ return uriString.startsWith(PLATFORM_PROTOCOL);
+ }
+
+ /**
+ * Returns the value of the 'Min Occurs' attribute. The default value is "1".
+ *
+ * @param component -
+ * a concrete component.
+ * @return the value of the 'Min Occurs' attribute.
+ */
+ public static int getMinOccurs(XSDConcreteComponent component)
+ {
+ int minOccur = 1;
+ if (component != null)
+ {
+ Object o = component.getContainer();
+ if (o instanceof XSDParticle)
+ {
+ if (((XSDParticle) o).isSetMinOccurs())
+ {
+ try
+ {
+ minOccur = ((XSDParticle) o).getMinOccurs();
+ }
+ catch (Exception e)
+ {
+ minOccur = 1;
+ }
+ }
+ }
+ }
+ return minOccur;
+ }
+
+ /**
+ * Returns the value of the 'Max Occurs' attribute. The default value is "1".
+ *
+ * @param component -
+ * a concrete component.
+ * @return the value of the 'Max Occurs' attribute.
+ */
+ public static int getMaxOccurs(XSDConcreteComponent component)
+ {
+ int maxOccur = 1;
+ if (component != null)
+ {
+ Object o = component.getContainer();
+ if (o instanceof XSDParticle)
+ {
+ if (((XSDParticle) o).isSetMaxOccurs())
+ {
+ try
+ {
+ maxOccur = ((XSDParticle) o).getMaxOccurs();
+ }
+ catch (Exception e)
+ {
+ maxOccur = 1;
+ }
+ }
+ }
+ }
+ return maxOccur;
+ }
+
+ /**
+ * Returns the enumerated values for the given type.
+ *
+ * @param type -
+ * a type definition.
+ * @return the enumerated values for the given type.
+ */
+ public static String[] getEnumeratedValuesForType(XSDTypeDefinition type)
+ {
+ List result = new ArrayList();
+ if (type instanceof XSDSimpleTypeDefinition)
+ {
+ List enumerationFacets = ((XSDSimpleTypeDefinition) type).getEnumerationFacets();
+ for (Iterator i = enumerationFacets.iterator(); i.hasNext();)
+ {
+ XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i.next();
+ List values = enumFacet.getValue();
+ for (Iterator j = values.iterator(); j.hasNext();)
+ {
+ Object o = j.next();
+ if (o != null)
+ {
+ result.add(o.toString());
+ }
+ }
+ }
+ }
+ String[] array = new String[result.size()];
+ result.toArray(array);
+ return array;
+ }
+
+ /**
+ * Return a list of documentation elements from the given annotation. Working
+ * with documentation elements requires dropping down into the DOM model.
+ *
+ * @param annotation -
+ * an XSDAnnotation node.
+ * @return a list of documentation elements.
+ */
+ public static CMNodeList getDocumentations(XSDAnnotation annotation)
+ {
+ CMNodeListImpl documentations = new CMNodeListImpl();
+ if (annotation != null)
+ {
+ List documentationsElements = annotation.getUserInformation();
+ for (Iterator i = documentationsElements.iterator(); i.hasNext();)
+ {
+ documentations.getList().add(new DocumentationImpl((Element) i.next()));
+ }
+ }
+ return documentations;
+ }
+
+ /**
+ * Adapted from public static List findTypesDerivedFrom(XSDSchema schema,
+ * String namespace, String localName) in class XSDSchemaQueryTools found in
+ * org.eclipse.xsd plugin.
+ *
+ * Find typeDefinitions that derive from a given type.
+ *
+ * @param type
+ * the type derived from
+ * @return List of any XSDTypeDefinitions found
+ */
+ public static List findTypesDerivedFrom(XSDTypeDefinition type)
+ {
+ ArrayList typesDerivedFrom = new ArrayList();
+ if (type != null)
+ {
+ XSDSchema schema = type.getSchema();
+ String localName = type.getName();
+ if ((null != schema) && (null != localName))
+ {
+ String namespace = schema.getTargetNamespace();
+ // A handy convenience method quickly gets all
+ // typeDefinitions within our schema; note that
+ // whether or not this returns types in included,
+ // imported, or redefined schemas is subject to change
+ List typedefs = schema.getTypeDefinitions();
+ for (Iterator iter = typedefs.iterator(); iter.hasNext();)
+ {
+ XSDTypeDefinition typedef = (XSDTypeDefinition) iter.next();
+ if (typedef instanceof XSDComplexTypeDefinition)
+ {
+ // Walk the baseTypes from this typedef seeing if any
+ // of them match the requested one
+ if (isTypeDerivedFrom(typedef, namespace, localName))
+ {
+ // We found it, return the original one and continue
+ typesDerivedFrom.add(typedef);
+ continue;
+ }
+ }
+ }
+ }
+ }
+ return typesDerivedFrom;
+ }
+
+ /**
+ * Adapted from protected static boolean isTypeDerivedFrom(XSDTypeDefinition
+ * typedef, String namespace, String localName) in class XSDSchemaQueryTools
+ * found in org.eclipse.xsd plugin.
+ *
+ * Recursive worker method to find typeDefinitions that derive from a named
+ * type.
+ *
+ * @see #findTypesDerivedFrom(XSDSchema, String, String)
+ * @param typeDef
+ * to see if it's derived from
+ * @param namespace
+ * for the type derived from
+ * @param localName
+ * for the type derived from
+ * @return true if it is; false otherwise
+ */
+ protected static boolean isTypeDerivedFrom(XSDTypeDefinition typedef, String namespace, String localName)
+ {
+ // Walk the baseTypes from this typedef seeing if any
+ // of them match the requested one
+ XSDTypeDefinition baseType = typedef.getBaseType();
+ // As this convenience method if our parameters match
+ if (baseType.hasNameAndTargetNamespace(localName, namespace))
+ {
+ return true;
+ }
+ XSDTypeDefinition rootType = typedef.getRootType();
+ if (rootType == baseType)
+ {
+ // If we've hit the root, we aren't derived from it
+ return false;
+ }
+ else
+ {
+ // Otherwise continue to traverse upwards
+ return isTypeDerivedFrom(baseType, namespace, localName);
+ }
+ }
+
+ /**
+ * Returns the corresponding cmnode of the specified XML Schema node.
+ *
+ * @param target -
+ * an XML Schema node
+ * @return the corresponding cmnode.
+ */
+ public static CMNode getAdapter(Notifier o)
+ {
+ return (CMNode) xsdAdapterFactoryImpl.adapt(o);
+ }
+
+ /**
+ * Adapted from public String getPrefix(String ns, boolean withColon) in class
+ * TypesHelper found in org.eclipse.wst.xsd.editor plugin.
+ *
+ * @param schema -
+ * the relevant schema
+ * @param ns -
+ * the relevant namespace
+ */
+ public static String getPrefix(XSDSchema schema, String ns)
+ {
+ String key = "";
+ if ((schema != null) && (ns != null))
+ {
+ Map map = schema.getQNamePrefixToNamespaceMap();
+ Iterator iter = map.keySet().iterator();
+ while (iter.hasNext())
+ {
+ Object keyObj = iter.next();
+ Object value = map.get(keyObj);
+ if (value != null && value.toString().equals(ns))
+ {
+ if (keyObj != null)
+ {
+ key = keyObj.toString();
+ }
+ else
+ {
+ key = "";
+ }
+ break;
+ }
+ }
+ }
+ return key;
+ }
+ /**
+ * The Factory for the XSD adapter model. It provides a create method for each
+ * non-abstract class of the model.
+ */
+ public static class XSDAdapterFactoryImpl extends AdapterFactoryImpl
+ {
+ public Adapter createAdapter(Notifier target)
+ {
+ XSDSwitch xsdSwitch = new XSDSwitch()
+ {
+ public Object caseXSDWildcard(XSDWildcard object)
+ {
+ return new XSDWildcardAdapter(object);
+ }
+
+ public Object caseXSDModelGroupDefinition(XSDModelGroupDefinition object)
+ {
+ return new XSDModelGroupDefinitionAdapter(object);
+ }
+
+ public Object caseXSDAttributeUse(XSDAttributeUse object)
+ {
+ return new XSDAttributeUseAdapter(object);
+ }
+
+ public Object caseXSDElementDeclaration(XSDElementDeclaration object)
+ {
+ return new XSDElementDeclarationAdapter(object);
+ }
+
+ public Object caseXSDModelGroup(XSDModelGroup object)
+ {
+ return new XSDModelGroupAdapter(object);
+ }
+
+ public Object caseXSDSchema(XSDSchema object)
+ {
+ return new XSDSchemaAdapter(object);
+ }
+ };
+ Object o = xsdSwitch.doSwitch((EObject) target);
+ Adapter result = null;
+ if (o instanceof Adapter)
+ {
+ result = (Adapter) o;
+ }
+ else
+ {
+ Thread.dumpStack();
+ }
+ return result;
+ }
+
+ public Adapter adapt(Notifier target)
+ {
+ return adapt(target, this);
+ }
+ }
+ /**
+ * XSDBaseAdapter -- an abstract base node in the model. All other model nodes
+ * are derived from it.
+ */
+ public static abstract class XSDBaseAdapter extends CMNodeImpl
+ {
+ protected CMNodeListImpl documentation = new CMNodeListImpl();
+
+ /**
+ * Returns the name of the node. The default value is an empty string value.
+ * All derived classes must override this method if they do not want the
+ * default value.
+ *
+ * @return the name of the node.
+ */
+ public String getNodeName()
+ {
+ return "";
+ }
+
+ /**
+ * Returns true of the given factory is the factory for this XSD adapter
+ * model.
+ *
+ * @param type -
+ * a factory
+ * @return true if the type is the adapter factory for this model.
+ */
+ public boolean isAdapterForType(Object type)
+ {
+ return type == xsdAdapterFactoryImpl;
+ }
+
+ /**
+ * Returns true if the property is supported for this class.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return true if the property is supported.
+ */
+ public boolean supports(String propertyName)
+ {
+ return propertyName.equals(PROPERTY_NS_PREFIX_QUALIFICATION) || propertyName.equals(PROPERTY_NILLABLE) || propertyName.equals(PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS)
+ || propertyName.equals(PROPERTY_DOCUMENTATION) || propertyName.equals(PROPERTY_DOCUMENTATION_SOURCE) || propertyName.equals(PROPERTY_DOCUMENTATION_LANGUAGE)
+ || propertyName.equals(PROPERTY_MOF_NOTIFIER) || propertyName.equals(PROPERTY_DEFINITION_INFO) || propertyName.equals(PROPERTY_DEFINITION) || propertyName.equals(PROPERTY_CMDOCUMENT)
+ || propertyName.equals(PROPERTY_IS_NAME_SPACE_AWARE) || propertyName.equals(PROPERTY_SPEC) || super.supports(propertyName);
+ }
+
+ /**
+ * Returns the value of the 'Nillable' attribute. This represents the
+ * nillable infoset property. The default value is false. All derived
+ * classes must override this method if they do not want the default value.
+ *
+ * @return the value of the 'Nillable' attribute.
+ */
+ public boolean isNillable()
+ {
+ return false;
+ }
+
+ /**
+ * Returns the cmdocument that is the owner of this cmnode. The default
+ * value is null; All derived classes must override this method if they do
+ * not want the default value.
+ *
+ * @return the cmdocument corresponding to this cmnode.
+ */
+ public CMDocument getCMDocument()
+ {
+ return null;
+ }
+
+ /**
+ * Return a list of documentation elements. The default value is an empty
+ * CMNodeList; All derived classes must override this method if they do not
+ * want the default value.
+ *
+ * @return a list of documentation elements.
+ */
+ protected CMNodeList getDocumentation()
+ {
+ return documentation;
+ }
+
+ /**
+ * Returns the property value for the property name. Returns null if the
+ * property is not supported.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return the property value for the property name.
+ */
+ public Object getProperty(String propertyName)
+ {
+ Object result = null;
+ if (propertyName.equals(PROPERTY_CMDOCUMENT))
+ {
+ result = getCMDocument();
+ }
+ else if (propertyName.equals(PROPERTY_DOCUMENTATION))
+ {
+ result = getDocumentation();
+ }
+ else if (propertyName.equals(PROPERTY_USES_LOCAL_ELEMENT_DECLARATIONS))
+ {
+ result = Boolean.TRUE;
+ }
+ else if (propertyName.equals(PROPERTY_IS_NAME_SPACE_AWARE))
+ {
+ result = Boolean.TRUE;
+ }
+ else if (propertyName.equals(PROPERTY_NS_PREFIX_QUALIFICATION))
+ {
+ result = getNSPrefixQualification();
+ }
+ else if (propertyName.equals(PROPERTY_NILLABLE))
+ {
+ result = isNillable() ? xsiDocument.nilAttribute : null;
+ }
+ else if (propertyName.equals(PROPERTY_MOF_NOTIFIER))
+ {
+ result = getKey();
+ }
+ else if (propertyName.equals(PROPERTY_SPEC))
+ {
+ result = getSpec();
+ }
+ else
+ {
+ result = super.getProperty(propertyName);
+ {
+ CMDocument cmDocument = getCMDocument();
+ if (cmDocument instanceof XSDSchemaAdapter)
+ {
+ AnnotationMap map = ((XSDSchemaAdapter) cmDocument).annotationMap;
+ if (map != null)
+ {
+ String spec = getSpec();
+ if (spec != null)
+ {
+ result = map.getProperty(getSpec(), propertyName);
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+
+
+ /*
+ * Returns the value of the form [attribute] which affects the target
+ * namespace of locally scoped features. The default value is null. All
+ * derived classes must override this method if they do not want the default
+ * value. @return the value of the form [attribute].
+ */
+ public Object getNSPrefixQualification()
+ {
+ return null;
+ }
+
+ /**
+ * Returns a general XPath expression for the node.
+ *
+ * @return a general XPath expression for the node.
+ */
+ public String getSpec()
+ {
+ return "//" + getNodeName();
+ }
+ }
+ /**
+ * XSDSchemaAdapter implements CMDocument. A representation of the model
+ * object 'Schema'.
+ */
+ public static class XSDSchemaAdapter extends XSDBaseAdapter implements CMDocument
+ {
+ protected XSDSchema xsdSchema;
+ protected CMNamedNodeMapImpl namedNodeMap;
+ protected CMNamedNodeMapImpl entityNodeMap;
+ protected String[] encodingInfo = new String[2];
+ protected AnnotationMap annotationMap = new AnnotationMap();
+ protected Hashtable substitutionGroupTable;
+
+ /**
+ * Constructor.
+ *
+ * @param xsdSchema -
+ * the schema node.
+ */
+ public XSDSchemaAdapter(XSDSchema xsdSchema)
+ {
+ this.xsdSchema = xsdSchema;
+ }
+
+ /**
+ * Returns the key for this cmnode which is the corresponding XML Schema
+ * node.
+ *
+ * @return the key for this cmnode.
+ */
+ public Object getKey()
+ {
+ return xsdSchema;
+ }
+
+ /**
+ * Returns the filename.
+ *
+ * @return the filename.
+ */
+ public String getNodeName()
+ {
+ // See buildCMDocument() above.
+ return xsdSchema.getSchemaLocation();
+ }
+
+ /**
+ * Returns true if the property is supported for this class.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return true if the property is supported.
+ */
+ public boolean supports(String propertyName)
+ {
+ return propertyName.equals(PROPERTY_TARGET_NAMESPACE_URI) || propertyName.equals(PROPERTY_IMPORTED_NAMESPACE_INFO) || propertyName.equals(PROPERTY_NAMESPACE_INFO)
+ || propertyName.equals(PROPERTY_ELEMENT_FORM_DEFAULT) || propertyName.equals(PROPERTY_ANNOTATION_MAP) || propertyName.equals(PROPERTY_ENCODING_INFO) || super.supports(propertyName);
+ }
+
+ /**
+ * Returns true if a prefix is globally required for elements.
+ *
+ * @param xsdSchema -
+ * the corresponding schema node.
+ * @return true if a prefix is globally required for elements.
+ */
+ protected boolean isPrefixRequired(XSDSchema xsdSchema)
+ {
+ boolean result = true;
+ if (xsdSchema.isSetElementFormDefault())
+ result = !(xsdSchema.getElementFormDefault().getValue() == XSDForm.QUALIFIED);
+ return result;
+ }
+
+ /**
+ * Returns the property value for the property name. Returns null if the
+ * property is not supported.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return the property value for the property name.
+ */
+ public Object getProperty(String propertyName)
+ {
+ Object result = null;
+ if (propertyName.equals(PROPERTY_TARGET_NAMESPACE_URI))
+ {
+ result = xsdSchema.getTargetNamespace();
+ }
+ else if (propertyName.equals(PROPERTY_IMPORTED_NAMESPACE_INFO))
+ {
+ List list = new Vector();
+ getImportedNamespaceInfo(xsdSchema, list);
+ result = list;
+ }
+ else if (propertyName.equals(PROPERTY_NAMESPACE_INFO))
+ {
+ List list = new Vector();
+ NamespaceInfo info = new NamespaceInfo();
+ info.uri = xsdSchema.getTargetNamespace();
+ info.prefix = getPrefix(xsdSchema, info.uri);
+ info.locationHint = null; // note that this locationHint info is null
+ // for the root xsd file
+ info.isPrefixRequired = isPrefixRequired(xsdSchema);
+ list.add(info);
+ getImportedNamespaceInfo(xsdSchema, list);
+ result = list;
+ }
+ else if (propertyName.equals(PROPERTY_ELEMENT_FORM_DEFAULT))
+ {
+ result = xsdSchema.getElementFormDefault().getName();
+ }
+ else if (propertyName.equals(PROPERTY_ANNOTATION_MAP))
+ {
+ result = annotationMap;
+ }
+ else if (propertyName.equals(PROPERTY_ENCODING_INFO))
+ {
+ result = encodingInfo;
+ }
+ else if (propertyName.equals("allElements"))
+ {
+ result = getAllElements();
+ }
+ else if (propertyName.startsWith("getElementForType#"))
+ {
+ int index = propertyName.indexOf("#");
+ String typeName = propertyName.substring(index + 1, propertyName.length());
+ //
+ //
+ XSDTypeDefinition td = xsdSchema.resolveTypeDefinition(typeName);
+ if (td != null)
+ {
+ LocalElementVisitor localElementVisitor = new LocalElementVisitor();
+ localElementVisitor.visitTypeDefinition(td);
+ result = localElementVisitor.getCMNamedNodeMap();
+ }
+ }
+ else
+ {
+ result = super.getProperty(propertyName);
+ }
+ return result;
+ }
+
+ /**
+ * Gather information on namespaces used in external references.
+ *
+ * @param theXSDSchema -
+ * the corresponding schema node
+ * @param list -
+ * the list of imported namespaces.
+ */
+ public void getImportedNamespaceInfo(XSDSchema theXSDSchema, List list)
+ {
+ for (Iterator iterator = theXSDSchema.getContents().iterator(); iterator.hasNext();)
+ {
+ XSDSchemaContent content = (XSDSchemaContent) iterator.next();
+ if (content instanceof XSDImport)
+ {
+ XSDImport xImport = (XSDImport) content;
+ XSDSchema importedXSDSchema = xImport.getResolvedSchema();
+ NamespaceInfo info = new NamespaceInfo();
+ info.uri = xImport.getNamespace();
+ info.prefix = getPrefix(importedXSDSchema, info.uri);
+ info.locationHint = xImport.getSchemaLocation();
+ if (importedXSDSchema != null)
+ {
+ info.isPrefixRequired = isPrefixRequired(importedXSDSchema);
+ }
+ list.add(info);
+ }
+ }
+ }
+
+ /**
+ * Returns set of named (top-level) element declarations for this schema
+ * node.
+ *
+ * @return a set of named (top-level) element declarations.
+ */
+ public CMNamedNodeMap getElements()
+ {
+ if (namedNodeMap == null)
+ {
+ namedNodeMap = new CMNamedNodeMapImpl();
+
+ // Note that if we call xsdSchema.getElementDeclarations()
+ // we get 'more' elements than we really want since we also
+ // get 'imported' elements. Below we test to ensure the elements
+ // actually have the same target namespace as the schema.
+ String targetNamespace = xsdSchema.getTargetNamespace();
+ for (Iterator i = xsdSchema.getElementDeclarations().iterator(); i.hasNext();)
+ {
+ XSDElementDeclaration ed = (XSDElementDeclaration) i.next();
+ if (targetNamespace != null ? targetNamespace.equals(ed.getTargetNamespace()) : ed.getTargetNamespace() == null)
+ {
+ XSDElementDeclarationAdapter adapter = (XSDElementDeclarationAdapter) getAdapter(ed);
+ namedNodeMap.getHashtable().put(adapter.getNodeName(), adapter);
+ }
+ }
+ }
+ return namedNodeMap;
+ }
+
+ /**
+ * Returns the built-in entity declarations.
+ *
+ * @return the built-in entity declarations.
+ */
+ public CMNamedNodeMap getEntities()
+ {
+ if (entityNodeMap == null)
+ {
+ entityNodeMap = new CMNamedNodeMapImpl();
+ // add the built in entity declarations
+ entityNodeMap.getHashtable().put("amp", new CMEntityDeclarationImpl("amp", "&"));
+ entityNodeMap.getHashtable().put("lt", new CMEntityDeclarationImpl("lt", "<"));
+ entityNodeMap.getHashtable().put("gt", new CMEntityDeclarationImpl("gt", ">"));
+ entityNodeMap.getHashtable().put("quot", new CMEntityDeclarationImpl("quot", "\""));
+ entityNodeMap.getHashtable().put("apos", new CMEntityDeclarationImpl("apos", "'"));
+ }
+ return entityNodeMap;
+ }
+
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return DOCUMENT;
+ }
+
+ /*
+ * Returns null. !!! Why are we not implementing this???? @return null.
+ */
+ public CMNamespace getNamespace()
+ {
+ return null;
+ }
+
+ /**
+ * Returns this.
+ *
+ * @return this.
+ */
+ public CMDocument getCMDocument()
+ {
+ return this;
+ }
+
+ public CMNamedNodeMap getAllElements()
+ {
+ CMNamedNodeMapImpl map = new CMNamedNodeMapImpl();
+ for (Iterator i = getElements().iterator(); i.hasNext(); )
+ {
+ CMElementDeclaration ed = (CMElementDeclaration)i.next();
+ map.put(ed);
+ addLocalElementDefinitions(map, ed);
+ }
+ return map;
+ }
+
+ protected void addLocalElementDefinitions(CMNamedNodeMapImpl map, CMElementDeclaration parentElementDeclaration)
+ {
+ CMNamedNodeMap localElementMap = parentElementDeclaration.getLocalElements();
+ for (Iterator i = localElementMap.iterator(); i.hasNext(); )
+ {
+ CMElementDeclaration ed = (CMElementDeclaration)i.next();
+ if (map.getNamedItem(ed.getNodeName()) == null)
+ {
+ map.put(ed);
+ addLocalElementDefinitions(map, ed);
+ }
+ }
+ }
+ }
+ /**
+ * XSDAttributeUseAdapter implements CMAttributeDeclaration. A representation
+ * of the model object 'Attribute Use'.
+ */
+ public static class XSDAttributeUseAdapter extends XSDBaseAdapter implements CMAttributeDeclaration
+ {
+ // provides access to the XML Schema node
+ protected XSDAttributeUse xsdAttributeUse;
+ // provides access to the type of the attribute
+ protected CMDataType dataType = new DataTypeImpl();
+
+ /**
+ * Constructor.
+ *
+ * @param xsdAttributeUse -
+ * the XML Schema node.
+ */
+ public XSDAttributeUseAdapter(XSDAttributeUse xsdAttributeUse)
+ {
+ this.xsdAttributeUse = xsdAttributeUse;
+ }
+
+ /**
+ * Returns the key for this cmnode which is the corresponding XML Schema
+ * node.
+ *
+ * @return the key for this cmnode.
+ */
+ public Object getKey()
+ {
+ return xsdAttributeUse;
+ }
+
+ /**
+ * Returns a general XPath expression for the node.
+ *
+ * @return a general XPath expression for the node.
+ */
+ public String getSpec()
+ {
+ return "//@" + getAttrName();
+ }
+
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return ATTRIBUTE_DECLARATION;
+ }
+
+ /**
+ * Returns the name of the node. Similar to getAttrName().
+ *
+ * @return the name of the node.
+ */
+ public String getNodeName()
+ {
+ return getAttrName();
+ }
+
+ /**
+ * getEnumAttr method
+ *
+ * @return java.util.Enumeration
+ * @deprecated -- to be replaced in future with additional CMDataType
+ * methods (currently found on CMDataTypeHelper)
+ */
+ public Enumeration getEnumAttr()
+ {
+ return Collections.enumeration(Collections.EMPTY_LIST);
+ }
+
+ /**
+ * Returns the name of this attribute. Similar to getNodeName().
+ *
+ * @return the name of this attribute.
+ */
+ public String getAttrName()
+ {
+ return xsdAttributeUse.getAttributeDeclaration().getName();
+ }
+
+ /**
+ * Returns the type of the attribute.
+ *
+ * @return the type of the attribute.
+ */
+ public CMDataType getAttrType()
+ {
+ return dataType;
+ }
+
+ /**
+ * Returns the value of the default or fixed constraint.
+ *
+ * @return the value of the default or fixed constraint.
+ */
+ public String getDefaultValue()
+ {
+ return dataType.getImpliedValue();
+ }
+
+ /**
+ * Returns the usage constraint for this attribute. The usages are defined
+ * in CMAttributeDeclaration class (OPTIONAL, REQUIRED, FIXED or
+ * PROHIBITED).
+ *
+ * @return the usage constraint for this attribute.
+ */
+ public int getUsage()
+ {
+ int useKind = OPTIONAL;
+ switch (xsdAttributeUse.getUse().getValue())
+ {
+ case XSDAttributeUseCategory.OPTIONAL : {
+ useKind = OPTIONAL;
+ break;
+ }
+ case XSDAttributeUseCategory.PROHIBITED : {
+ useKind = PROHIBITED;
+ break;
+ }
+ case XSDAttributeUseCategory.REQUIRED : {
+ useKind = REQUIRED;
+ break;
+ }
+ }
+ return useKind;
+ }
+
+ /*
+ * Returns the value of the form [attribute] which affects the target
+ * namespace of locally scoped features. If the form is not set on this
+ * attribute, then see if there is a globally defined default. @return the
+ * value of the form [attribute].
+ */
+ public Object getNSPrefixQualification()
+ {
+ String form = null;
+ if (xsdAttributeUse.getContent() != xsdAttributeUse.getAttributeDeclaration())
+ {
+ form = "qualified";
+ }
+ else if (xsdAttributeUse.getContent().isSetForm())
+ {
+ form = xsdAttributeUse.getContent().getForm().getName();
+ }
+ else
+ {
+ XSDSchema schema = xsdAttributeUse.getSchema();
+ if (schema != null)
+ form = schema.getAttributeFormDefault().getName();
+ }
+ return form;
+ }
+
+ /**
+ * Return a list of documentation elements.
+ *
+ * @return a list of documentation elements.
+ */
+ protected CMNodeList getDocumentation()
+ {
+ XSDAnnotation annotation = xsdAttributeUse.getAttributeDeclaration().getAnnotation();
+ return getDocumentations(annotation);
+ }
+
+ /**
+ * Returns the cmdocument that is the owner of this cmnode.
+ *
+ * @return the cmdocument corresponding to this cmnode.
+ */
+ public CMDocument getCMDocument()
+ {
+ return (CMDocument) getAdapter(xsdAttributeUse.getSchema());
+ }
+ /**
+ * XSDAttributeUseAdapter.DataTypeImpl An inner class to hold type
+ * information for this attribute.
+ */
+ public class DataTypeImpl implements CMDataType
+ {
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return CMNode.DATA_TYPE;
+ }
+
+ /**
+ * Returns the name of the attribute type. Same as getDataTypeName().
+ *
+ * @return the name of the attribute type.
+ */
+ public String getNodeName()
+ {
+ return getDataTypeName();
+ }
+
+ /**
+ * Returns false. This class does not support any properties.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return false.
+ */
+ public boolean supports(String propertyName)
+ {
+ return false;
+ }
+
+ /**
+ * Returns null. This class does not support any properties.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return null.
+ */
+ public Object getProperty(String propertyName)
+ {
+ return null;
+ }
+
+ /**
+ * Returns the name of the attribute type. Same as getNodeName().
+ *
+ * @return the name of the attribute type.
+ */
+ public String getDataTypeName()
+ {
+ XSDSimpleTypeDefinition sc = xsdAttributeUse.getAttributeDeclaration().getTypeDefinition();
+ String typeName = sc.getName();
+ return typeName != null ? typeName : "string";
+ }
+
+ /**
+ * Returns the kind of constraint: none, default or fixed. The kinds are
+ * defined in CMDataType class (IMPLIED_VALUE_NONE, IMPLIED_VALUE_FIXED or
+ * IMPLIED_VALUE_DEFAULT).
+ *
+ * @return the kind of constraint: none, default or fixed.
+ */
+ public int getImpliedValueKind()
+ {
+ int result = IMPLIED_VALUE_NONE;
+ if (xsdAttributeUse.isSetConstraint())
+ {
+ if (xsdAttributeUse.getConstraint().getValue() == XSDConstraint.DEFAULT)
+ result = IMPLIED_VALUE_DEFAULT;
+ else if (xsdAttributeUse.getConstraint().getValue() == XSDConstraint.FIXED)
+ result = IMPLIED_VALUE_FIXED;
+ }
+ return result;
+ }
+
+ /**
+ * Returns the value of the default or fixed constraint.
+ *
+ * @return the value of the default or fixed constraint.
+ */
+ public String getImpliedValue()
+ {
+ String result = null;
+ if (xsdAttributeUse.isSetConstraint())
+ {
+ result = xsdAttributeUse.getLexicalValue();
+ }
+ return result;
+ }
+
+ /**
+ * Returns the enumerated values for the attribute type.
+ *
+ * @return the enumerated values for the attribute type.
+ */
+ public String[] getEnumeratedValues()
+ {
+ return getEnumeratedValuesForType(getXSDType());
+ }
+
+ /**
+ * Generate a valid value for the attribute based on its type.
+ *
+ * @return a valid value for the attribute based on its type.
+ */
+ public String generateInstanceValue()
+ {
+ XSDAttributeDeclaration attr = xsdAttributeUse.getAttributeDeclaration();
+ return XSDTypeUtil.getInstanceValue(attr.getResolvedAttributeDeclaration().getTypeDefinition());
+ }
+
+ /**
+ * Returns the corresponding XML Schema type definition.
+ *
+ * @return the corresponding XML Schema type definition.
+ */
+ protected XSDTypeDefinition getXSDType()
+ {
+ XSDAttributeDeclaration attr = xsdAttributeUse.getAttributeDeclaration();
+ return attr.getResolvedAttributeDeclaration().getTypeDefinition();
+ }
+ }
+ }
+ /**
+ * ElementDeclarationBaseImpl implements CMElementDeclaration. This is the
+ * base class for XSDElementDeclaration and DerivedElementDeclarationImpl.
+ *
+ * Abstract methods in this class are: public abstract Object getKey(); public
+ * abstract Object getNSPrefixQualification(); public abstract
+ * XSDElementDeclaration getXSDElementDeclaration(); public abstract
+ * XSDTypeDefinition getXSDType(); public abstract List getXSITypes(); public
+ * abstract CMElementDeclaration getDerivedElementDeclaration(String
+ * uriQualifiedTypeName); public abstract CMNode getDefinition(); public
+ * abstract String getDefinitionInfo(); public abstract CMNodeListImpl
+ * getSubstitutionGroup();
+ */
+ public static abstract class ElementDeclarationBaseImpl extends XSDBaseAdapter implements CMElementDeclaration
+ {
+ protected CMDataType dataType = new DataTypeImpl();
+ protected CMNamedNodeMap namedNodeMap;
+
+ /**
+ * Returns corresponding XML Schema element declaration.
+ *
+ * @return corresponding XML Schema element declaration.
+ */
+ protected abstract XSDElementDeclaration getXSDElementDeclaration();
+
+ /**
+ * Returns corresponding XML Schema element declaration.
+ *
+ * @return corresponding XML Schema element declaration.
+ */
+ protected abstract XSDElementDeclaration getResolvedXSDElementDeclaration();
+
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return ELEMENT_DECLARATION;
+ }
+
+ /**
+ * Returns the name of the node. The same as getElementName().
+ *
+ * @return the name of the node.
+ */
+ public String getNodeName()
+ {
+ return getElementName();
+ }
+
+ /**
+ * Returns the name of this element. The same as getNodeName().
+ *
+ * @return the name of this element.
+ */
+ public String getElementName()
+ {
+ String result = getResolvedXSDElementDeclaration().getName();
+ return result != null ? result : "";
+ }
+
+ /**
+ * Returns true if the property is supported for this class.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return true if the property is supported.
+ */
+ public boolean supports(String propertyName)
+ {
+ return propertyName.equals(PROPERTY_XSITYPES) || propertyName.equals(PROPERTY_DERIVED_ELEMENT_DECLARATION) || propertyName.equals(PROPERTY_SUBSTITUTION_GROUP)
+ || propertyName.equals(PROPERTY_ABSTRACT) || super.supports(propertyName);
+ }
+
+ /**
+ * Returns the key for this cmnode which is the corresponding XML Schema
+ * node.
+ *
+ * @return the key for this cmnode.
+ */
+ public abstract Object getKey();
+
+ /**
+ * Returns the set of attributes defined for this element.
+ *
+ * @return the set of attributes defined for this element.
+ */
+ public CMNamedNodeMap getAttributes()
+ {
+ CMNamedNodeMapImpl map = new CMNamedNodeMapImpl();
+ XSDTypeDefinition td = getXSDType();
+ getAttributes(map, td);
+ addXSITypeAttribute(map);
+ return map;
+ }
+
+ /**
+ * Gather the set of attributes defined for this element.
+ *
+ * @param map -
+ * used for returning the set of attributes.
+ * @param xsdTypeDefinition -
+ * the type definition for this element.
+ */
+ public void getAttributes(CMNamedNodeMapImpl map, XSDTypeDefinition xsdTypeDefinition)
+ {
+ if (xsdTypeDefinition instanceof XSDComplexTypeDefinition)
+ {
+ XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) xsdTypeDefinition;
+ for (Iterator i = ctd.getAttributeUses().iterator(); i.hasNext();)
+ {
+ XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) i.next();
+ XSDAttributeUseAdapter adapter = (XSDAttributeUseAdapter) getAdapter(xsdAttributeUse);
+ if (adapter != null && adapter.getNodeName() != null)
+ {
+ map.getHashtable().put(adapter.getNodeName(), adapter);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the content for this element.
+ *
+ * @return the content for this element.
+ */
+ public CMContent getContent()
+ {
+ CMContent result = null;
+ XSDTypeDefinition td = getXSDType();
+ if (td instanceof XSDComplexTypeDefinition)
+ {
+ DerivedChildVisitor dcv = new DerivedChildVisitor(td);
+ dcv.visitTypeDefinition(td);
+ CMNodeList nodeList = dcv.getChildNodeList();
+ if (nodeList.getLength() > 1)
+ {
+ result = new CMGroupImpl(nodeList, CMGroup.SEQUENCE);
+ }
+ else if (nodeList.getLength() > 0)
+ {
+ result = (CMContent) nodeList.item(0);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns the content type of this element. The content type is defined in
+ * CMElementDeclaration (ANY, EMPTY, ELEMENT, MIXED, PCDATA or CDATA).
+ *
+ * @return the content type of this element.
+ */
+ public int getContentType()
+ {
+ int contentType = EMPTY;
+ XSDTypeDefinition td = getXSDType();
+ if (td instanceof XSDSimpleTypeDefinition)
+ {
+ String typeName = td.getName();
+ if (typeName != null && typeName.equals("anyType"))
+ {
+ contentType = ANY;
+ }
+ else
+ {
+ contentType = PCDATA;
+ }
+ }
+ else if (td instanceof XSDComplexTypeDefinition)
+ {
+ XSDContentTypeCategory category = ((XSDComplexTypeDefinition) td).getContentTypeCategory();
+ if (category != null)
+ {
+ switch (category.getValue())
+ {
+ case XSDContentTypeCategory.ELEMENT_ONLY :
+ contentType = ELEMENT;
+ break;
+ case XSDContentTypeCategory.EMPTY :
+ contentType = EMPTY;
+ break;
+ case XSDContentTypeCategory.MIXED :
+ contentType = MIXED;
+ break;
+ case XSDContentTypeCategory.SIMPLE :
+ contentType = PCDATA;
+ break;
+ }
+ }
+ }
+ return contentType;
+ }
+
+ /**
+ * Returns the name of the element type.
+ *
+ * @return the name of the element type.
+ */
+ public CMDataType getDataType()
+ {
+ CMDataType result = null;
+ int contentType = getContentType();
+ boolean hasDataType = contentType == PCDATA || contentType == MIXED;
+ if (hasDataType)
+ {
+ result = dataType;
+ }
+ return result;
+ }
+
+ /**
+ * Returns the value of 'Min Occurs' attribute. The default value is "1".
+ *
+ * @return the value of the 'Min Occurs' attribute.
+ */
+ public int getMinOccur()
+ {
+ return getMinOccurs(getXSDElementDeclaration());
+ }
+
+ /**
+ * Returns the value of the 'Max Occurs' attribute. The default value is
+ * "1".
+ *
+ * @return the value of the 'Max Occurs' attribute.
+ */
+ public int getMaxOccur()
+ {
+ return getMaxOccurs(getXSDElementDeclaration());
+ }
+
+ /**
+ * Returns the referenced element declaration if this is an element
+ * reference. Otherwise it returns itself.
+ *
+ * @return an element declaration.
+ */
+ protected abstract CMNode getDefinition();
+
+ /**
+ * Returns a string indicating whether the element declaration is global or
+ * local. Returns null if this is an element reference.
+ *
+ * @return a string indicating whether the element declaration is global or
+ * local.
+ */
+ protected abstract String getDefinitionInfo();
+
+ /**
+ * Returns the elements local to this element declaration.
+ *
+ * @return the elements local to this element declaration.
+ */
+ public CMNamedNodeMap getLocalElements()
+ {
+ if (namedNodeMap == null)
+ {
+ LocalElementVisitor localElementVisitor = new LocalElementVisitor();
+ localElementVisitor.visitTypeDefinition(getXSDType());
+ namedNodeMap = localElementVisitor.getCMNamedNodeMap();
+ }
+ return namedNodeMap;
+ }
+
+ /**
+ * Returns the property value for the property name. Returns null if the
+ * property is not supported.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return the property value for the property name.
+ */
+ public Object getProperty(String propertyName)
+ {
+ Object result = null;
+ if (propertyName.equals(PROPERTY_DEFINITION_INFO))
+ {
+ result = getDefinitionInfo();
+ }
+ else if (propertyName.equals(PROPERTY_DEFINITION))
+ {
+ result = getDefinition();
+ }
+ else if (propertyName.equals(PROPERTY_XSITYPES))
+ {
+ result = getXSITypes();
+ }
+ else if (propertyName.startsWith(PROPERTY_DERIVED_ELEMENT_DECLARATION))
+ {
+ int index = propertyName.indexOf("=");
+ if (index != -1)
+ {
+ String uriQualifiedTypeName = propertyName.substring(index + 1);
+ result = getDerivedElementDeclaration(uriQualifiedTypeName);
+ }
+ }
+ else if (propertyName.equals(PROPERTY_SUBSTITUTION_GROUP))
+ {
+ return getSubstitutionGroup();
+ }
+ else if (propertyName.equals(PROPERTY_ABSTRACT))
+ {
+ return getAbstract();
+ }
+ else
+ {
+ result = super.getProperty(propertyName);
+ }
+ return result;
+ }
+
+ /**
+ * Returns the value of the 'Nillable' attribute. This represents the
+ * nillable infoset property. The default value is false.
+ *
+ * @return the value of the 'Nillable' attribute.
+ */
+ public boolean isNillable()
+ {
+ if (getXSDElementDeclaration().isSetNillable())
+ return getXSDElementDeclaration().isNillable();
+ else
+ return false;
+ }
+
+ /**
+ * Returns whether the element is 'Abstract'.
+ *
+ * @return true if the element is 'Abstract'.
+ */
+ public Boolean getAbstract()
+ {
+ boolean result = getResolvedXSDElementDeclaration().isAbstract();
+ // TODO... how do we handle elements with abstract type's ?
+ return result ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ /**
+ * Returns a list of documentation elements.
+ *
+ * @return a list of documentation elements.
+ */
+ protected CMNodeList getDocumentation()
+ {
+ XSDAnnotation annotation = getXSDElementDeclaration().getAnnotation();
+ return getDocumentations(annotation);
+ }
+
+ /**
+ * Returns the corresponding XML Schema type definition.
+ *
+ * @return the corresponding XML Schema type definition.
+ */
+ protected abstract XSDTypeDefinition getXSDType();
+
+ /**
+ * Returns a list of type names.
+ *
+ * @return a list of type names.
+ */
+ protected abstract List getXSITypes();
+
+ /**
+ * Return the element declaration corresponding to the given uri qualified
+ * type name.
+ *
+ * @param uriQualifiedTypeName -
+ * a uri qualified type name
+ * @return corresponding element declaration.
+ */
+ protected abstract CMElementDeclaration getDerivedElementDeclaration(String uriQualifiedTypeName);
+
+ /**
+ * Returns a list of documentation elements.
+ *
+ * @return a list of documentation elements.
+ */
+ protected void addXSITypeAttribute(CMNamedNodeMapImpl map)
+ {
+ List list = getXSITypes();
+ int listSize = list.size();
+ if (listSize > 1)
+ {
+ CMDataType dataType = new CMDataTypeImpl("typeNames", (String) null);
+ CMAttributeDeclarationImpl attribute = new CMAttributeDeclarationImpl("type", CMAttributeDeclaration.OPTIONAL, dataType);
+ attribute.setCMDocument(xsiDocument);
+ attribute.setPrefixQualification(true);
+ attribute.setXSITypes(list);
+ map.getHashtable().put(attribute.getNodeName(), attribute);
+ }
+ }
+
+ /**
+ * Returns the cmdocument that is the owner of this cmnode.
+ *
+ * @return the cmdocument corresponding to this cmnode.
+ */
+ public CMDocument getCMDocument()
+ {
+ return (CMDocument) getAdapter(getResolvedXSDElementDeclaration().getSchema());
+ }
+
+ /**
+ * Returns the substitution group for this element. The group consists of:
+ * 1. the element declaration itself 2. and any element declaration that has
+ * a {substitution group affiliation} in the group
+ *
+ * @return the substitution group for this element.
+ */
+ protected abstract CMNodeListImpl getSubstitutionGroup();
+ /*
+ * XSDElementDeclarationAdapter.DataTypeImpl An inner class to hold type
+ * information for this element.
+ */
+ public class DataTypeImpl implements CMDataType
+ {
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return CMNode.DATA_TYPE;
+ }
+
+ /**
+ * Returns the name of the element type. Same as getDataTypeName().
+ *
+ * @return the name of the element type.
+ */
+ public String getNodeName()
+ {
+ return getDataTypeName();
+ }
+
+ /**
+ * Returns false. This class does not support any properties.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return false.
+ */
+ public boolean supports(String propertyName)
+ {
+ return false;
+ }
+
+ /**
+ * Returns null. This class does not support any properties.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return null.
+ */
+ public Object getProperty(String propertyName)
+ {
+ return null;
+ }
+
+ /**
+ * Returns the name of the element type. Same as getNodeName().
+ *
+ * @return the name of the element type.
+ */
+ public String getDataTypeName()
+ {
+ String typeName = null;
+ XSDSimpleTypeDefinition std = getXSDType().getSimpleType();
+ if (std != null)
+ typeName = std.getName();
+ return typeName != null ? typeName : "string";
+ }
+
+ /**
+ * Returns the kind of constraint: none, default or fixed. The kinds are
+ * defined in CMDataType class (IMPLIED_VALUE_NONE, IMPLIED_VALUE_FIXED or
+ * IMPLIED_VALUE_DEFAULT).
+ *
+ * @return the kind of constraint: none, default or fixed.
+ */
+ public int getImpliedValueKind()
+ {
+ int result = IMPLIED_VALUE_NONE;
+ if (getXSDElementDeclaration().isSetConstraint())
+ {
+ if (getXSDElementDeclaration().getConstraint().getValue() == XSDConstraint.DEFAULT)
+ result = IMPLIED_VALUE_DEFAULT;
+ else if (getXSDElementDeclaration().getConstraint().getValue() == XSDConstraint.FIXED)
+ result = IMPLIED_VALUE_FIXED;
+ }
+ return result;
+ }
+
+ /**
+ * Returns the value of the default or fixed constraint.
+ *
+ * @return the value of the default or fixed constraint.
+ */
+ public String getImpliedValue()
+ {
+ String result = null;
+ if (getXSDElementDeclaration().isSetConstraint())
+ {
+ result = getXSDElementDeclaration().getLexicalValue();
+ }
+ return result;
+ }
+
+ /**
+ * Returns the enumerated values for the attribute type.
+ *
+ * @return the enumerated values for the attribute type.
+ */
+ public String[] getEnumeratedValues()
+ {
+ return getEnumeratedValuesForType(getXSDType());
+ }
+
+ public String generateInstanceValue()
+ {
+ return XSDTypeUtil.getInstanceValue(getXSDType());
+ }
+
+ /**
+ * Returns the cmdocument that is the owner of this cmnode.
+ *
+ * @return the cmdocument corresponding to this cmnode.
+ */
+ public CMDocument getCMDocument()
+ {
+ return (CMDocument) getAdapter(getXSDElementDeclaration().getSchema());
+ }
+ }
+ }
+ /**
+ * XSDElementDeclarationAdapter implements CMElementDeclaration. A
+ * representation of the model object 'Element Declaration'.
+ */
+ public static class XSDElementDeclarationAdapter extends ElementDeclarationBaseImpl
+ {
+ protected List derivedElementDeclarations = null;
+ protected List xsiTypes = null;
+ protected XSDElementDeclaration xsdElementDeclaration;
+ protected CMNodeListImpl substitutionGroup;
+
+ /**
+ * Constructor.
+ *
+ * @param xsdElementDeclaration -
+ * the XML Schema node.
+ */
+ public XSDElementDeclarationAdapter(XSDElementDeclaration xsdElementDeclaration)
+ {
+ this.xsdElementDeclaration = xsdElementDeclaration;
+ }
+
+ /**
+ * Returns corresponding XML Schema element declaration.
+ *
+ * @return corresponding XML Schema element declaration.
+ */
+ protected XSDElementDeclaration getXSDElementDeclaration()
+ {
+ return xsdElementDeclaration;
+ }
+
+ /**
+ * Returns corresponding XML Schema element declaration.
+ *
+ * @return corresponding XML Schema element declaration.
+ */
+ protected XSDElementDeclaration getResolvedXSDElementDeclaration()
+ {
+ return xsdElementDeclaration.getResolvedElementDeclaration();
+ }
+
+ /**
+ * Returns the key for this cmnode which is the corresponding XML Schema
+ * node.
+ *
+ * @return the key for this cmnode.
+ */
+ public Object getKey()
+ {
+ return xsdElementDeclaration;
+ }
+
+ /**
+ * Returns the referenced element declaration if this is an element
+ * reference. Otherwise it returns itself.
+ *
+ * @return an element declaration.
+ */
+ public CMNode getDefinition()
+ {
+ return getAdapter(xsdElementDeclaration.getResolvedElementDeclaration());
+ }
+
+ /**
+ * Returns a string indicating whether the element declaration is global or
+ * local. Returns null if this is an element reference.
+ *
+ * @return a string indicating whether the element declaration is global or
+ * local.
+ */
+ protected String getDefinitionInfo()
+ {
+ if (xsdElementDeclaration.isElementDeclarationReference())
+ return null;
+ else if (xsdElementDeclaration.isGlobal())
+ return DEFINITION_INFO_GLOBAL;
+ else
+ return DEFINITION_INFO_LOCAL;
+ }
+
+ public Object getNSPrefixQualification()
+ {
+ String form = null;
+ if (xsdElementDeclaration.isElementDeclarationReference())
+ {
+ form = "qualified";
+ }
+ else
+ {
+ if (xsdElementDeclaration.isSetForm())
+ {
+ form = xsdElementDeclaration.getForm().getName();
+ }
+ else
+ {
+ XSDSchema schema = xsdElementDeclaration.getSchema();
+ if (schema != null)
+ form = schema.getElementFormDefault().getName();
+ }
+ }
+ return form;
+ }
+
+ /**
+ * Returns the corresponding XML Schema type definition.
+ *
+ * @return the corresponding XML Schema type definition.
+ */
+ protected XSDTypeDefinition getXSDType()
+ {
+ return xsdElementDeclaration.getResolvedElementDeclaration().getTypeDefinition();
+ }
+
+ /**
+ * Returns a list of type names.
+ *
+ * @return a list of type names.
+ */
+ protected List getXSITypes()
+ {
+ if (xsiTypes == null)
+ {
+ computeDerivedTypeInfo();
+ }
+ return xsiTypes;
+ }
+
+ protected void computeDerivedTypeInfo()
+ {
+ xsiTypes = new Vector();
+ derivedElementDeclarations = new Vector();
+ computeDerivedTypeInfoHelper(getXSDType(), xsiTypes, derivedElementDeclarations);
+ }
+
+ protected void computeDerivedTypeInfoHelper(XSDTypeDefinition type, List typeNameList, List edList)
+ {
+ if (type instanceof XSDComplexTypeDefinition)
+ {
+ List derivedTypes = findTypesDerivedFrom(type);
+ ArrayList inclusiveDerivedTypes = new ArrayList();
+ inclusiveDerivedTypes.add(type);
+ if ((derivedTypes != null) && (derivedTypes.size() > 0))
+ {
+ inclusiveDerivedTypes.addAll(derivedTypes);
+ }
+ for (Iterator i = inclusiveDerivedTypes.iterator(); i.hasNext();)
+ {
+ XSDTypeDefinition derivedType = (XSDTypeDefinition) i.next();
+ XSDSchema schema = derivedType.getSchema();
+ if (schema != null)
+ {
+ String uri = schema.getTargetNamespace();
+ String name = derivedType.getName();
+ if (name != null)
+ {
+ name = uri != null ? ("[" + uri + "]" + name) : name;
+ typeNameList.add(name);
+ DerivedElementDeclarationImpl ed = new DerivedElementDeclarationImpl(this, derivedType, name);
+ edList.add(ed);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Return the element declaration corresponding to the given uri qualified
+ * type name.
+ *
+ * @param uriQualifiedTypeName -
+ * a uri qualified type name
+ * @return corresponding element declaration.
+ */
+ protected CMElementDeclaration getDerivedElementDeclaration(String uriQualifiedTypeName)
+ {
+ CMElementDeclaration result = null;
+ if (derivedElementDeclarations == null)
+ {
+ computeDerivedTypeInfo();
+ }
+ for (Iterator i = derivedElementDeclarations.iterator(); i.hasNext();)
+ {
+ DerivedElementDeclarationImpl ed = (DerivedElementDeclarationImpl) i.next();
+ if ((ed != null) && (ed.uriQualifiedTypeName != null))
+ {
+ if (ed.uriQualifiedTypeName.equals(uriQualifiedTypeName))
+ {
+ result = ed;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns the substitution group for this element. The group consists of:
+ * 1. the element declaration itself 2. and any element declaration that has
+ * a {substitution group affiliation} in the group
+ *
+ * @return the substitution group for this element.
+ */
+ protected CMNodeListImpl getSubstitutionGroup()
+ {
+ if (substitutionGroup == null)
+ {
+ substitutionGroup = new CMNodeListImpl();
+ List sgroup = getResolvedXSDElementDeclaration().getSubstitutionGroup();
+ for (Iterator i = sgroup.iterator(); i.hasNext();)
+ {
+ XSDElementDeclaration ed = (XSDElementDeclaration) i.next();
+ substitutionGroup.add(getAdapter(ed));
+ }
+ }
+ return substitutionGroup;
+ }
+ }
+ /**
+ * DerivedElementDeclarationImpl extends ElementDeclarationBaseImpl
+ *
+ */
+ public static class DerivedElementDeclarationImpl extends ElementDeclarationBaseImpl
+ {
+ protected XSDElementDeclarationAdapter owner;
+ protected XSDTypeDefinition xsdType;
+ public String uriQualifiedTypeName;
+
+ /**
+ * Constructor.
+ *
+ * @param owner -
+ * @param xsdType -
+ * @param uriQualifiedTypeName -
+ */
+ public DerivedElementDeclarationImpl(XSDElementDeclarationAdapter owner, XSDTypeDefinition xsdType, String uriQualifiedTypeName)
+ {
+ this.owner = owner;
+ this.xsdType = xsdType;
+ this.uriQualifiedTypeName = uriQualifiedTypeName;
+ }
+
+ /**
+ * Returns corresponding XML Schema element declaration.
+ *
+ * @return corresponding XML Schema element declaration.
+ */
+ protected XSDElementDeclaration getXSDElementDeclaration()
+ {
+ return (XSDElementDeclaration) owner.getKey();
+ }
+
+ /**
+ * Returns corresponding XML Schema element declaration.
+ *
+ * @return corresponding XML Schema element declaration.
+ */
+ protected XSDElementDeclaration getResolvedXSDElementDeclaration()
+ {
+ return ((XSDElementDeclaration) owner.getKey()).getResolvedElementDeclaration();
+ }
+
+ /**
+ * Returns the key for this cmnode which is the corresponding XML Schema
+ * node.
+ *
+ * @return the key for this cmnode.
+ */
+ public Object getKey()
+ {
+ return owner.getKey();
+ }
+
+ /**
+ * Returns the corresponding XML Schema type definition.
+ *
+ * @return the corresponding XML Schema type definition.
+ */
+ protected XSDTypeDefinition getXSDType()
+ {
+ return xsdType;
+ }
+
+ /**
+ * Returns a list of type names.
+ *
+ * @return a list of type names.
+ */
+ protected List getXSITypes()
+ {
+ return owner.getXSITypes();
+ }
+
+ /**
+ * Return the element declaration corresponding to the given uri qualified
+ * type name.
+ *
+ * @param uriQualifiedTypeName -
+ * a uri qualified type name
+ * @return corresponding element declaration.
+ */
+ protected CMElementDeclaration getDerivedElementDeclaration(String uriQualifiedTypeName)
+ {
+ return owner.getDerivedElementDeclaration(uriQualifiedTypeName);
+ }
+
+ /**
+ * Returns the referenced element declaration if this is an element
+ * reference. Otherwise it returns itself.
+ *
+ * @return an element declaration.
+ */
+ protected CMNode getDefinition()
+ {
+ return this;
+ }
+
+ /**
+ * Returns a string indicating whether the element declaration is global or
+ * local. Returns null if this is an element reference.
+ *
+ * @return a string indicating whether the element declaration is global or
+ * local.
+ */
+ protected String getDefinitionInfo()
+ {
+ return owner.getDefinitionInfo();
+ }
+
+ /*
+ * Returns the value of the form [attribute] which affects the target
+ * namespace of locally scoped features. @return the value of the form
+ * [attribute].
+ */
+ public Object getNSPrefixQualification()
+ {
+ return owner.getNSPrefixQualification();
+ }
+
+ /**
+ * Returns the substitution group for this element. The group consists of:
+ * 1. the element declaration itself 2. and any element declaration that has
+ * a {substitution group affiliation} in the group
+ *
+ * @return the substitution group for this element.
+ */
+ protected CMNodeListImpl getSubstitutionGroup()
+ {
+ return owner.getSubstitutionGroup();
+ }
+ }
+ /**
+ * XSDWildcardAdapter
+ */
+ public static class XSDWildcardAdapter extends XSDBaseAdapter implements CMAnyElement
+ {
+ protected XSDWildcard xsdWildcard;
+
+ public XSDWildcardAdapter(XSDWildcard xsdWildcard)
+ {
+ this.xsdWildcard = xsdWildcard;
+ }
+
+ /**
+ * Returns the key for this cmnode which is the corresponding XML Schema
+ * node.
+ *
+ * @return the key for this cmnode.
+ */
+ public Object getKey()
+ {
+ return xsdWildcard;
+ }
+
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return ANY_ELEMENT;
+ }
+
+ /**
+ * Returns the name of the node. The default value is an empty string value.
+ * All derived classes must override this method if they do not want the
+ * default value.
+ *
+ * @return the name of the node.
+ */
+ public String getNodeName()
+ {
+ return "any";
+ }
+
+ public String getNamespaceURI()
+ {
+ String uri = xsdWildcard.getElement().getAttribute("namespace");
+ return (uri != null || uri.length() == 0) ? uri : "##any";
+ }
+
+ /**
+ * Returns the value of 'Min Occurs' attribute. The default value is "1".
+ *
+ * @return the value of the 'Min Occurs' attribute.
+ */
+ public int getMinOccur()
+ {
+ return getMinOccurs(xsdWildcard);
+ }
+
+ /**
+ * Returns the value of the 'Max Occurs' attribute. The default value is
+ * "1".
+ *
+ * @return the value of the 'Max Occurs' attribute.
+ */
+ public int getMaxOccur()
+ {
+ return getMaxOccurs(xsdWildcard);
+ }
+
+ /**
+ * Returns the cmdocument that is the owner of this cmnode.
+ *
+ * @return the cmdocument corresponding to this cmnode.
+ */
+ public CMDocument getCMDocument()
+ {
+ return (CMDocument) getAdapter(xsdWildcard.getSchema());
+ }
+
+ /**
+ * Returns a list of documentation elements.
+ *
+ * @return a list of documentation elements.
+ */
+ protected CMNodeList getDocumentation()
+ {
+ XSDAnnotation annotation = xsdWildcard.getAnnotation();
+ return getDocumentations(annotation);
+ }
+ }
+ /**
+ * XSDModelGroupAdapter
+ */
+ public static class XSDModelGroupAdapter extends XSDBaseAdapter implements CMGroup
+ {
+ protected XSDModelGroup xsdModelGroup;
+
+ public XSDModelGroupAdapter()
+ {
+ }
+
+ public XSDModelGroupAdapter(XSDModelGroup xsdModelGroup)
+ {
+ this.xsdModelGroup = xsdModelGroup;
+ }
+
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return GROUP;
+ }
+
+ /**
+ * Returns the key for this cmnode which is the corresponding XML Schema
+ * node.
+ *
+ * @return the key for this cmnode.
+ */
+ public Object getKey()
+ {
+ return xsdModelGroup;
+ }
+
+ /**
+ * Returns a list of the children of this group.
+ *
+ * @return a list of the children of this group.
+ */
+ public CMNodeList getChildNodes()
+ {
+ CMNodeListImpl nodeList = new CMNodeListImpl();
+ if (xsdModelGroup != null)
+ {
+ for (Iterator i = xsdModelGroup.getParticles().iterator(); i.hasNext();)
+ {
+ XSDParticle particle = (XSDParticle) i.next();
+ XSDParticleContent content = particle.getContent();
+ CMNode adapter = getAdapter(content);
+ if (adapter != null)
+ {
+ nodeList.getList().add(adapter);
+ }
+ }
+ }
+ return nodeList;
+ }
+
+ /**
+ * Returns the name of the node. The default value is an empty string value.
+ * All derived classes must override this method if they do not want the
+ * default value.
+ *
+ * @return the name of the node.
+ */
+ public String getNodeName()
+ {
+ CMDescriptionBuilder descriptionBuilder = new CMDescriptionBuilder();
+ return descriptionBuilder.buildDescription(this);
+ }
+
+ /**
+ * Returns the value of 'Min Occurs' attribute. The default value is "1".
+ *
+ * @return the value of the 'Min Occurs' attribute.
+ */
+ public int getMinOccur()
+ {
+ return getMinOccurs(xsdModelGroup);
+ }
+
+ /**
+ * Returns the value of the 'Max Occurs' attribute. The default value is
+ * "1".
+ *
+ * @return the value of the 'Max Occurs' attribute.
+ */
+ public int getMaxOccur()
+ {
+ return getMaxOccurs(xsdModelGroup);
+ }
+
+ /**
+ * Return operator of this group -- CHOICE, SEQUENCE or ALL value.
+ *
+ * @return the operator of this group.
+ */
+ public int getOperator()
+ {
+ int result = 0;
+ //todo... handle ALONE case by checkig if child count == 1
+ if (xsdModelGroup != null)
+ {
+ switch (xsdModelGroup.getCompositor().getValue())
+ {
+ case XSDCompositor.CHOICE : {
+ result = CHOICE;
+ break;
+ }
+ case XSDCompositor.SEQUENCE : {
+ result = SEQUENCE;
+ break;
+ }
+ case XSDCompositor.ALL : {
+ result = ALL;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns a list of documentation elements.
+ *
+ * @return a list of documentation elements.
+ */
+ protected CMNodeList getDocumentation()
+ {
+ XSDAnnotation annotation = xsdModelGroup.getAnnotation();
+ return getDocumentations(annotation);
+ }
+
+ /**
+ * Returns the cmdocument that is the owner of this cmnode.
+ *
+ * @return the cmdocument corresponding to this cmnode.
+ */
+ public CMDocument getCMDocument()
+ {
+ return (CMDocument) getAdapter(xsdModelGroup.getSchema());
+ }
+ }
+ /**
+ * XSDModelGroupDefinitionAdapter
+ */
+ public static class XSDModelGroupDefinitionAdapter extends XSDBaseAdapter implements CMGroup
+ {
+ protected XSDModelGroupDefinition xsdModelGroupDefinition;
+
+ public XSDModelGroupDefinitionAdapter(XSDModelGroupDefinition xsdModelGroupDefinition)
+ {
+ this.xsdModelGroupDefinition = xsdModelGroupDefinition;
+ }
+
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return GROUP;
+ }
+
+ /**
+ * Returns the key for this cmnode which is the corresponding XML Schema
+ * node.
+ *
+ * @return the key for this cmnode.
+ */
+ public Object getKey()
+ {
+ return xsdModelGroupDefinition;
+ }
+
+ /**
+ * Returns a list of the children of this group.
+ *
+ * @return a list of the children of this group.
+ */
+ public CMNodeList getChildNodes()
+ {
+ CMNodeListImpl nodeList = new CMNodeListImpl();
+ XSDModelGroup modelGroup = xsdModelGroupDefinition.getResolvedModelGroupDefinition().getModelGroup();
+ if (modelGroup != null)
+ {
+ CMNode adapter = getAdapter(modelGroup);
+ nodeList.add(adapter);
+ }
+ return nodeList;
+ }
+
+ /**
+ * Returns the name of the node. The default value is an empty string value.
+ * All derived classes must override this method if they do not want the
+ * default value.
+ *
+ * @return the name of the node.
+ */
+ public String getNodeName()
+ {
+ CMDescriptionBuilder descriptionBuilder = new CMDescriptionBuilder();
+ return descriptionBuilder.buildDescription(this);
+ }
+
+ /**
+ * Returns the value of 'Min Occurs' attribute. The default value is "1".
+ *
+ * @return the value of the 'Min Occurs' attribute.
+ */
+ public int getMinOccur()
+ {
+ return getMinOccurs(xsdModelGroupDefinition);
+ }
+
+ /**
+ * Returns the value of the 'Max Occurs' attribute. The default value is
+ * "1".
+ *
+ * @return the value of the 'Max Occurs' attribute.
+ */
+ public int getMaxOccur()
+ {
+ return getMaxOccurs(xsdModelGroupDefinition);
+ }
+
+ /**
+ * Return operator of this group -- CHOICE, SEQUENCE or ALL value.
+ *
+ * @return the operator of this group.
+ */
+ public int getOperator()
+ {
+ return XSDCompositor.SEQUENCE;
+ }
+
+ /**
+ * Returns a list of documentation elements.
+ *
+ * @return a list of documentation elements.
+ */
+ protected CMNodeList getDocumentation()
+ {
+ XSDAnnotation annotation = xsdModelGroupDefinition.getAnnotation();
+ return getDocumentations(annotation);
+ }
+
+ /**
+ * Returns the cmdocument that is the owner of this cmnode.
+ *
+ * @return the cmdocument corresponding to this cmnode.
+ */
+ public CMDocument getCMDocument()
+ {
+ return (CMDocument) getAdapter(xsdModelGroupDefinition.getSchema());
+ }
+ }
+ /**
+ * DocumentationImpl implements CMDocumentation. A representation of the
+ * documentation element part of the 'User Information' feature. Working with
+ * the documentation element requires dropping down into the DOM model.
+ */
+ public static class DocumentationImpl implements CMDocumentation
+ {
+ protected Element documentation;
+
+ /**
+ * Constructor.
+ *
+ * @param documentation -
+ * a documentation element.
+ */
+ public DocumentationImpl(Element documentation)
+ {
+ this.documentation = documentation;
+ }
+
+ /**
+ * Returns the type of the node. The types are defined in CMNode class
+ * (ANY_ELEMENT, ATTRIBUTE_DECLARATION, DATA_TYPE, DOCUMENT,
+ * ELEMENT_DECLARATION, ENTITY_DECLARATION, GROUP, NAME_SPACE or
+ * DOCUMENTATION).
+ *
+ * @return the type of this node.
+ */
+ public int getNodeType()
+ {
+ return DOCUMENTATION;
+ }
+
+ /**
+ * Returns an empty string value.
+ *
+ * @return an empty string value.
+ */
+ public String getNodeName()
+ {
+ return "";
+ }
+
+ /**
+ * Returns false. This class does not support any properties.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return false.
+ */
+ public boolean supports(String propertyName)
+ {
+ return false;
+ }
+
+ /**
+ * Returns null. This class does not support any properties.
+ *
+ * @param propertyName -
+ * name of a property
+ * @return null.
+ */
+ public Object getProperty(String propertyName)
+ {
+ return null;
+ }
+
+ /**
+ * Returns the content of the documentation element.
+ *
+ * @return the content of the documentation element.
+ */
+ public String getValue()
+ {
+ String content = "";
+ boolean contentFound = false;
+ NodeList nodes = documentation.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++)
+ {
+ Node node = nodes.item(i);
+ if (node instanceof Text)
+ {
+ contentFound = true;
+ content += node.getNodeValue();
+ }
+ }
+ return contentFound ? content : null;
+ }
+
+ /**
+ * Returns the xml:lang attribute value of the documentation element.
+ *
+ * @return the xml:lang attribute value of the documentation element.
+ */
+ public String getLanguage()
+ {
+ return documentation.hasAttributeNS(XSDConstants.XML_NAMESPACE_URI_1998, XML_LANG_ATTRIBUTE) ? documentation.getAttributeNS(XSDConstants.XML_NAMESPACE_URI_1998, XML_LANG_ATTRIBUTE) : null;
+ }
+
+ /**
+ * Returns the source attribute value of the documentation element.
+ *
+ * @return the source attribute value of the documentation element.
+ */
+ public String getSource()
+ {
+ return documentation.hasAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) ? documentation.getAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) : null;
+ }
+ }
+ /**
+ * XSIDocument extends CMDocumentImpl. This class is used to hold those
+ * attributes that are for direct use in any XML documents. These attributes
+ * are in a different namespace, which has the namespace name
+ * http://www.w3.org/2001/XMLSchema-instance. Attributes in this namespace
+ * include: xsi:type xsi:nil xsi:schemaLocation xsi:noNamespaceSchemaLocation
+ */
+ public static class XSIDocument extends CMDocumentImpl
+ {
+ public CMAttributeDeclarationImpl nilAttribute;
+
+ /**
+ * Constructor. Creates the 'xsi:nil'
+ */
+ public XSIDocument()
+ {
+ super(XSDConstants.SCHEMA_INSTANCE_URI_2001);
+ // create the 'nill' attribute
+ String[] values = {"false", "true"};
+ nilAttribute = new CMAttributeDeclarationImpl("nil", CMAttributeDeclaration.REQUIRED, new CMDataTypeImpl("boolean", values));
+ nilAttribute.setPrefixQualification(true);
+ nilAttribute.setCMDocument(this);
+ }
+ }
+ /**
+ * Note this XSD model visitor differs from the XSD model visitor in
+ * org.eclipse.wst.xsd.editor plugin. In visitModelGroup method we call
+ * getParticles() instead of getContents(). This gathers all of the content of
+ * a derived type.
+ */
+ public static class XSDCMVisitor extends XSDVisitor
+ {
+ public void visitSimpleTypeDefinition(XSDSimpleTypeDefinition type)
+ {
+ XSDParticle ctd = type.getComplexType();
+ if (ctd != null)
+ visitParticle(ctd);
+ }
+
+ public void visitModelGroup(XSDModelGroup modelGroup)
+ {
+ if (modelGroup.getParticles() != null)
+ {
+ for (Iterator iterator = modelGroup.getParticles().iterator(); iterator.hasNext();)
+ {
+ XSDParticle particle = (XSDParticle) iterator.next();
+ visitParticle(particle);
+ }
+ }
+ }
+
+ public void visitModelGroupDefinition(XSDModelGroupDefinition modelGroupDef)
+ {
+ XSDModelGroup modelGroup = modelGroupDef.getResolvedModelGroupDefinition().getModelGroup();
+ if (modelGroup != null)
+ {
+ visitModelGroup(modelGroup);
+ }
+ }
+ }
+ /**
+ * A visitor class that walks the xsd model and computes the list of children
+ * that belong to the initially visited element type.
+ */
+ public static class DerivedChildVisitor extends XSDCMVisitor
+ {
+ protected CMNodeListImpl childNodeList = new CMNodeListImpl();
+ protected List baseTypeList = new Vector();
+ Object root;
+
+ DerivedChildVisitor(Object root)
+ {
+ this.root = root;
+ }
+
+ public CMNodeListImpl getChildNodeList()
+ {
+ return childNodeList;
+ }
+
+ public void visitWildcard(XSDWildcard wildcard)
+ {
+ childNodeList.getList().add(getAdapter(wildcard));
+ }
+
+ public void visitElementDeclaration(XSDElementDeclaration element)
+ {
+ childNodeList.getList().add(getAdapter(element));
+ }
+
+ public void visitModelGroup(XSDModelGroup modelGroup)
+ {
+ childNodeList.getList().add(getAdapter(modelGroup));
+ }
+
+ public void visitModelGroupDefinition(XSDModelGroupDefinition modelGroupDefinition)
+ {
+ childNodeList.getList().add(getAdapter(modelGroupDefinition));
+ }
+ }
+ /**
+ * A visitor class that gathers all of the elements within a type definition.
+ */
+ public static class LocalElementVisitor extends XSDCMVisitor
+ {
+ protected CMNamedNodeMapImpl namedNodeMap = new CMNamedNodeMapImpl();
+ protected List baseTypeList = new Vector();
+
+ public void visitElementDeclaration(XSDElementDeclaration element)
+ {
+ XSDElementDeclarationAdapter adapter = (XSDElementDeclarationAdapter) getAdapter(element);
+ namedNodeMap.getHashtable().put(adapter.getNodeName(), adapter);
+ }
+
+ public CMNamedNodeMap getCMNamedNodeMap()
+ {
+ return namedNodeMap;
+ }
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDTypeUtil.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDTypeUtil.java
new file mode 100644
index 0000000..3946868
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDTypeUtil.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.xsd.XSDSimpleTypeDefinition;
+import org.eclipse.xsd.XSDTypeDefinition;
+
+/**
+ * Helper class to generate valid values for built-in simple types.
+ */
+
+public class XSDTypeUtil
+{
+ protected static Map defaultValue = new HashMap();
+
+ public static void initialize()
+ {
+ defaultValue.put("anySimpleType", null);
+ defaultValue.put("anyType", null);
+ defaultValue.put("anyURI", "http://tempuri.org");
+ defaultValue.put("base64Binary", "0");
+ defaultValue.put("boolean", "true");
+ defaultValue.put("byte", "0");
+ defaultValue.put("date", "2001-01-01");
+ defaultValue.put("dateTime", "2001-12-31T12:00:00");
+ defaultValue.put("decimal", "0.0");
+ defaultValue.put("double", "0.0");
+ defaultValue.put("duration", "P1D");
+ defaultValue.put("ENTITY", "entity");
+ defaultValue.put("ENTITIES", "entities");
+ defaultValue.put("float", "0.0");
+ defaultValue.put("gDay", "---01");
+ defaultValue.put("gMonth", "--01--");
+ defaultValue.put("gMonthDay", "--01-01");
+ defaultValue.put("gYear", "2001");
+ defaultValue.put("gYearMonth", "2001-01");
+ defaultValue.put("hexBinary", "0F00");
+ defaultValue.put("ID", null);
+ defaultValue.put("IDREF", null);
+ defaultValue.put("IDREFS", null);
+ defaultValue.put("int", "0");
+ defaultValue.put("integer", "0");
+ defaultValue.put("language", "EN");
+ defaultValue.put("long", "0");
+ defaultValue.put("Name", "Name");
+ defaultValue.put("NCName", "NCName");
+ defaultValue.put("negativeInteger", "-1");
+ defaultValue.put("NMTOKEN", "NMTOKEN");
+ defaultValue.put("NMTOKENS", "NMTOKENS");
+ defaultValue.put("nonNegativeInteger", "0");
+ defaultValue.put("nonPositiveInteger", "0");
+ defaultValue.put("normalizedString", null);
+ defaultValue.put("NOTATION", "NOTATION");
+ defaultValue.put("positiveInteger", "1");
+ defaultValue.put("QName", "QName");
+ defaultValue.put("short", "0");
+ defaultValue.put("string", null);
+ defaultValue.put("time", "12:00:00");
+ defaultValue.put("token", "token");
+ defaultValue.put("unsignedByte", "0");
+ defaultValue.put("unsignedInt", "0");
+ defaultValue.put("unsignedLong", "0");
+ defaultValue.put("unsignedShort", "0");
+ }
+
+
+ /*
+ * Returns true if the type is built-in.
+ * @param type - an XSDTypeDefinition object.
+ * @return true if the type is built-in.
+ */
+ public static boolean isBuiltIn(XSDTypeDefinition type)
+ {
+ boolean result = false;
+ if (type instanceof XSDSimpleTypeDefinition)
+ {
+ String name = type.getName();
+ if (name != null)
+ {
+ return defaultValue.containsKey(name);
+ }
+ }
+ return result;
+ }
+
+
+ /**
+ * Returns a valid default value for the simple type.
+ * @param type - a simple built-in type.
+ * @return a valid default value for the simple type.
+ */
+ public static String getInstanceValue(XSDTypeDefinition type)
+ {
+ if (type != null)
+ {
+ if (isBuiltIn(type))
+ {
+ String nameID = type.getName();
+ return (String)defaultValue.get(nameID);
+ }
+ else
+ {
+ XSDTypeDefinition basetype = type.getBaseType();
+ if (basetype != type) return getInstanceValue(basetype);
+ }
+ }
+ return null;
+ }
+}
+
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDVisitor.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDVisitor.java
new file mode 100644
index 0000000..f40e1a4
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDVisitor.java
@@ -0,0 +1,190 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal;
+
+import java.util.Iterator;
+
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDAttributeGroupDefinition;
+import org.eclipse.xsd.XSDComplexTypeContent;
+import org.eclipse.xsd.XSDComplexTypeDefinition;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDIdentityConstraintDefinition;
+import org.eclipse.xsd.XSDModelGroup;
+import org.eclipse.xsd.XSDModelGroupDefinition;
+import org.eclipse.xsd.XSDNotationDeclaration;
+import org.eclipse.xsd.XSDParticle;
+import org.eclipse.xsd.XSDParticleContent;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDSimpleTypeDefinition;
+import org.eclipse.xsd.XSDTypeDefinition;
+import org.eclipse.xsd.XSDWildcard;
+
+public class XSDVisitor
+{
+ public XSDVisitor()
+ {
+ }
+
+ protected XSDSchema schema;
+
+ public void visitSchema(XSDSchema schema)
+ {
+ this.schema = schema;
+ for (Iterator iterator = schema.getAttributeDeclarations().iterator(); iterator.hasNext();)
+ {
+ XSDAttributeDeclaration attr = (XSDAttributeDeclaration) iterator.next();
+ visitAttributeDeclaration(attr);
+ }
+ for (Iterator iterator = schema.getTypeDefinitions().iterator(); iterator.hasNext();)
+ {
+ XSDTypeDefinition type = (XSDTypeDefinition) iterator.next();
+ visitTypeDefinition(type);
+ }
+ for (Iterator iterator = schema.getElementDeclarations().iterator(); iterator.hasNext();)
+ {
+ XSDElementDeclaration element = (XSDElementDeclaration) iterator.next();
+ visitElementDeclaration(element);
+ }
+ for (Iterator iterator = schema.getIdentityConstraintDefinitions().iterator(); iterator.hasNext();)
+ {
+ XSDIdentityConstraintDefinition identityConstraint = (XSDIdentityConstraintDefinition) iterator.next();
+ visitIdentityConstraintDefinition(identityConstraint);
+ }
+ for (Iterator iterator = schema.getModelGroupDefinitions().iterator(); iterator.hasNext();)
+ {
+ XSDModelGroupDefinition modelGroup = (XSDModelGroupDefinition) iterator.next();
+ visitModelGroupDefinition(modelGroup);
+ }
+ for (Iterator iterator = schema.getAttributeGroupDefinitions().iterator(); iterator.hasNext();)
+ {
+ XSDAttributeGroupDefinition attributeGroup = (XSDAttributeGroupDefinition) iterator.next();
+ visitAttributeGroupDefinition(attributeGroup);
+ }
+ for (Iterator iterator = schema.getNotationDeclarations().iterator(); iterator.hasNext();)
+ {
+ XSDNotationDeclaration element = (XSDNotationDeclaration) iterator.next();
+ visitNotationDeclaration(element);
+ }
+
+ }
+
+ public void visitAttributeDeclaration(XSDAttributeDeclaration attr)
+ {
+ }
+
+ public void visitTypeDefinition(XSDTypeDefinition type)
+ {
+ if (type instanceof XSDSimpleTypeDefinition)
+ {
+ visitSimpleTypeDefinition((XSDSimpleTypeDefinition)type);
+ }
+ else if (type instanceof XSDComplexTypeDefinition)
+ {
+ visitComplexTypeDefinition((XSDComplexTypeDefinition)type);
+ }
+ }
+
+ public void visitElementDeclaration(XSDElementDeclaration element)
+ {
+ if (element.isElementDeclarationReference())
+ {
+ }
+ else if (element.getAnonymousTypeDefinition() != null)
+ {
+ visitTypeDefinition(element.getAnonymousTypeDefinition());
+ }
+ }
+
+ public void visitIdentityConstraintDefinition(XSDIdentityConstraintDefinition identityConstraint)
+ {
+ }
+
+ public void visitModelGroupDefinition(XSDModelGroupDefinition modelGroupDef)
+ {
+ if (!modelGroupDef.isModelGroupDefinitionReference())
+ {
+ if (modelGroupDef.getModelGroup() != null)
+ {
+ visitModelGroup(modelGroupDef.getModelGroup());
+ }
+ }
+ }
+
+ public void visitAttributeGroupDefinition(XSDAttributeGroupDefinition attributeGroup)
+ {
+ }
+
+ public void visitNotationDeclaration(XSDNotationDeclaration notation)
+ {
+ }
+
+ public void visitSimpleTypeDefinition(XSDSimpleTypeDefinition type)
+ {
+ }
+
+ public void visitComplexTypeDefinition(XSDComplexTypeDefinition type)
+ {
+ if (type.getContentType() != null)
+ {
+ XSDComplexTypeContent complexContent = type.getContentType();
+ if (complexContent instanceof XSDSimpleTypeDefinition)
+ {
+ visitSimpleTypeDefinition((XSDSimpleTypeDefinition)complexContent);
+ }
+ else if (complexContent instanceof XSDParticle)
+ {
+ visitParticle((XSDParticle) complexContent);
+ }
+ }
+ }
+
+ public void visitParticle(XSDParticle particle)
+ {
+ visitParticleContent(particle.getContent());
+ }
+
+ public void visitParticleContent(XSDParticleContent particleContent)
+ {
+ if (particleContent instanceof XSDModelGroupDefinition)
+ {
+ visitModelGroupDefinition((XSDModelGroupDefinition) particleContent);
+ }
+ else if (particleContent instanceof XSDModelGroup)
+ {
+ visitModelGroup((XSDModelGroup)particleContent);
+ }
+ else if (particleContent instanceof XSDElementDeclaration)
+ {
+ visitElementDeclaration((XSDElementDeclaration)particleContent);
+ }
+ else if (particleContent instanceof XSDWildcard)
+ {
+ visitWildcard((XSDWildcard)particleContent);
+ }
+ }
+
+ public void visitModelGroup(XSDModelGroup modelGroup)
+ {
+ if (modelGroup.getContents() != null)
+ {
+ for (Iterator iterator = modelGroup.getContents().iterator(); iterator.hasNext();)
+ {
+ XSDParticle particle = (XSDParticle) iterator.next();
+ visitParticle(particle);
+ }
+ }
+ }
+
+ public void visitWildcard(XSDWildcard wildcard)
+ {
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/util/XSDSchemaLocatorAdapterFactory.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/util/XSDSchemaLocatorAdapterFactory.java
new file mode 100644
index 0000000..cba5df1
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/util/XSDSchemaLocatorAdapterFactory.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal.util;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
+import org.eclipse.xsd.util.XSDSchemaLocator;
+
+public class XSDSchemaLocatorAdapterFactory extends AdapterFactoryImpl
+{
+ protected XSDSchemaLocatorImpl schemaLocator = new XSDSchemaLocatorImpl();
+
+ public boolean isFactoryForType(Object type)
+ {
+ return type == XSDSchemaLocator.class;
+ }
+
+ public Adapter adaptNew(Notifier target, Object type)
+ {
+ return schemaLocator;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/util/XSDSchemaLocatorImpl.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/util/XSDSchemaLocatorImpl.java
new file mode 100644
index 0000000..68001e0
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/util/XSDSchemaLocatorImpl.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.contentmodel.internal.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.util.XSDResourceImpl;
+import org.eclipse.xsd.util.XSDSchemaLocator;
+
+public class XSDSchemaLocatorImpl extends AdapterImpl implements XSDSchemaLocator
+{
+ /**
+ * @see org.eclipse.xsd.util.XSDSchemaLocator#locateSchema(org.eclipse.xsd.XSDSchema,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ public XSDSchema locateSchema(XSDSchema xsdSchema, String namespaceURI, String rawSchemaLocationURI, String resolvedSchemaLocationURI)
+ {
+ XSDSchema result = null;
+ String baseLocation = xsdSchema.getSchemaLocation();
+ String resolvedURI = URIResolverPlugin.createResolver().resolve(baseLocation, namespaceURI, rawSchemaLocationURI);
+ if (resolvedURI == null)
+ {
+ resolvedURI = resolvedSchemaLocationURI;
+ }
+ try
+ {
+ ResourceSet resourceSet = xsdSchema.eResource().getResourceSet();
+ URI uri = URI.createURI(resolvedURI);
+ Resource r = resourceSet.getResource(uri, false);
+ XSDResourceImpl resolvedResource = null;
+ if (r instanceof XSDResourceImpl)
+ {
+ resolvedResource = (XSDResourceImpl)r;
+ }
+ else
+ {
+ InputStream inputStream = resourceSet.getURIConverter().createInputStream(uri);
+ resolvedResource = (XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd"));
+ resolvedResource.setURI(uri);
+ resolvedResource.load(inputStream, null);
+ }
+
+ result = resolvedResource.getSchema();
+ }
+ catch (IOException exception)
+ {
+ // It is generally not an error to fail to resolve.
+ // If a resource is actually created,
+ // which happens only when we can create an input stream,
+ // then it's an error if it's not a good schema
+ }
+ return result;
+ }
+
+ public boolean isAdatperForType(Object type)
+ {
+ return type == XSDSchemaLocator.class;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/XSDValidator.java b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/XSDValidator.java
new file mode 100644
index 0000000..f1de6f3
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/XSDValidator.java
@@ -0,0 +1,369 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.validation.internal;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.xerces.parsers.SAXParser;
+import org.apache.xerces.xni.XMLResourceIdentifier;
+import org.apache.xerces.xni.XNIException;
+import org.apache.xerces.xni.parser.XMLEntityResolver;
+import org.apache.xerces.xni.parser.XMLInputSource;
+import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
+import org.eclipse.wst.xml.validation.internal.core.ValidationInfo;
+import org.eclipse.wst.xml.validation.internal.core.ValidationReport;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+
+/**
+ * The XSDValidator will validate XSD files.
+ *
+ * @author Lawrence Mandel, IBM
+ */
+public class XSDValidator
+{
+
+ private final boolean WRAPPER_ERROR_SUPPORT_ENABLED = true;
+
+ private final String XML_INSTANCE_DOC_TOP = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<root \n"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
+
+ private final String XML_INSTANCE_DOC_MID = " xsi:noNamespaceSchemaLocation=\"";
+
+ private final String XML_INSTANCE_DOC_BOT = "\">\n" + "</root>\n";
+
+ private final String DUMMY_URI = "http://example.org/dummy";
+
+ private URIResolver uriresolver = null;
+
+ public ValidationReport validate(String uri)
+ {
+ return validate(uri, null);
+ }
+
+ /**
+ * Validate the XSD file specified by the URI.
+ *
+ * @param uri
+ * The URI of the XSD file to validate.
+ */
+ public ValidationReport validate(String uri, InputStream inputStream)
+ {
+ ValidationInfo valinfo = new ValidationInfo(uri);
+ try
+ {
+ String ns = null;
+ String schemaLocationString = "";
+
+ URL url = new URL(uri);
+ if (url != null)
+ {
+ BufferedReader bufreader = new BufferedReader(new InputStreamReader(url.openStream()));
+
+ if (bufreader != null)
+ {
+ String source = "";
+ while (bufreader.ready())
+ {
+ source += bufreader.readLine();
+ }
+ bufreader.close();
+ int tn = source.indexOf("targetNamespace");
+ if (tn != -1)
+ {
+ int firstquote = source.indexOf("\"", tn) + 1;
+ int secondquote = source.indexOf("\"", firstquote);
+ ns = source.substring(firstquote, secondquote);
+ }
+ }
+ bufreader.close();
+ }
+
+ XSDErrorHandler errorHandler = new XSDErrorHandler(valinfo);
+ try
+ {
+ String instanceDoc = XML_INSTANCE_DOC_TOP;
+ if (ns != null && !ns.equals(""))
+ {
+ instanceDoc += " xmlns=\"" + ns + "\"\n";
+ instanceDoc += " xsi:schemaLocation=\"";
+ instanceDoc += ns;
+ instanceDoc += " ";
+ } else
+ {
+ instanceDoc += " xsi:noNamespaceSchemaLocation=\"";
+ }
+ instanceDoc += uri.replaceAll(" ", "%20");
+ if (!schemaLocationString.equals(""))
+ {
+ instanceDoc += " " + schemaLocationString;
+ }
+ instanceDoc += XML_INSTANCE_DOC_BOT;
+ InputSource is = new InputSource(new StringReader(instanceDoc));
+ is.setSystemId(DUMMY_URI);
+
+ String soapFile = "platform:/plugin/org.eclipse.wst.wsdl.validation./xsd/xml-soap.xsd";
+ XMLReader reader = new SAXParser();
+ try
+ {
+ reader.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
+ reader.setFeature("http://xml.org/sax/features/namespaces", true);
+ reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+ reader.setFeature("http://xml.org/sax/features/validation", true);
+ reader.setFeature("http://apache.org/xml/features/validation/schema", true);
+ reader.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
+ reader.setFeature("http://xml.org/sax/features/external-general-entities", true);
+ reader.setFeature("http://xml.org/sax/features/external-parameter-entities", true);
+ reader.setFeature("http://apache.org/xml/features/validation/warn-on-duplicate-attdef", true);
+
+ reader.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
+ "http://xml.apache.org/xml-soap " + soapFile);
+ reader.setErrorHandler(errorHandler);
+
+ if (uriresolver != null)
+ {
+ XSDEntityResolver resolver = new XSDEntityResolver(uriresolver, uri, inputStream);
+ try
+ {
+ reader.setProperty("http://apache.org/xml/properties/internal/entity-resolver", resolver);
+ }
+ catch (Exception e)
+ {
+ reader.setEntityResolver(resolver);
+ }
+ }
+
+ reader.parse(is);
+
+ } catch (SAXException e)
+ {
+ //LoggerFactory.getLoggerInstance().logError("XSD Validator Exception: ", e);
+ }
+ } catch (IOException except)
+ {
+ //LoggerFactory.getLoggerInstance().logError("XSD Validator Exception: ", except);
+ }
+ } catch (Exception e)
+ {
+ //LoggerFactory.getLoggerInstance().logError("XSD Validator Exception: ", e);
+ }
+
+ return valinfo;
+ }
+
+ /**
+ * Set the URI resolver to use with XSD validation.
+ *
+ * @param uriresolver
+ * The URI resolver to use.
+ */
+ public void setURIResolver(URIResolver uriresolver)
+ {
+ this.uriresolver = uriresolver;
+ }
+
+ /**
+ * The XSDErrorHandler handle Xerces parsing errors and puts the errors
+ * into the given ValidationInfo object.
+ *
+ * @author Lawrence Mandel, IBM
+ */
+ protected class XSDErrorHandler implements org.xml.sax.ErrorHandler
+ {
+
+ private final int ERROR = 0;
+
+ private final int WARNING = 1;
+
+ private final ValidationInfo valinfo;
+
+ public XSDErrorHandler(ValidationInfo valinfo)
+ {
+ this.valinfo = valinfo;
+ }
+
+ /**
+ * Add a validation message with the given severity.
+ *
+ * @param exception The exception that contains the information about the message.
+ * @param severity The severity of the validation message.
+ */
+ protected void addValidationMessage(SAXParseException exception, int severity)
+ {
+ // get the error key by taking the substring of what is before the ':' in the error message:
+ String errorKey = exception.getLocalizedMessage();
+ if (errorKey != null)
+ {
+ int index = errorKey.indexOf(':');
+ if (index != -1)
+ { errorKey = errorKey.substring(0, index);
+ }
+ }
+
+ if (exception.getSystemId() != null && !exception.getSystemId().equals(DUMMY_URI))
+ {
+ if (severity == WARNING)
+ {
+ valinfo.addWarning(exception.getLocalizedMessage(), exception.getLineNumber(), exception.getColumnNumber(), exception.getSystemId());
+ }
+ else
+ {
+ valinfo.addError(exception.getLocalizedMessage(), exception.getLineNumber(), exception.getColumnNumber(), exception.getSystemId(), errorKey, null);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+ */
+ public void error(SAXParseException exception) throws SAXException
+ {
+ addValidationMessage(exception, ERROR);
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+ */
+ public void fatalError(SAXParseException exception) throws SAXException
+ {
+ addValidationMessage(exception, ERROR);
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+ */
+ public void warning(SAXParseException exception) throws SAXException
+ {
+ addValidationMessage(exception, WARNING);
+ }
+ }
+
+ /**
+ * The XSDEntityResolver wraps an idresolver to provide entity resolution to
+ * the XSD validator.
+ *
+ * @author Lawrence Mandel, IBM
+ */
+ protected class XSDEntityResolver implements EntityResolver, XMLEntityResolver
+ {
+ private URIResolver uriresolver = null;
+
+ private String baselocation = null;
+ private InputStream inputStream;
+
+ /**
+ * Constructor.
+ *
+ * @param idresolver
+ * The idresolver this entity resolver wraps.
+ * @param baselocation The base location to resolve with.
+ */
+ public XSDEntityResolver(URIResolver uriresolver, String baselocation, InputStream inputStream)
+ {
+ this.uriresolver = uriresolver;
+ this.baselocation = baselocation;
+ this.inputStream = inputStream;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String,
+ * java.lang.String)
+ */
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
+ {
+ String location = null;
+ if (baselocation.equals(systemId))
+ {
+ location = systemId;
+ }
+ else
+ {
+ location = uriresolver.resolve(baselocation, publicId, systemId);
+ }
+ InputSource is = null;
+ if (location != null && !location.equals(""))
+ {
+ try
+ {
+ URI uri = URI.create(location);
+ URL url = uri.toURL();
+ is = new InputSource(location);
+ is.setByteStream(url.openStream());
+ } catch (MalformedURLException e)
+ {
+ throw new IOException(e.getMessage());
+ }
+ }
+ return is;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xni.parser.XMLEntityResolver#resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier)
+ */
+ public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException
+ {
+ // consider the resourceIdentifier's fields to see we're actually in the dummy xml file
+ // and if this is the reference to the schema we want to validate
+ // ... if so return an XMLInputSource built from the dirty copy of the schema
+ boolean isDummyXML = DUMMY_URI.equals(resourceIdentifier.getBaseSystemId());
+ if (isDummyXML && inputStream != null)
+ {
+ XMLInputSource inputSource = new XMLInputSource(null, resourceIdentifier.getLiteralSystemId(), null, inputStream, null);
+ return inputSource;
+ }
+ else
+ {
+ String publicId = resourceIdentifier.getPublicId();
+ if (publicId == null || publicId.equals(""))
+ {
+ publicId = resourceIdentifier.getNamespace();
+ }
+ String baseSystemId = resourceIdentifier.getBaseSystemId();
+ if (baseSystemId == null)
+ {
+ baseSystemId = baselocation;
+ }
+
+ String location = uriresolver.resolve(baseSystemId, publicId, resourceIdentifier.getLiteralSystemId());
+ XMLInputSource is = null;
+ if (location != null && !location.equals(""))
+ {
+ try
+ {
+ // Xerces only produces file import messages if an IOException
+ // is thrown when resolving a resource. A stream is opened for
+ // the resolved location to allow for these messages by handling
+ // the case where the resource cannot be opened for reading.
+ URL url = new URL(location);
+ is = new XMLInputSource(resourceIdentifier.getPublicId(), location, location);
+ is.setByteStream(url.openStream());
+ } catch (Exception e)
+ {
+ throw new IOException(e.getMessage());
+ }
+ }
+ return is;
+ }
+ }
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/ValidateAction.java b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/ValidateAction.java
new file mode 100644
index 0000000..c3bcdf4
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/ValidateAction.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.xsd.validation.internal.ui.eclipse;
+
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.xml.validation.internal.core.ValidationMessage;
+import org.eclipse.wst.xml.validation.internal.core.ValidationReport;
+
+
+
+/**
+ * This class manages the 'UI' related details of validation. Here's a quick
+ * overview of the details :
+ * - manages Marker creation based on the results of the validation
+ * - (optionally) displays dialog to summarize the results of validation
+ *
+ * @author Lawrence Mandel, IBM
+ * @author Keith Chong, IBM
+ */
+public class ValidateAction extends org.eclipse.wst.xml.validation.internal.core.ValidateAction
+{
+ // Property file strings.
+ private static final String _UI_DIALOG_XML_SCHEMA_INVALID_TEXT = "_UI_DIALOG_XML_SCHEMA_INVALID_TEXT";
+ private static final String _UI_DIALOG_XML_SCHEMA_INVALID_TITLE = "_UI_DIALOG_XML_SCHEMA_INVALID_TITLE";
+ private static final String _UI_VALIDATION_INTERNAL_ERROR = "_UI_VALIDATION_INTERNAL_ERROR";
+ private static final String _UI_DIALOG_XML_SCHEMA_VALID_TITLE = "_UI_DIALOG_XML_SCHEMA_VALID_TITLE";
+ private static final String _UI_DIALOG_XML_SCHEMA_VALID_TEXT = "_UI_DIALOG_XML_SCHEMA_VALID_TEXT";
+ private static final String _UI_MESSAGE_LIMIT_EXCEEDED = "_UI_DIALOG_XML_SCHEMA_LIMITE_EXCEEDED";
+ private static final String _UI_DIALOG_XML_SCHEMA_VALID_WITH_WARNINGS = "_UI_DIALOG_XML_SCHEMA_VALID_WITH_WARNINGS";
+
+ private InputStream inputStream;
+
+ /**
+ * Constructor.
+ *
+ * @param file The file to validate.
+ * @param showDialog Whether or not to show a dialog when validation is complete.
+ */
+ public ValidateAction(IFile file, boolean showDialog)
+ {
+ super(file, showDialog);
+ }
+
+ /*
+ * Store additional information in the message parameters
+ * param[0] = the column number of the error
+ * param[1] = the 'squiggle selection strategy' for which DOM part to squiggle
+ * param[2] = the name or value of what is to be squiggled
+ */
+ protected void addInfoToMessage (ValidationMessage validationMessage, IMessage message)
+ {
+ if (inputStream != null)
+ {
+ XSDMessageInfoHelper messageInfoHelper = new XSDMessageInfoHelper();
+ String[] messageInfo = messageInfoHelper.createMessageInfo(validationMessage.getMessage(), validationMessage.getKey());
+
+ message.setAttribute(COLUMN_NUMBER_ATTRIBUTE, new Integer(validationMessage.getColumnNumber()));
+ message.setAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE, messageInfo[0]);
+ message.setAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE, messageInfo[1]);
+ }
+ }
+
+ protected void validate(final IFile file)
+ {
+ final ValidationOutcome valoutcome = new ValidationOutcome();
+ IPath path = file.getLocation();
+ final String uri = createURIForFilePath(path.toString());
+
+ IWorkspaceRunnable op = new IWorkspaceRunnable()
+ {
+
+ public void run(IProgressMonitor progressMonitor) throws CoreException
+ {
+ clearMarkers(file);
+ XSDValidator validator = XSDValidator.getInstance();
+ ValidationReport valreport = validator.validate(uri, inputStream);
+ valoutcome.isValid = valreport.isValid();
+ if(valreport.getValidationMessages().length == 0)
+ {
+ valoutcome.hasMessages = false;
+ }
+ else
+ {
+ valoutcome.hasMessages = true;
+ }
+ createMarkers(file, valreport.getValidationMessages());
+
+ file.setSessionProperty(ValidationMessage.ERROR_MESSAGE_MAP_QUALIFIED_NAME, valreport.getNestedMessages());
+ }
+ };
+
+ try
+ {
+ ResourcesPlugin.getWorkspace().run(op, null);
+ String internalErrorMessage = null;
+
+ if (showDialog)
+ {
+ if (!valoutcome.isValid)
+ {
+ String message = XSDValidatorManager.getString(_UI_DIALOG_XML_SCHEMA_INVALID_TEXT);
+ String title = XSDValidatorManager.getString(_UI_DIALOG_XML_SCHEMA_INVALID_TITLE);
+ if (internalErrorMessage != null)
+ {
+ message = message + "\n" + internalErrorMessage;
+ }
+ openErrorDialog(title, message);
+ }
+ else if (valoutcome.isValid && valoutcome.hasMessages)
+ {
+ String message = XSDValidatorManager.getString(_UI_DIALOG_XML_SCHEMA_VALID_WITH_WARNINGS);
+ String title = XSDValidatorManager.getString(_UI_DIALOG_XML_SCHEMA_VALID_TITLE);
+ openWarningDialog(title, message);
+ }
+ else
+ {
+ String message = XSDValidatorManager.getString(_UI_DIALOG_XML_SCHEMA_VALID_TEXT);
+ String title = XSDValidatorManager.getString(_UI_DIALOG_XML_SCHEMA_VALID_TITLE);
+ //String message = validator.isGrammarEncountered() ?
+ // XSDValidatorManager.getString("_UI_THE_XML_FILE_IS_VALID") :
+ // XSDValidatorManager.getString("_UI_THE_XML_FILE_IS_WELL_FORMED") +
+ // XSDValidatorManager.getString("_UI_NO_GRAMMAR_WARNING");
+ openValidDialog(title, message);
+ }
+ }
+ }
+
+ catch (CoreException e)
+ {
+ }
+ }
+ public void setInputStream(InputStream inputStream)
+ { this.inputStream = inputStream;
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/ValidateSchemaActionDelegate.java b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/ValidateSchemaActionDelegate.java
new file mode 100644
index 0000000..49ec04c
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/ValidateSchemaActionDelegate.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.xsd.validation.internal.ui.eclipse;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IActionDelegate;
+
+/**
+ * Validate schema - from popup
+ */
+public class ValidateSchemaActionDelegate
+ implements IActionDelegate
+{
+ public static final String copyright = "(c) Copyright IBM Corporation 2002.";
+ protected ISelection selection;
+
+ public void run(IAction action)
+ {
+ try {
+ // CS.. for now the following line tests to ensure the user has xerces jars installed
+ // so that we can perform some 'fail fast' behaviour
+ //
+ Class theClass = Class.forName("org.apache.xerces.xni.parser.XMLParserConfiguration", true, this.getClass().getClassLoader());
+ if (theClass == null)
+ {
+ throw(new Exception("Missing Xerces jars in plugin's 'jars' folder"));
+ }
+
+ IFile fileResource = null;
+ if (!selection.isEmpty() && selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ Object element = structuredSelection.getFirstElement();
+
+ if (element instanceof IFile)
+ {
+ fileResource = (IFile) element;
+ }
+ else
+ {
+ return;
+ }
+ }
+ ValidateAction validateaction = new ValidateAction(fileResource, true);
+ validateaction.setValidator(new Validator());
+ validateaction.run();
+ }
+ catch (Exception e) {
+ // CS..here's where we need to pop up a dialog to tell the user that xerces is not available
+ //
+ String xercesLine1 = "Required files xercesImpl.jar and xmlParserAPIs.jar cannot be found.\n\n";
+ String xercesLine2 = "Download Xerces 2.6.2 and place xercesImpl.jar and xmlParserAPIs.jar in a folder entitled jars in the org.eclipse.wst.xml.validation plugin.\n\n";
+ String xercesLine3 = "For more information see www.eclipse.org/webtools/wst/components/xml/xercesInfo.xml.";
+ MessageDialog.openError(Display.getDefault().getActiveShell(), "Missing Xerces", xercesLine1 + xercesLine2 + xercesLine3);
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection selection)
+ {
+ this.selection = selection;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/Validator.java b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/Validator.java
new file mode 100644
index 0000000..3ad5828
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/Validator.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.xsd.validation.internal.ui.eclipse;
+
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.operations.IRuleGroup;
+import org.eclipse.wst.validation.internal.operations.ValidatorManager;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
+import org.eclipse.wst.validation.internal.provisional.core.IValidator;
+
+
+public class Validator implements IValidator
+{
+ public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
+ private final String GET_FILE = "getFile";
+ public final String GET_PROJECT_FILES = "getAllFiles";
+
+ public void validate(IFile file)
+ {
+ ValidateAction validateAction = new ValidateAction(file, false);
+ validateAction.setValidator(this);
+ validateAction.run();
+ }
+ /**
+ * This is the method which performs the validation on the MOF model.
+ * <br><br>
+ * <code>helper</code> and <code>reporter</code> may not be null. <code>changedFiles</code> may be null, if a full
+ * build is desired.
+ * <br><br>
+ * <code>helper</code> returns the ifile for the given information in the IFileDelta array
+ * <br><br>
+ * <code>reporter</code> is an instance of an IReporter interface, which is used for interaction with the user.
+ * <br><br>
+ * <code>changedFiles</code> is an array of file names which have changed since the last validation.
+ * If <code>changedFiles</code> is null, or if it is an empty array, then a full build
+ * is performed. Otherwise, validation on just the files listed in the Vector is performed.
+ */
+ public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
+ String[] changedFiles = helper.getURIs();
+ if (changedFiles != null && changedFiles.length > 0)
+ {
+ for (int i = 0; i < changedFiles.length; i++)
+ {
+ String fileName = changedFiles[i];
+ if (fileName != null)
+ {
+ Object []parms = {fileName};
+
+ IFile file = (IFile) helper.loadModel(GET_FILE, parms);
+ if (file != null)
+ {
+ //the helper might not have the file stored in it. could have an InputStream
+ if (helper.loadModel("inputStream") instanceof InputStream)
+ {
+ validate(file, (InputStream)helper.loadModel("inputStream"), reporter); //do we need the fileName? what is int ruleGroup?
+ }
+ else
+ {
+ //if (((Helper)helper).isInJavaBuildPath(file) &&
+ // !((AWorkbenchHelper)helper).isInJavaSourcePath(file))
+ //{
+ // continue;
+ //}
+ validateIfNeeded(file, helper, reporter);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ Object []parms = {this.getClass().getName()};
+ Collection files = (Collection) helper.loadModel(GET_PROJECT_FILES, parms);
+ Iterator iter = files.iterator();
+ while (iter.hasNext())
+ {
+ IFile file = (IFile) iter.next();
+ validateIfNeeded(file, helper, reporter);
+ }
+ }
+ }
+
+
+ private void validate(IFile file, InputStream inputStream, IReporter reporter)
+ {
+ ValidateAction validateAction = new ValidateAction(file, false);
+ validateAction.setValidator(this);
+ if (inputStream != null)
+ {
+ validateAction.setInputStream(inputStream);
+ validateAction.setReporter(reporter);
+ }
+ validateAction.run();
+ }
+
+ protected void validateIfNeeded(IFile file, IValidationContext helper, IReporter reporter)
+ {
+ ValidatorManager mgr = ValidatorManager.getManager();
+
+ Integer ruleGroupInt = (Integer)helper.loadModel(IRuleGroup.PASS_LEVEL, null); // pass in a "null" so that loadModel doesn't attempt to cast the result into a RefObject
+ int ruleGroup = (ruleGroupInt == null) ? IRuleGroup.PASS_FULL : ruleGroupInt.intValue();
+
+ Object stream = helper.loadModel("inputStream");
+ if (stream instanceof InputStream)
+ {
+ validate(file, (InputStream)stream, reporter);
+ }
+ else
+ {
+ validate(file, null, reporter);
+ }
+ }
+
+ /**
+ * Unpacks the fileModelPair and returns an IFile object.
+ */
+ //protected IFile getFile(Object object)
+ //{
+ // IFile result = null;
+ // if (object instanceof List)
+ // {
+ // List fileModelPair = (List)object;
+ // if (fileModelPair.size()>0)
+ // {
+ // Object file = fileModelPair.get(0);
+ // if (file instanceof IFile)
+ // {
+ /// result = (IFile)file;
+ // }
+ // }
+ // }
+ // return result;
+ // }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wtp.validation.core.IValidator#cleanup(org.eclipse.wtp.validation.core.IReporter)
+ */
+ public void cleanup(IReporter reporter)
+ {
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDMessageInfoHelper.java b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDMessageInfoHelper.java
new file mode 100644
index 0000000..851b088
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDMessageInfoHelper.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.validation.internal.ui.eclipse;
+
+
+/**
+ * @author Mark Hutchinson
+ *
+ * The XSDMessageInfoHelper creates a string with the
+ */
+public class XSDMessageInfoHelper
+{
+ public XSDMessageInfoHelper()
+ { super();
+ }
+
+ public String[] createMessageInfo(String errorMessage, String errorKey)
+ {
+ //Now map the error key to what we would want to underline:
+ String nameOrValue = "";
+ String selectionStrategy = "";
+ if (errorKey.equals("s4s-elt-invalid-content.1") || errorKey.equals("s4s-elt-must-match.1") || errorKey.equals("s4s-att-must-appear") || errorKey.equals("s4s-elt-invalid-content.2"))
+ { selectionStrategy = "START_TAG";
+ }
+ else if (errorKey.equals("s4s-att-not-allowed"))
+ { selectionStrategy = "ATTRIBUTE_NAME";
+ nameOrValue = getFirstStringBetweenSingleQuotes(errorMessage);
+ }
+ else if (errorKey.equals("s4s-att-invalid-value"))
+ { selectionStrategy = "ATTRIBUTE_VALUE";
+ nameOrValue = getFirstStringBetweenSingleQuotes(errorMessage);
+ }
+ else if (errorKey.equals("s4s-elt-character"))
+ { selectionStrategy = "TEXT";
+ }
+ else if (errorKey.equals("src-resolve.4.2") || errorKey.equals("src-resolve"))
+ { selectionStrategy = "VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE";
+ nameOrValue = getFirstStringBetweenSingleQuotes(errorMessage);
+ }
+ String messageInfo[] = new String[2];
+ messageInfo[0] = selectionStrategy;
+ messageInfo[1] = nameOrValue;
+ return messageInfo;
+ }
+
+ /*
+ * Mark Hutchinson
+ *
+ * This method is used to get the value between the first pair of single quotes
+ * It is used to extract information from the error Message (for example
+ * an attribute name)
+ */
+ private String getFirstStringBetweenSingleQuotes(String s)
+ {
+ int first = s.indexOf("'");
+ int second = s.indexOf("'", first + 1);
+ String betweenQuotes = null;
+ if (first != -1 && second != -1)
+ { betweenQuotes = s.substring(first + 1, second);
+ }
+ return betweenQuotes;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDValidator.java b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDValidator.java
new file mode 100644
index 0000000..3e96943
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDValidator.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.xsd.validation.internal.ui.eclipse;
+
+import java.io.InputStream;
+
+import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
+import org.eclipse.wst.xml.validation.internal.core.ValidationReport;
+
+
+/**
+ * An XSD validator specific to Eclipse. This validator will wrap the internal
+ * XSD validator an provide automatic URI resolver support.
+ * Using this class is equivalent to using the internal XSD validator and registering
+ * the URI resolver.
+ *
+ * @author Lawrence Mandel, IBM
+ */
+public class XSDValidator
+{
+ private static XSDValidator instance = null;
+ private org.eclipse.wst.xsd.validation.internal.XSDValidator validator = null;
+
+ /**
+ * Return the one and only instance of the XSD validator. The validator
+ * can be reused and cannot be customized so there should only be one instance of it.
+ *
+ * @return The one and only instance of the XSD validator.
+ */
+ public static XSDValidator getInstance()
+ {
+ if(instance == null)
+ {
+ instance = new XSDValidator();
+ }
+ return instance;
+ }
+ /**
+ * Constructor. Create the XSD validator and set the URI resolver.
+ */
+ protected XSDValidator()
+ {
+ validator = new org.eclipse.wst.xsd.validation.internal.XSDValidator();
+ validator.setURIResolver(URIResolverPlugin.createResolver());
+ }
+ /**
+ * Validate the file at the given URI.
+ *
+ * @param uri The URI of the file to validate.
+ */
+ /*public ValidationReport validate(String uri)
+ {
+ return validator.validate(uri);
+ }*/
+ public ValidationReport validate(String uri, InputStream inputStream)
+ {
+ return validator.validate(uri, inputStream);
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDValidatorManager.java b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDValidatorManager.java
new file mode 100644
index 0000000..30f07c3
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src-validation/org/eclipse/wst/xsd/validation/internal/ui/eclipse/XSDValidatorManager.java
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.xsd.validation.internal.ui.eclipse;
+
+import java.io.IOException;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.wst.xsd.core.internal.XSDCorePlugin;
+
+public class XSDValidatorManager extends AbstractUIPlugin
+{
+ public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
+ protected static XSDValidatorManager plugin;
+
+ public XSDValidatorManager(IPluginDescriptor descriptor)
+ {
+ super(descriptor);
+ plugin = this;
+
+ }
+
+ /**
+ * Copy the w3c XMLSchema.dtd and datatypes.dtd into the plugin metadata directory
+ * for validation purposes
+ */
+ public void startup()
+ {
+ //ModelManagerPlugin plugin = (ModelManagerPlugin) Platform.getPlugin(ModelManagerPlugin.ID);
+ //modelManager = plugin.getModelManager();
+ }
+
+ //private static ModelManager modelManager;
+ //public static ModelManager getModelManager()
+ //{
+ // return modelManager;
+ //}
+
+ /**
+ * Get the Install URL
+ */
+ public static URL getInstallURL()
+ {
+ return XSDCorePlugin.getDefault().getDescriptor().getInstallURL();
+ }
+
+ /**
+ * Return the plugin physical directory location
+ */
+ public static IPath getPluginLocation()
+ {
+ try
+ {
+ IPath installPath = new Path(getInstallURL().toExternalForm()).removeTrailingSeparator();
+ String installStr = Platform.asLocalURL(new URL(installPath.toString())).getFile();
+ return new Path(installStr);
+ }
+ catch (IOException e)
+ {
+
+ }
+ return null;
+ }
+
+ /**
+ * Get the metadata directory for this plugin
+ */
+ //public static String getMetaDataDirectory()
+ //{
+ // return getPlugin().getStateLocation().toOSString();
+ //}
+
+ /**
+ * Get the one xmlschema package.
+ */
+// public XMLSchemaPackage getXMLSchemaPackage()
+// {
+// return xmlschemaPackage;
+// }
+
+// /**
+// * Get the one xmlschema factory.
+// */
+// public XMLSchemaFactory getXMLSchemaFactory()
+// {
+// return (XMLSchemaFactory)xmlschemaPackage.getEFactoryInstance();
+// }
+
+ /**
+ * Get the singleton instance.
+ */
+ public static XSDValidatorManager getInstance()
+ {
+ return plugin;
+ }
+
+
+ //public static Image getXSDImage(String iconName)
+ //{
+ // return getPlugin().getImage(iconName);
+ //}
+
+ /**
+ * Get resource string
+ */
+ public static String getString(String key)
+ {
+ return XSDCorePlugin.getDefault().getDescriptor().getResourceBundle().getString(key);
+ }
+
+ /**
+ * Get resource string
+ */
+ public static String getString(String key, String arg0)
+ {
+ return MessageFormat.format(getString(key), new Object [] { arg0 });
+ }
+
+ /**
+ * Get resource string
+ */
+ public static String getString(String key, String arg0, String arg1)
+ {
+ return MessageFormat.format(getString(key), new Object [] { arg0, arg1 });
+ }
+ public IWorkspace getWorkspace()
+ {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ //public static Shell getShell()
+ //{
+ // return getPlugin().getWorkbench().getActiveWorkbenchWindow().getShell();
+ //}
+
+ /**
+ * Get the xml schema default namespace prefix
+ */
+ //public String getXMLSchemaPrefix()
+ //{
+ // return getPreferenceStore().getString(CONST_XSD_DEFAULT_PREFIX_TEXT);
+ //}
+
+ /**
+ * Get the xml schema language qualification
+ */
+ //public boolean isQualifyXMLSchemaLanguage()
+ //{
+ // return getPreferenceStore().getBoolean(CONST_XSD_LANGUAGE_QUALIFY);
+ //}
+
+
+
+ public static final String CONST_XSD_DEFAULT_PREFIX_TEXT = "org.eclipse.wst.xmlschema.xsdDefaultPrefixText";
+ public static final String CONST_XSD_LANGUAGE_QUALIFY = "org.eclipse.wst.xmlschema.xsdQualify";
+
+
+}
diff --git a/bundles/org.eclipse.wst.xsd.core/src/org/eclipse/wst/xsd/core/internal/XSDCorePlugin.java b/bundles/org.eclipse.wst.xsd.core/src/org/eclipse/wst/xsd/core/internal/XSDCorePlugin.java
new file mode 100644
index 0000000..ab2fe3a
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.core/src/org/eclipse/wst/xsd/core/internal/XSDCorePlugin.java
@@ -0,0 +1,59 @@
+package org.eclipse.wst.xsd.core.internal;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.wst.xsd.contentmodel.internal.XSDCMManager;
+import org.eclipse.wst.xsd.contentmodel.internal.XSDTypeUtil;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class XSDCorePlugin extends Plugin {
+ //The shared instance.
+ private static XSDCorePlugin plugin;
+
+ /**
+ * The constructor.
+ */
+ public XSDCorePlugin() {
+ super();
+ plugin = this;
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ XSDCMManager.getInstance().startup();
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ plugin = null;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static XSDCorePlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path.
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.wst.xsd.core", path);
+ }
+}