286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2000-2002,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.NamespaceSupport;
286N/A
286N/A/**
286N/A * This class customizes the behaviour of the util.NamespaceSupport
286N/A * class in order to easily implement some features that we need for
286N/A * efficient schema handling. It will not be generally useful.
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Neil Graham, IBM
286N/A *
286N/A */
286N/Apublic class SchemaNamespaceSupport
286N/A extends NamespaceSupport {
286N/A
286N/A public SchemaNamespaceSupport () {
286N/A super();
286N/A } // constructor
286N/A
286N/A // more effecient than NamespaceSupport(NamespaceContext)
286N/A public SchemaNamespaceSupport(SchemaNamespaceSupport nSupport) {
286N/A fNamespaceSize = nSupport.fNamespaceSize;
286N/A if (fNamespace.length < fNamespaceSize)
286N/A fNamespace = new String[fNamespaceSize];
286N/A System.arraycopy(nSupport.fNamespace, 0, fNamespace, 0, fNamespaceSize);
286N/A fCurrentContext = nSupport.fCurrentContext;
286N/A if (fContext.length <= fCurrentContext)
286N/A fContext = new int[fCurrentContext+1];
286N/A System.arraycopy(nSupport.fContext, 0, fContext, 0, fCurrentContext+1);
286N/A } // end constructor
286N/A
286N/A /**
286N/A * This method takes a set of Strings, as stored in a
286N/A * NamespaceSupport object, and "fools" the object into thinking
286N/A * that this is one unified context. This is meant to be used in
286N/A * conjunction with things like local elements, whose declarations
286N/A * may be deeply nested but which for all practical purposes may
286N/A * be regarded as being one level below the global <schema>
286N/A * element--at least with regard to namespace declarations.
286N/A * It's worth noting that the context from which the strings are
286N/A * being imported had better be using the same SymbolTable.
286N/A */
286N/A public void setEffectiveContext (String [] namespaceDecls) {
286N/A if(namespaceDecls == null || namespaceDecls.length == 0) return;
286N/A pushContext();
286N/A int newSize = fNamespaceSize + namespaceDecls.length;
286N/A if (fNamespace.length < newSize) {
286N/A // expand namespace's size...
286N/A String[] tempNSArray = new String[newSize];
286N/A System.arraycopy(fNamespace, 0, tempNSArray, 0, fNamespace.length);
286N/A fNamespace = tempNSArray;
286N/A }
286N/A System.arraycopy(namespaceDecls, 0, fNamespace, fNamespaceSize,
286N/A namespaceDecls.length);
286N/A fNamespaceSize = newSize;
286N/A } // setEffectiveContext(String):void
286N/A
286N/A /**
286N/A * This method returns an array of Strings, as would be stored in
286N/A * a NamespaceSupport object. This array contains all
286N/A * declarations except those at the global level.
286N/A */
286N/A public String [] getEffectiveLocalContext() {
286N/A // the trick here is to recognize that all local contexts
286N/A // happen to start at fContext[3].
286N/A // context 1: empty
286N/A // context 2: decls for xml and xmlns;
286N/A // context 3: decls on <xs:schema>: the global ones
286N/A String[] returnVal = null;
286N/A if (fCurrentContext >= 3) {
286N/A int bottomLocalContext = fContext[3];
286N/A int copyCount = fNamespaceSize - bottomLocalContext;
286N/A if (copyCount > 0) {
286N/A returnVal = new String[copyCount];
286N/A System.arraycopy(fNamespace, bottomLocalContext, returnVal, 0,
286N/A copyCount);
286N/A }
286N/A }
286N/A return returnVal;
286N/A } // getEffectiveLocalContext():String
286N/A
286N/A // This method removes from this object all the namespaces
286N/A // returned by getEffectiveLocalContext.
286N/A public void makeGlobal() {
286N/A if (fCurrentContext >= 3) {
286N/A fCurrentContext = 3;
286N/A fNamespaceSize = fContext[3];
286N/A }
286N/A } // makeGlobal
286N/A} // class NamespaceSupport