Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 2002-2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM - Initial API and implementation
*/
package org.eclipse.xsd.util;
import java.util.HashSet;
import java.util.Set;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
import org.eclipse.xsd.XSDTypeDefinition;
/**
* The Constants for XML and XML Schema and related DOM Utilities.
*/
public class XSDConstants
{
/**
* The value "http://www.w3.org/TR/xmlschema-1/".
*/
public static final String PART1 = "http://www.w3.org/TR/xmlschema-1/";
/**
* The value "http://www.w3.org/TR/xmlschema-2/".
*/
public static final String PART2 = "http://www.w3.org/TR/xmlschema-2/";
/**
* The value "http://www.w3.org/XML/1998/namespace".
*/
public static final String XML_NAMESPACE_URI_1998 = "http://www.w3.org/XML/1998/namespace";
/**
* The value "http://www.w3.org/2000/xmlns/".
*/
public static final String XMLNS_URI_2000 = "http://www.w3.org/2000/xmlns/";
/**
* The value http://www.w3.org/1999/XMLSchema".
*/
public static final String SCHEMA_FOR_SCHEMA_URI_1999 = "http://www.w3.org/1999/XMLSchema";
/**
* The value "http://www.w3.org/2000/10/XMLSchema".
*/
public static final String SCHEMA_FOR_SCHEMA_URI_2000_10 = "http://www.w3.org/2000/10/XMLSchema";
/**
* The value "http://www.w3.org/2001/XMLSchema".
*/
public static final String SCHEMA_FOR_SCHEMA_URI_2001 = "http://www.w3.org/2001/XMLSchema";
/**
* The value "http://www.w3.org/2001/XMLSchema-instance".
*/
public static final String SCHEMA_INSTANCE_URI_2001 = "http://www.w3.org/2001/XMLSchema-instance";
/**
* Returns whether the given namespace is (one of) the XML namespace(s).
* @param namespace a namespace.
* @return whether the given namespace is (one of) the XML namespace(s).
*/
public static boolean isXMLNamespace(String namespace)
{
return
XML_NAMESPACE_URI_1998.equals(namespace);
}
/**
* Returns whether the given namespace is (one of) the XMLNS namespace(s).
* @param namespace a namespace.
* @return whether the given namespace is (one of) the XMLNS namespace(s).
*/
public static boolean isXMLNSNamespace(String namespace)
{
return
XMLNS_URI_2000.equals(namespace);
}
/**
* Returns whether the given namespace is one of the XML Schema for Schema namespaces.
* @param namespace a namespace.
* @return whether the given namespace is one of the XML Schema for Schema namespaces.
*/
public static boolean isSchemaForSchemaNamespace(String namespace)
{
return
SCHEMA_FOR_SCHEMA_URI_2001.equals(namespace) ||
SCHEMA_FOR_SCHEMA_URI_2000_10.equals(namespace) ||
SCHEMA_FOR_SCHEMA_URI_1999.equals(namespace);
}
/**
* Returns whether the given namespace is (one of) the XML Schema Instance namespace(s).
* @param namespace a namespace.
* @return whether the given namespace is (one of) the XML Schema Instance namespace(s).
*/
public static boolean isSchemaInstanceNamespace(String namespace)
{
return
SCHEMA_INSTANCE_URI_2001.equals(namespace);
}
//
// all
// annotation
// any
// anyAttribute
// appinfo
// attribute
// attributeGroup
// choice
// complexContent
// complexType
// documentation
// element
// enumeration
// extension
// field
// fractionDigits
// group
// import
// include
// key
// keyref
// length
// list
// maxExclusive
// maxInclusive
// maxLength
// minExclusive
// minInclusive
// minLength
// notation
// pattern
// redefine
// restriction
// schema
// selector
// sequence
// simpleContent
// simpleType
// totalDigits
// union
// unique
// whiteSpace
// (
// for i in $(cat elements); do
// j=$(echo $i | tr '[:lower:]' '[:upper:]');
// echo ' /**';
// echo ' * The value "'$i'".';
// echo ' * @see #'$j'_ELEMENT';
// echo ' * @see #ELEMENT_TAGS';
// echo ' * @see #nodeType(String)';
// echo ' */';
// echo ' public final static String '$j'_ELEMENT_TAG = "'$i'";';
// echo '';
// done;
// k=0;
// for i in $(cat elements); do
// j=$(echo $i | tr '[:lower:]' '[:upper:]');
// echo ' /**';
// echo ' * The value '$k'.';
// echo ' * @see #'$j'_ELEMENT_TAG';
// echo ' * @see #ELEMENT_TAGS';
// echo ' * @see #nodeType(String)';
// echo ' */';
// echo ' public final static int '$j'_ELEMENT = '$k';';
// echo '';
// k=$(($k+1));
// done;
// echo ' /**';
// echo ' * The sorted strings representing all XML Schema element tags.';
// echo ' * @see #nodeType(String)';
// echo ' * @see #nodeType(Node)';
// echo ' */';
// echo ' public static final String [] ELEMENT_TAGS =';
// echo ' new String []';
// echo ' {';
// for i in $(cat elements); do
// j=$(echo $i | tr '[:lower:]' '[:upper:]');
// echo ' '$j'_ELEMENT_TAG,';
// done;
// echo ' };';
// )
/**
* The value "all".
* @see #ALL_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String ALL_ELEMENT_TAG = "all";
/**
* The value "annotation".
* @see #ANNOTATION_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String ANNOTATION_ELEMENT_TAG = "annotation";
/**
* The value "any".
* @see #ANY_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String ANY_ELEMENT_TAG = "any";
/**
* The value "anyAttribute".
* @see #ANYATTRIBUTE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String ANYATTRIBUTE_ELEMENT_TAG = "anyAttribute";
/**
* The value "appinfo".
* @see #APPINFO_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String APPINFO_ELEMENT_TAG = "appinfo";
/**
* The value "attribute".
* @see #ATTRIBUTE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String ATTRIBUTE_ELEMENT_TAG = "attribute";
/**
* The value "attributeGroup".
* @see #ATTRIBUTEGROUP_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String ATTRIBUTEGROUP_ELEMENT_TAG = "attributeGroup";
/**
* The value "choice".
* @see #CHOICE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String CHOICE_ELEMENT_TAG = "choice";
/**
* The value "complexContent".
* @see #COMPLEXCONTENT_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String COMPLEXCONTENT_ELEMENT_TAG = "complexContent";
/**
* The value "complexType".
* @see #COMPLEXTYPE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String COMPLEXTYPE_ELEMENT_TAG = "complexType";
/**
* The value "documentation".
* @see #DOCUMENTATION_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String DOCUMENTATION_ELEMENT_TAG = "documentation";
/**
* The value "element".
* @see #ELEMENT_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String ELEMENT_ELEMENT_TAG = "element";
/**
* The value "enumeration".
* @see #ENUMERATION_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String ENUMERATION_ELEMENT_TAG = "enumeration";
/**
* The value "extension".
* @see #EXTENSION_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String EXTENSION_ELEMENT_TAG = "extension";
/**
* The value "field".
* @see #FIELD_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String FIELD_ELEMENT_TAG = "field";
/**
* The value "fractionDigits".
* @see #FRACTIONDIGITS_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String FRACTIONDIGITS_ELEMENT_TAG = "fractionDigits";
/**
* The value "group".
* @see #GROUP_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String GROUP_ELEMENT_TAG = "group";
/**
* The value "import".
* @see #IMPORT_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String IMPORT_ELEMENT_TAG = "import";
/**
* The value "include".
* @see #INCLUDE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String INCLUDE_ELEMENT_TAG = "include";
/**
* The value "key".
* @see #KEY_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String KEY_ELEMENT_TAG = "key";
/**
* The value "keyref".
* @see #KEYREF_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String KEYREF_ELEMENT_TAG = "keyref";
/**
* The value "length".
* @see #LENGTH_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String LENGTH_ELEMENT_TAG = "length";
/**
* The value "list".
* @see #LIST_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String LIST_ELEMENT_TAG = "list";
/**
* The value "maxExclusive".
* @see #MAXEXCLUSIVE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String MAXEXCLUSIVE_ELEMENT_TAG = "maxExclusive";
/**
* The value "maxInclusive".
* @see #MAXINCLUSIVE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String MAXINCLUSIVE_ELEMENT_TAG = "maxInclusive";
/**
* The value "maxLength".
* @see #MAXLENGTH_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String MAXLENGTH_ELEMENT_TAG = "maxLength";
/**
* The value "minExclusive".
* @see #MINEXCLUSIVE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String MINEXCLUSIVE_ELEMENT_TAG = "minExclusive";
/**
* The value "minInclusive".
* @see #MININCLUSIVE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String MININCLUSIVE_ELEMENT_TAG = "minInclusive";
/**
* The value "minLength".
* @see #MINLENGTH_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String MINLENGTH_ELEMENT_TAG = "minLength";
/**
* The value "notation".
* @see #NOTATION_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String NOTATION_ELEMENT_TAG = "notation";
/**
* The value "pattern".
* @see #PATTERN_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String PATTERN_ELEMENT_TAG = "pattern";
/**
* The value "redefine".
* @see #REDEFINE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String REDEFINE_ELEMENT_TAG = "redefine";
/**
* The value "restriction".
* @see #RESTRICTION_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String RESTRICTION_ELEMENT_TAG = "restriction";
/**
* The value "schema".
* @see #SCHEMA_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String SCHEMA_ELEMENT_TAG = "schema";
/**
* The value "selector".
* @see #SELECTOR_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String SELECTOR_ELEMENT_TAG = "selector";
/**
* The value "sequence".
* @see #SEQUENCE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String SEQUENCE_ELEMENT_TAG = "sequence";
/**
* The value "simpleContent".
* @see #SIMPLECONTENT_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String SIMPLECONTENT_ELEMENT_TAG = "simpleContent";
/**
* The value "simpleType".
* @see #SIMPLETYPE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String SIMPLETYPE_ELEMENT_TAG = "simpleType";
/**
* The value "totalDigits".
* @see #TOTALDIGITS_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String TOTALDIGITS_ELEMENT_TAG = "totalDigits";
/**
* The value "union".
* @see #UNION_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String UNION_ELEMENT_TAG = "union";
/**
* The value "unique".
* @see #UNIQUE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String UNIQUE_ELEMENT_TAG = "unique";
/**
* The value "whiteSpace".
* @see #WHITESPACE_ELEMENT
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static String WHITESPACE_ELEMENT_TAG = "whiteSpace";
/**
* The value 0.
* @see #ALL_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int ALL_ELEMENT = 0;
/**
* The value 1.
* @see #ANNOTATION_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int ANNOTATION_ELEMENT = 1;
/**
* The value 2.
* @see #ANY_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int ANY_ELEMENT = 2;
/**
* The value 3.
* @see #ANYATTRIBUTE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int ANYATTRIBUTE_ELEMENT = 3;
/**
* The value 4.
* @see #APPINFO_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int APPINFO_ELEMENT = 4;
/**
* The value 5.
* @see #ATTRIBUTE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int ATTRIBUTE_ELEMENT = 5;
/**
* The value 6.
* @see #ATTRIBUTEGROUP_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int ATTRIBUTEGROUP_ELEMENT = 6;
/**
* The value 7.
* @see #CHOICE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int CHOICE_ELEMENT = 7;
/**
* The value 8.
* @see #COMPLEXCONTENT_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int COMPLEXCONTENT_ELEMENT = 8;
/**
* The value 9.
* @see #COMPLEXTYPE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int COMPLEXTYPE_ELEMENT = 9;
/**
* The value 10.
* @see #DOCUMENTATION_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int DOCUMENTATION_ELEMENT = 10;
/**
* The value 11.
* @see #ELEMENT_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int ELEMENT_ELEMENT = 11;
/**
* The value 12.
* @see #ENUMERATION_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int ENUMERATION_ELEMENT = 12;
/**
* The value 13.
* @see #EXTENSION_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int EXTENSION_ELEMENT = 13;
/**
* The value 14.
* @see #FIELD_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int FIELD_ELEMENT = 14;
/**
* The value 15.
* @see #FRACTIONDIGITS_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int FRACTIONDIGITS_ELEMENT = 15;
/**
* The value 16.
* @see #GROUP_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int GROUP_ELEMENT = 16;
/**
* The value 17.
* @see #IMPORT_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int IMPORT_ELEMENT = 17;
/**
* The value 18.
* @see #INCLUDE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int INCLUDE_ELEMENT = 18;
/**
* The value 19.
* @see #KEY_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int KEY_ELEMENT = 19;
/**
* The value 20.
* @see #KEYREF_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int KEYREF_ELEMENT = 20;
/**
* The value 21.
* @see #LENGTH_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int LENGTH_ELEMENT = 21;
/**
* The value 22.
* @see #LIST_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int LIST_ELEMENT = 22;
/**
* The value 23.
* @see #MAXEXCLUSIVE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int MAXEXCLUSIVE_ELEMENT = 23;
/**
* The value 24.
* @see #MAXINCLUSIVE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int MAXINCLUSIVE_ELEMENT = 24;
/**
* The value 25.
* @see #MAXLENGTH_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int MAXLENGTH_ELEMENT = 25;
/**
* The value 26.
* @see #MINEXCLUSIVE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int MINEXCLUSIVE_ELEMENT = 26;
/**
* The value 27.
* @see #MININCLUSIVE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int MININCLUSIVE_ELEMENT = 27;
/**
* The value 28.
* @see #MINLENGTH_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int MINLENGTH_ELEMENT = 28;
/**
* The value 29.
* @see #NOTATION_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int NOTATION_ELEMENT = 29;
/**
* The value 30.
* @see #PATTERN_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int PATTERN_ELEMENT = 30;
/**
* The value 31.
* @see #REDEFINE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int REDEFINE_ELEMENT = 31;
/**
* The value 32.
* @see #RESTRICTION_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int RESTRICTION_ELEMENT = 32;
/**
* The value 33.
* @see #SCHEMA_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int SCHEMA_ELEMENT = 33;
/**
* The value 34.
* @see #SELECTOR_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int SELECTOR_ELEMENT = 34;
/**
* The value 35.
* @see #SEQUENCE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int SEQUENCE_ELEMENT = 35;
/**
* The value 36.
* @see #SIMPLECONTENT_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int SIMPLECONTENT_ELEMENT = 36;
/**
* The value 37.
* @see #SIMPLETYPE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int SIMPLETYPE_ELEMENT = 37;
/**
* The value 38.
* @see #TOTALDIGITS_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int TOTALDIGITS_ELEMENT = 38;
/**
* The value 39.
* @see #UNION_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int UNION_ELEMENT = 39;
/**
* The value 40.
* @see #UNIQUE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int UNIQUE_ELEMENT = 40;
/**
* The value 41.
* @see #WHITESPACE_ELEMENT_TAG
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public final static int WHITESPACE_ELEMENT = 41;
/**
* The sorted strings representing all
* XML Schema element tags.
* @see #nodeType(String)
* @see #nodeType(Node)
*/
public static final String [] ELEMENT_TAGS =
new String []
{
ALL_ELEMENT_TAG,
ANNOTATION_ELEMENT_TAG,
ANY_ELEMENT_TAG,
ANYATTRIBUTE_ELEMENT_TAG,
APPINFO_ELEMENT_TAG,
ATTRIBUTE_ELEMENT_TAG,
ATTRIBUTEGROUP_ELEMENT_TAG,
CHOICE_ELEMENT_TAG,
COMPLEXCONTENT_ELEMENT_TAG,
COMPLEXTYPE_ELEMENT_TAG,
DOCUMENTATION_ELEMENT_TAG,
ELEMENT_ELEMENT_TAG,
ENUMERATION_ELEMENT_TAG,
EXTENSION_ELEMENT_TAG,
FIELD_ELEMENT_TAG,
FRACTIONDIGITS_ELEMENT_TAG,
GROUP_ELEMENT_TAG,
IMPORT_ELEMENT_TAG,
INCLUDE_ELEMENT_TAG,
KEY_ELEMENT_TAG,
KEYREF_ELEMENT_TAG,
LENGTH_ELEMENT_TAG,
LIST_ELEMENT_TAG,
MAXEXCLUSIVE_ELEMENT_TAG,
MAXINCLUSIVE_ELEMENT_TAG,
MAXLENGTH_ELEMENT_TAG,
MINEXCLUSIVE_ELEMENT_TAG,
MININCLUSIVE_ELEMENT_TAG,
MINLENGTH_ELEMENT_TAG,
NOTATION_ELEMENT_TAG,
PATTERN_ELEMENT_TAG,
REDEFINE_ELEMENT_TAG,
RESTRICTION_ELEMENT_TAG,
SCHEMA_ELEMENT_TAG,
SELECTOR_ELEMENT_TAG,
SEQUENCE_ELEMENT_TAG,
SIMPLECONTENT_ELEMENT_TAG,
SIMPLETYPE_ELEMENT_TAG,
TOTALDIGITS_ELEMENT_TAG,
UNION_ELEMENT_TAG,
UNIQUE_ELEMENT_TAG,
WHITESPACE_ELEMENT_TAG
};
/**
* Returns the index of the element type,
* if it is an XML Schema element tag, or -1.
* @return the index of the element type.
* @see #ELEMENT_TAGS
* @see #nodeType(Node)
*/
public static final int nodeType(String localName)
{
for (int i = 0; i < ELEMENT_TAGS.length; ++i)
{
if (localName.equals(ELEMENT_TAGS[i]))
{
return i;
}
}
return -1;
}
/**
* Returns the index of the node's element type,
* if it is an XML Schema element tag, or -1.
* @return the index of the node's element type.
* @see #ELEMENT_TAGS
* @see #nodeType(String)
*/
public static final int nodeType(Node node)
{
return
isSchemaForSchemaNamespace(node.getNamespaceURI()) ?
nodeType(node.getLocalName()) :
-1;
}
/**
* Returns the URI representation of the node's namespace URI and local name,
* i.e., #.
* @return the URI representation of the node's namespace URI and local name.
*/
public static final String uri(Node node)
{
String namespaceURI = node.getNamespaceURI();
if (namespaceURI == null)
{
namespaceURI = "";
}
return namespaceURI + "#" + node.getLocalName();
}
// abstract
// attributeFormDefault
// base
// block
// blockDefault
// default
// elementFormDefault
// final
// finalDefault
// fixed
// form
// id
// itemType
// maxOccurs
// memberTypes
// minOccurs
// mixed
// name
// namespace
// nillable
// processContents
// public
// ref
// refer
// schemaLocation
// source
// substitutionGroup
// system
// targetNamespace
// type
// use
// value
// version
// xpath
// (
// for i in $(cat attributes); do
// j=$(echo $i | tr '[:lower:]' '[:upper:]');
// echo ' /**';
// echo ' * The value "'$i'"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.';
// echo ' * @see #ELEMENT_TAGS';
// echo ' */';
// echo ' public final static String '$j'_ATTRIBUTE = "'$i'";';
// echo '';
// done;
// )
/**
* The value "abstract"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String ABSTRACT_ATTRIBUTE = "abstract";
/**
* The value "attributeFormDefault"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String ATTRIBUTEFORMDEFAULT_ATTRIBUTE = "attributeFormDefault";
/**
* The value "base"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String BASE_ATTRIBUTE = "base";
/**
* The value "block"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String BLOCK_ATTRIBUTE = "block";
/**
* The value "blockDefault"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String BLOCKDEFAULT_ATTRIBUTE = "blockDefault";
/**
* The value "defRef"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String DEFREF_ATTRIBUTE = "defRef";
/**
* The value "default"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String DEFAULT_ATTRIBUTE = "default";
/**
* The value "elementFormDefault"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String ELEMENTFORMDEFAULT_ATTRIBUTE = "elementFormDefault";
/**
* The value "final"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String FINAL_ATTRIBUTE = "final";
/**
* The value "finalDefault"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String FINALDEFAULT_ATTRIBUTE = "finalDefault";
/**
* The value "fixed"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String FIXED_ATTRIBUTE = "fixed";
/**
* The value "form"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String FORM_ATTRIBUTE = "form";
/**
* The value "id"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String ID_ATTRIBUTE = "id";
/**
* The value "itemType"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String ITEMTYPE_ATTRIBUTE = "itemType";
/**
* The value "maxOccurs"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String MAXOCCURS_ATTRIBUTE = "maxOccurs";
/**
* The value "memberTypes"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String MEMBERTYPES_ATTRIBUTE = "memberTypes";
/**
* The value "minOccurs"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String MINOCCURS_ATTRIBUTE = "minOccurs";
/**
* The value "mixed"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String MIXED_ATTRIBUTE = "mixed";
/**
* The value "name"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String NAME_ATTRIBUTE = "name";
/**
* The value "namespace"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String NAMESPACE_ATTRIBUTE = "namespace";
/**
* The value "nillable"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String NILLABLE_ATTRIBUTE = "nillable";
/**
* The value "occurs"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String OCCURS_ATTRIBUTE = "occurs";
/**
* The value "processContents"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String PROCESSCONTENTS_ATTRIBUTE = "processContents";
/**
* The value "public"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String PUBLIC_ATTRIBUTE = "public";
/**
* The value "ref"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String REF_ATTRIBUTE = "ref";
/**
* The value "refer"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String REFER_ATTRIBUTE = "refer";
/**
* The value "schemaLocation"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String SCHEMALOCATION_ATTRIBUTE = "schemaLocation";
/**
* The value "source"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String SOURCE_ATTRIBUTE = "source";
/**
* The value "substitutionGroup"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String SUBSTITUTIONGROUP_ATTRIBUTE = "substitutionGroup";
/**
* The value "system"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String SYSTEM_ATTRIBUTE = "system";
/**
* The value "targetNamespace"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String TARGETNAMESPACE_ATTRIBUTE = "targetNamespace";
/**
* The value "type"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String TYPE_ATTRIBUTE = "type";
/**
* The value "use"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String USE_ATTRIBUTE = "use";
/**
* The value "value"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String VALUE_ATTRIBUTE = "value";
/**
* The value "version"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String VERSION_ATTRIBUTE = "version";
/**
* The value "xpath"; an attribute on an {@link #ELEMENT_TAGS XML Schema element}.
* @see #ELEMENT_TAGS
*/
public final static String XPATH_ATTRIBUTE = "xpath";
/**
* The value "http://www.w3.org/2001/XMLSchema-hasFacetAndProperty".
*/
public static final String SCHEMA_HAS_FACET_AND_PROPERTY_URI_2001 = "http://www.w3.org/2001/XMLSchema-hasFacetAndProperty";
/**
* Returns whether the give namespace is one of the XML Schema has facet and property namespaces.
* @param namespace a namespace.
* @return whether the give namespace is one of the XML Schema has facet and property namespaces.
*/
public static boolean isSchemaHasFacetAndPropertyNamespace(String namespace)
{
return
SCHEMA_HAS_FACET_AND_PROPERTY_URI_2001.equals(namespace);
}
/**
* The value "hasFacet".
* @see #HFP_HASFACET_ELEMENT
* @see #HFP_ELEMENT_TAGS
* @see #hfpNodeType(String)
*/
public final static String HFP_HASFACET_ELEMENT_TAG = "hasFacet";
/**
* The value "hasProperty".
* @see #HFP_HASPROPERTY_ELEMENT
* @see #HFP_ELEMENT_TAGS
* @see #hfpNodeType(String)
*/
public final static String HFP_HASPROPERTY_ELEMENT_TAG = "hasProperty";
/**
* The value 0.
* @see #HFP_HASFACET_ELEMENT_TAG
* @see #HFP_ELEMENT_TAGS
* @see #hfpNodeType(String)
*/
public final static int HFP_HASFACET_ELEMENT = 0;
/**
* The value 1.
* @see #HFP_HASPROPERTY_ELEMENT_TAG
* @see #HFP_ELEMENT_TAGS
* @see #hfpNodeType(String)
*/
public final static int HFP_HASPROPERTY_ELEMENT = 1;
/**
* The sorted strings representing all XML Schema
* has facet and property element tags.
* @see #hfpNodeType(String)
*/
public static final String [] HFP_ELEMENT_TAGS =
new String []
{
HFP_HASFACET_ELEMENT_TAG,
HFP_HASPROPERTY_ELEMENT_TAG
};
/**
* Returns the index of the element type,
* if it is an XML Schema has facet and property element tag, or -1.
* @see #HFP_ELEMENT_TAGS
* @see #hfpNodeType(Node)
* @return the index of the element type.
*/
public static final int hfpNodeType(String localName)
{
for (int i = 0; i < HFP_ELEMENT_TAGS.length; ++i)
{
if (localName.equals(HFP_ELEMENT_TAGS[i]))
{
return i;
}
}
return -1;
}
/**
* Returns the index of the node's element type,
* if it is an XML Schema has facet and property element tag, or -1.
* @see #isSchemaHasFacetAndPropertyNamespace
* @see #HFP_ELEMENT_TAGS
* @see #hfpNodeType(String)
* @return the index of the node's element type,
*/
public static int hfpNodeType(Node node)
{
return
isSchemaHasFacetAndPropertyNamespace(node.getNamespaceURI()) ?
hfpNodeType(node.getLocalName()) :
-1;
}
/**
* The value "name"; an attribute on an XML Schema {@link #HFP_ELEMENT_TAGS has facet and property element}.
* @see #HFP_ELEMENT_TAGS
*/
public final static String HFP_NAME_ATTRIBUTE = "name";
/**
* The value "value"; an attribute on an XML Schema {@link #HFP_ELEMENT_TAGS has facet and property element}.
* @see #HFP_ELEMENT_TAGS
*/
public final static String HFP_VALUE_ATTRIBUTE = "value";
/**
* Returns the URI corresponding to the resolved QName of the value of the attribute of the element.
* @param element an element.
* @param localNameOfAttribute the name of the attribute whose value to use.
* @return the URI corresponding to the resolved QName of the value of the attribute of the element.
* @see #lookupQName(Element, String)
* @see Element#getAttribute(String)
*/
public static String lookupQNameForAttribute(Element element, String localNameOfAttribute)
{
if (element != null && element.hasAttribute(localNameOfAttribute))
{
// Some DOM implementations return a null here.
//
String qName = XMLTypeUtil.normalize(element.getAttribute(localNameOfAttribute), true);
return lookupQName(element, qName);
}
else
{
return "";
}
}
/**
* Returns the URI corresponding to the resolved QName.
* @param element an element.
* @param qName the QName to resolve in the context of the given element.
* @return the URI corresponding to the resolved QName.
*/
public static String lookupQName(Element element, String qName)
{
// Some DOM implementations return a null here.
//
int index = qName == null ? -1 : qName.lastIndexOf(':');
String namespaceAttribute = "xmlns";
if (index != -1)
{
String prefix = qName.substring(0, index);
if (prefix.equals("xml"))
{
return XSDConstants.XML_NAMESPACE_URI_1998 + "#" + qName.substring(index + 1);
}
namespaceAttribute = "xmlns:" + qName.substring(0, index);
}
for (Node node = element; node instanceof Element; node = node.getParentNode())
{
Element elementNode = (Element)node;
if (elementNode.hasAttribute(namespaceAttribute))
{
String namespace = elementNode.getAttribute(namespaceAttribute);
if ("".equals(namespace))
{
break;
}
String localName = qName == null ? "" : qName.substring(index + 1);
return namespace + "#" + localName;
}
}
return qName == null ? "" : index == -1 ? qName : qName.substring(0, index) + "#" + qName.substring(index + 1);
}
/**
* Returns the QName qualifier than is available at the given node to access the given namespace URI.
* A null string, indicates that no qualifier is to be used;
* a null value indicates that no qualifier is available.
* @param node the context node at which to lookup a qualifier.
* @param namespaceURI the namespace to be referenced.
* @return the QName qualifier than is available at the given node to access the given namespace URI.
*/
public static String lookupQualifier(Node node, String namespaceURI)
{
if (XSDConstants.XML_NAMESPACE_URI_1998.equals(namespaceURI))
{
return "xml";
}
Element leaf = null;
for (; node != null && node.getNodeType() == Node.ELEMENT_NODE; node = node.getParentNode())
{
Element elementNode = (Element)node;
if (leaf == null)
{
leaf = elementNode;
}
NamedNodeMap attributes = elementNode.getAttributes();
LOOP:
for (int i = 0, size = attributes.getLength(); i < size; ++i)
{
Attr attr = (Attr)attributes.item(i);
String name = attr.getNodeName();
if (name.startsWith("xmlns"))
{
String candidateNamespaceURI = attr.getNodeValue();
if (candidateNamespaceURI == null || candidateNamespaceURI.length() == 0 ?
namespaceURI == null || namespaceURI.length() == 0 :
candidateNamespaceURI.equals(namespaceURI))
{
int index = name.indexOf(':');
String result = index == -1 ? "" : name.substring(index + 1);
// Verify that there isn't another prefix declaration hiding the one we've found.
//
for (Element element = leaf; element != elementNode; element = (Element)element.getParentNode())
{
if (element.hasAttribute(name))
{
continue LOOP;
}
}
return result;
}
}
}
}
return namespaceURI == null || namespaceURI.length() == 0 ? "" : null;
}
/**
* Resolve the namespace and schema location relative to the base schema location.
* For example, the expression
*
* When no namespace schema location is provided, the namespace itself will be used.
* @param baseSchemaLocationURI the location of the schema containing the reference, i.e., {@link org.eclipse.xsd.XSDSchema#getSchemaLocation}.
* @param namespaceURI the namespace being resolved, i.e., {@link org.eclipse.xsd.XSDImport#getNamespace}.
* @param schemaLocationURI the suggested location of the namespace being resolved, i.e., {@link org.eclipse.xsd.XSDImport#getSchemaLocation}.
* @return the resolved schema location.
*/
public static String resolveSchemaLocation(String baseSchemaLocationURI, String namespaceURI, String schemaLocationURI)
{
try
{
if (schemaLocationURI == null)
{
schemaLocationURI = namespaceURI;
}
if (schemaLocationURI != null)
{
URI baseSchemaLocation = URI.createURI(baseSchemaLocationURI);
URI schemaLocation = URI.createURI(schemaLocationURI);
if (baseSchemaLocation.isHierarchical() && !baseSchemaLocation.isRelative() && schemaLocation.isRelative())
{
schemaLocation = schemaLocation.resolve(baseSchemaLocation);
}
return schemaLocation.toString();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
return schemaLocationURI;
}
/**
* Returns whether the type definition is one of the flavours of the ur-type, i.e.,
* complex anyType,
* simple anyType, or
* anySimpleType.
* @param xsdTypeDefinition a simple or complex type definition.
* @return whether the type definition is one of the flavours of the ur-type.
*/
public static boolean isURType(XSDTypeDefinition xsdTypeDefinition)
{
String name = xsdTypeDefinition.getName();
return
isSchemaForSchemaNamespace(xsdTypeDefinition.getTargetNamespace()) &&
("anyType".equals(name) || "anySimpleType".equals(name));
}
/**
* Returns whether the type definition is one of the flavours of the anyType, i.e.,
* complex anyType or
* simple anyType.
* @param xsdTypeDefinition a simple or complex type definition.
* @return whether the type definition is one of the flavours of the anyType.
*/
public static boolean isAnyType(XSDTypeDefinition xsdTypeDefinition)
{
return
isSchemaForSchemaNamespace(xsdTypeDefinition.getTargetNamespace()) &&
"anyType".equals(xsdTypeDefinition.getName());
}
/**
* Returns whether the type definition is the
* anySimpleType.
* @param xsdTypeDefinition a simple or complex type definition.
* @return whether the type definition is the anySimpleType.
*/
public static boolean isAnySimpleType(XSDTypeDefinition xsdTypeDefinition)
{
return
isSchemaForSchemaNamespace(xsdTypeDefinition.getTargetNamespace()) &&
"anySimpleType".equals(xsdTypeDefinition.getName());
}
/**
* Returns whether the type definition has the given namespace and name
* or is derived from a type with that namespace and name.
* @param xsdTypeDefinition a type definition.
* @return whether the type definition has the given namespace and name or is derived from a type with that namespace and name.
* @since 2.4
*/
public static boolean isOrIsDerivedFrom(XSDTypeDefinition xsdTypeDefinition, String name, String namespace)
{
Set visited = new HashSet();
while (xsdTypeDefinition != null)
{
if (xsdTypeDefinition.hasNameAndTargetNamespace(name, namespace))
{
return true;
}
if (!visited.add(xsdTypeDefinition = xsdTypeDefinition.getBaseType()))
{
return false;
}
}
return false;
}
/**
* Returns whether the type definition is a built-in type with the given name
* or is derived from a built-in type with that name.
* @param xsdSimpleTypeDefinition a type definition.
* @return whether the type definition is a built-in type with the given name
* or is derived from a built-in type with that name.
* @since 2.4
*/
public static boolean isOrIsDerivedFrom(XSDSimpleTypeDefinition xsdSimpleTypeDefinition, String name)
{
Set visited = new HashSet();
while (xsdSimpleTypeDefinition != null)
{
if (isSchemaForSchemaNamespace(xsdSimpleTypeDefinition.getTargetNamespace()) &&
name.equals(xsdSimpleTypeDefinition.getName()))
{
return true;
}
if (!visited.add(xsdSimpleTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition()))
{
return false;
}
}
return false;
}
/**
* Returns whether the simple type definition is
* ID or a type derived from it.
* @param xsdSimpleTypeDefinition a simple type definition.
* @return whether the simple type definition is ID or a type derived from it.
*/
public static boolean isOrIsDerivedFromID(XSDSimpleTypeDefinition xsdSimpleTypeDefinition)
{
return isOrIsDerivedFrom(xsdSimpleTypeDefinition, "ID");
}
}