KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > SchemaNamespaceSupport


1 /*
2  * Copyright 2000-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.impl.xs;
18
19 import org.apache.xerces.util.NamespaceSupport;
20
21 /**
22  * This class customizes the behaviour of the util.NamespaceSupport
23  * class in order to easily implement some features that we need for
24  * efficient schema handling. It will not be generally useful.
25  *
26  * @xerces.internal
27  *
28  * @author Neil Graham, IBM
29  *
30  * @version $Id: SchemaNamespaceSupport.java,v 1.6 2004/10/06 15:14:55 mrglavas Exp $
31  */

32 public class SchemaNamespaceSupport
33     extends NamespaceSupport {
34
35     public SchemaNamespaceSupport () {
36         super();
37     } // constructor
38

39     // more effecient than NamespaceSupport(NamespaceContext)
40
public SchemaNamespaceSupport(SchemaNamespaceSupport nSupport) {
41         fNamespaceSize = nSupport.fNamespaceSize;
42         if (fNamespace.length < fNamespaceSize)
43             fNamespace = new String JavaDoc[fNamespaceSize];
44         System.arraycopy(nSupport.fNamespace, 0, fNamespace, 0, fNamespaceSize);
45         fCurrentContext = nSupport.fCurrentContext;
46         if (fContext.length <= fCurrentContext)
47             fContext = new int[fCurrentContext+1];
48         System.arraycopy(nSupport.fContext, 0, fContext, 0, fCurrentContext+1);
49     } // end constructor
50

51     /**
52      * This method takes a set of Strings, as stored in a
53      * NamespaceSupport object, and "fools" the object into thinking
54      * that this is one unified context. This is meant to be used in
55      * conjunction with things like local elements, whose declarations
56      * may be deeply nested but which for all practical purposes may
57      * be regarded as being one level below the global <schema>
58      * element--at least with regard to namespace declarations.
59      * It's worth noting that the context from which the strings are
60      * being imported had better be using the same SymbolTable.
61      */

62     public void setEffectiveContext (String JavaDoc [] namespaceDecls) {
63         if(namespaceDecls == null || namespaceDecls.length == 0) return;
64         pushContext();
65         int newSize = fNamespaceSize + namespaceDecls.length;
66         if (fNamespace.length < newSize) {
67             // expand namespace's size...
68
String JavaDoc[] tempNSArray = new String JavaDoc[newSize];
69             System.arraycopy(fNamespace, 0, tempNSArray, 0, fNamespace.length);
70             fNamespace = tempNSArray;
71         }
72         System.arraycopy(namespaceDecls, 0, fNamespace, fNamespaceSize,
73                          namespaceDecls.length);
74         fNamespaceSize = newSize;
75     } // setEffectiveContext(String):void
76

77     /**
78      * This method returns an array of Strings, as would be stored in
79      * a NamespaceSupport object. This array contains all
80      * declarations except those at the global level.
81      */

82     public String JavaDoc [] getEffectiveLocalContext() {
83         // the trick here is to recognize that all local contexts
84
// happen to start at fContext[3].
85
// context 1: empty
86
// context 2: decls for xml and xmlns;
87
// context 3: decls on <xs:schema>: the global ones
88
String JavaDoc[] returnVal = null;
89         if (fCurrentContext >= 3) {
90             int bottomLocalContext = fContext[3];
91             int copyCount = fNamespaceSize - bottomLocalContext;
92             if (copyCount > 0) {
93                 returnVal = new String JavaDoc[copyCount];
94                 System.arraycopy(fNamespace, bottomLocalContext, returnVal, 0,
95                                  copyCount);
96             }
97         }
98         return returnVal;
99     } // getEffectiveLocalContext():String
100

101     // This method removes from this object all the namespaces
102
// returned by getEffectiveLocalContext.
103
public void makeGlobal() {
104         if (fCurrentContext >= 3) {
105             fCurrentContext = 3;
106             fNamespaceSize = fContext[3];
107         }
108     } // makeGlobal
109
} // class NamespaceSupport
110
Popular Tags