1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2000-2002 The Apache Software Foundation.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.impl.xs;
  58. import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
  59. /**
  60. * This class customizes the behaviour of the util.NamespaceSupport
  61. * class in order to easily implement some features that we need for
  62. * efficient schema handling. It will not be generally useful.
  63. *
  64. * @author Neil Graham, IBM
  65. *
  66. * @version $Id: SchemaNamespaceSupport.java,v 1.4 2002/08/14 22:49:28 sandygao Exp $
  67. */
  68. public class SchemaNamespaceSupport
  69. extends NamespaceSupport {
  70. public SchemaNamespaceSupport () {
  71. super();
  72. } // constructor
  73. // more effecient than NamespaceSupport(NamespaceContext)
  74. public SchemaNamespaceSupport(SchemaNamespaceSupport nSupport) {
  75. fNamespaceSize = nSupport.fNamespaceSize;
  76. if (fNamespace.length < fNamespaceSize)
  77. fNamespace = new String[fNamespaceSize];
  78. System.arraycopy(nSupport.fNamespace, 0, fNamespace, 0, fNamespaceSize);
  79. fCurrentContext = nSupport.fCurrentContext;
  80. if (fContext.length <= fCurrentContext)
  81. fContext = new int[fCurrentContext+1];
  82. System.arraycopy(nSupport.fContext, 0, fContext, 0, fCurrentContext+1);
  83. } // end constructor
  84. /**
  85. * This method takes a set of Strings, as stored in a
  86. * NamespaceSupport object, and "fools" the object into thinking
  87. * that this is one unified context. This is meant to be used in
  88. * conjunction with things like local elements, whose declarations
  89. * may be deeply nested but which for all practical purposes may
  90. * be regarded as being one level below the global <schema>
  91. * element--at least with regard to namespace declarations.
  92. * It's worth noting that the context from which the strings are
  93. * being imported had better be using the same SymbolTable.
  94. */
  95. public void setEffectiveContext (String [] namespaceDecls) {
  96. if(namespaceDecls == null || namespaceDecls.length == 0) return;
  97. pushContext();
  98. int newSize = fNamespaceSize + namespaceDecls.length;
  99. if (fNamespace.length < newSize) {
  100. // expand namespace's size...
  101. String[] tempNSArray = new String[newSize];
  102. System.arraycopy(fNamespace, 0, tempNSArray, 0, fNamespace.length);
  103. fNamespace = tempNSArray;
  104. }
  105. System.arraycopy(namespaceDecls, 0, fNamespace, fNamespaceSize,
  106. namespaceDecls.length);
  107. fNamespaceSize = newSize;
  108. } // setEffectiveContext(String):void
  109. /**
  110. * This method returns an array of Strings, as would be stored in
  111. * a NamespaceSupport object. This array contains all
  112. * declarations except those at the global level.
  113. */
  114. public String [] getEffectiveLocalContext() {
  115. // the trick here is to recognize that all local contexts
  116. // happen to start at fContext[3].
  117. // context 1: empty
  118. // context 2: decls for xml and xmlns;
  119. // context 3: decls on <xs:schema>: the global ones
  120. String[] returnVal = null;
  121. if (fCurrentContext >= 3) {
  122. int bottomLocalContext = fContext[3];
  123. int copyCount = fNamespaceSize - bottomLocalContext;
  124. if (copyCount > 0) {
  125. returnVal = new String[copyCount];
  126. System.arraycopy(fNamespace, bottomLocalContext, returnVal, 0,
  127. copyCount);
  128. }
  129. }
  130. return returnVal;
  131. } // getEffectiveLocalContext():String
  132. // This method removes from this object all the namespaces
  133. // returned by getEffectiveLocalContext.
  134. public void makeGlobal() {
  135. if (fCurrentContext >= 3) {
  136. fCurrentContext = 3;
  137. fNamespaceSize = fContext[3];
  138. }
  139. } // makeGlobal
  140. } // class NamespaceSupport