286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2002, 2003,2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.impl.xs;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;
286N/Aimport com.sun.org.apache.xerces.internal.xni.QName;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLAttributes;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XMLSchemaDescription;
286N/A
286N/A/**
286N/A * All information specific to XML Schema grammars.
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Neil Graham, IBM
286N/A * @author Neeraj Bajaj, SUN Microsystems.
286N/A *
559N/A * @version $Id: XSDDescription.java,v 1.6 2010-11-01 04:39:55 joehw Exp $
286N/A */
286N/Apublic class XSDDescription extends XMLResourceIdentifierImpl
286N/A implements XMLSchemaDescription {
286N/A // used to indicate what triggered the call
286N/A /**
286N/A * Indicate that this description was just initialized.
286N/A */
286N/A public final static short CONTEXT_INITIALIZE = -1;
286N/A /**
286N/A * Indicate that the current schema document is <include>d by another
286N/A * schema document.
286N/A */
286N/A public final static short CONTEXT_INCLUDE = 0;
286N/A /**
286N/A * Indicate that the current schema document is <redefine>d by another
286N/A * schema document.
286N/A */
286N/A public final static short CONTEXT_REDEFINE = 1;
286N/A /**
286N/A * Indicate that the current schema document is <import>ed by another
286N/A * schema document.
286N/A */
286N/A public final static short CONTEXT_IMPORT = 2;
286N/A /**
286N/A * Indicate that the current schema document is being preparsed.
286N/A */
286N/A public final static short CONTEXT_PREPARSE = 3;
286N/A /**
286N/A * Indicate that the parse of the current schema document is triggered
286N/A * by xsi:schemaLocation/noNamespaceSchemaLocation attribute(s) in the
286N/A * instance document. This value is only used if we don't defer the loading
286N/A * of schema documents.
286N/A */
286N/A public final static short CONTEXT_INSTANCE = 4;
286N/A /**
286N/A * Indicate that the parse of the current schema document is triggered by
286N/A * the occurrence of an element whose namespace is the target namespace
286N/A * of this schema document. This value is only used if we do defer the
286N/A * loading of schema documents until a component from that namespace is
286N/A * referenced from the instance.
286N/A */
286N/A public final static short CONTEXT_ELEMENT = 5;
286N/A /**
286N/A * Indicate that the parse of the current schema document is triggered by
286N/A * the occurrence of an attribute whose namespace is the target namespace
286N/A * of this schema document. This value is only used if we do defer the
286N/A * loading of schema documents until a component from that namespace is
286N/A * referenced from the instance.
286N/A */
286N/A public final static short CONTEXT_ATTRIBUTE = 6;
286N/A /**
286N/A * Indicate that the parse of the current schema document is triggered by
286N/A * the occurrence of an "xsi:type" attribute, whose value (a QName) has
286N/A * the target namespace of this schema document as its namespace.
286N/A * This value is only used if we do defer the loading of schema documents
286N/A * until a component from that namespace is referenced from the instance.
286N/A */
286N/A public final static short CONTEXT_XSITYPE = 7;
286N/A
286N/A // REVISIT: write description of these fields
286N/A protected short fContextType;
286N/A protected String [] fLocationHints ;
286N/A protected QName fTriggeringComponent;
286N/A protected QName fEnclosedElementName;
286N/A protected XMLAttributes fAttributes;
286N/A
286N/A /**
286N/A * the type of the grammar (e.g., DTD or XSD);
286N/A *
286N/A * @see com.sun.org.apache.xerces.internal.xni.grammars.Grammar
286N/A */
286N/A public String getGrammarType() {
286N/A return XMLGrammarDescription.XML_SCHEMA;
286N/A }
286N/A
286N/A /**
286N/A * Get the context. The returned value is one of the pre-defined
286N/A * CONTEXT_xxx constants.
286N/A *
286N/A * @return the value indicating the context
286N/A */
286N/A public short getContextType() {
286N/A return fContextType ;
286N/A }
286N/A
286N/A /**
286N/A * If the context is "include" or "redefine", then return the target
286N/A * namespace of the enclosing schema document; otherwise, the expected
286N/A * target namespace of this document.
286N/A *
286N/A * @return the expected/enclosing target namespace
286N/A */
286N/A public String getTargetNamespace() {
286N/A return fNamespace;
286N/A }
286N/A
286N/A /**
286N/A * For import and references from the instance document, it's possible to
286N/A * have multiple hints for one namespace. So this method returns an array,
286N/A * which contains all location hints.
286N/A *
286N/A * @return an array of all location hints associated to the expected
286N/A * target namespace
286N/A */
286N/A public String[] getLocationHints() {
286N/A return fLocationHints ;
286N/A }
286N/A
286N/A /**
286N/A * If a call is triggered by an element/attribute/xsi:type in the instance,
286N/A * this call returns the name of such triggering component: the name of
286N/A * the element/attribute, or the value of the xsi:type.
286N/A *
286N/A * @return the name of the triggering component
286N/A */
286N/A public QName getTriggeringComponent() {
286N/A return fTriggeringComponent ;
286N/A }
286N/A
286N/A /**
286N/A * If a call is triggered by an attribute or xsi:type, then this mehtod
286N/A * returns the enclosing element of such element.
286N/A *
286N/A * @return the name of the enclosing element
286N/A */
286N/A public QName getEnclosingElementName() {
286N/A return fEnclosedElementName ;
286N/A }
286N/A
286N/A /**
286N/A * If a call is triggered by an element/attribute/xsi:type in the instance,
286N/A * this call returns all attribute of such element (or enclosing element).
286N/A *
286N/A * @return all attributes of the tiggering/enclosing element
286N/A */
286N/A public XMLAttributes getAttributes() {
286N/A return fAttributes;
286N/A }
286N/A
286N/A public boolean fromInstance() {
286N/A return fContextType == CONTEXT_ATTRIBUTE ||
286N/A fContextType == CONTEXT_ELEMENT ||
286N/A fContextType == CONTEXT_INSTANCE ||
286N/A fContextType == CONTEXT_XSITYPE;
286N/A }
286N/A
286N/A /**
559N/A * @return true is the schema is external
559N/A */
559N/A public boolean isExternal() {
559N/A return fContextType == CONTEXT_INCLUDE ||
559N/A fContextType == CONTEXT_REDEFINE ||
559N/A fContextType == CONTEXT_IMPORT ||
559N/A fContextType == CONTEXT_ELEMENT ||
559N/A fContextType == CONTEXT_ATTRIBUTE ||
559N/A fContextType == CONTEXT_XSITYPE;
559N/A }
559N/A /**
286N/A * Compares this grammar with the given grammar. Currently, we compare
286N/A * the target namespaces.
286N/A *
286N/A * @param descObj The description of the grammar to be compared with
286N/A * @return True if they are equal, else false
286N/A */
286N/A public boolean equals(Object descObj) {
286N/A if(!(descObj instanceof XMLSchemaDescription)) return false;
286N/A XMLSchemaDescription desc = (XMLSchemaDescription)descObj;
286N/A if (fNamespace != null)
286N/A return fNamespace.equals(desc.getTargetNamespace());
286N/A else // fNamespace == null
286N/A return desc.getTargetNamespace() == null;
286N/A }
286N/A
286N/A /**
286N/A * Returns the hash code of this grammar
286N/A *
286N/A * @return The hash code
286N/A */
286N/A public int hashCode() {
286N/A return (fNamespace == null) ? 0 : fNamespace.hashCode();
286N/A }
286N/A
286N/A public void setContextType(short contextType){
286N/A fContextType = contextType ;
286N/A }
286N/A
286N/A public void setTargetNamespace(String targetNamespace){
286N/A fNamespace = targetNamespace ;
286N/A }
286N/A
286N/A public void setLocationHints(String [] locationHints){
286N/A int length = locationHints.length ;
286N/A fLocationHints = new String[length];
286N/A System.arraycopy(locationHints, 0, fLocationHints, 0, length);
286N/A //fLocationHints = locationHints ;
286N/A }
286N/A
286N/A public void setTriggeringComponent(QName triggeringComponent){
286N/A fTriggeringComponent = triggeringComponent ;
286N/A }
286N/A
286N/A public void setEnclosingElementName(QName enclosedElementName){
286N/A fEnclosedElementName = enclosedElementName ;
286N/A }
286N/A
286N/A public void setAttributes(XMLAttributes attributes){
286N/A fAttributes = attributes ;
286N/A }
286N/A
286N/A /**
286N/A * resets all the fields
286N/A */
286N/A public void reset(){
286N/A super.clear();
286N/A fContextType = CONTEXT_INITIALIZE;
286N/A fLocationHints = null ;
286N/A fTriggeringComponent = null ;
286N/A fEnclosedElementName = null ;
286N/A fAttributes = null ;
286N/A }
286N/A
286N/A public XSDDescription makeClone() {
286N/A XSDDescription desc = new XSDDescription();
286N/A desc.fAttributes = this.fAttributes;
286N/A desc.fBaseSystemId = this.fBaseSystemId;
286N/A desc.fContextType = this.fContextType;
286N/A desc.fEnclosedElementName = this.fEnclosedElementName;
286N/A desc.fExpandedSystemId = this.fExpandedSystemId;
286N/A desc.fLiteralSystemId = this.fLiteralSystemId;
286N/A desc.fLocationHints = this.fLocationHints;
286N/A desc.fPublicId = this.fPublicId;
286N/A desc.fNamespace = this.fNamespace;
286N/A desc.fTriggeringComponent = this.fTriggeringComponent;
286N/A return desc;
286N/A }
286N/A
286N/A} // XSDDescription