1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
  6. * 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.dtd.models;
  58. /**
  59. * Content model any node.
  60. *
  61. * @version $Id: CMAny.java,v 1.3 2003/05/08 20:11:55 elena Exp $
  62. */
  63. public class CMAny
  64. extends CMNode {
  65. //
  66. // Data
  67. //
  68. /**
  69. * The any content model type. This value is one of the following:
  70. * XMLContentSpec.CONTENTSPECNODE_ANY,
  71. * XMLContentSpec.CONTENTSPECNODE_ANY_OTHER,
  72. * XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL.
  73. */
  74. private int fType;
  75. /**
  76. * URI of the any content model. This value is set if the type is
  77. * of the following:
  78. * XMLContentSpec.CONTENTSPECNODE_ANY,
  79. * XMLContentSpec.CONTENTSPECNODE_ANY_OTHER.
  80. */
  81. private String fURI;
  82. /**
  83. * Part of the algorithm to convert a regex directly to a DFA
  84. * numbers each leaf sequentially. If its -1, that means its an
  85. * epsilon node. Zero and greater are non-epsilon positions.
  86. */
  87. private int fPosition = -1;
  88. //
  89. // Constructors
  90. //
  91. /** Constructs a content model any. */
  92. public CMAny(int type, String uri, int position) {
  93. super(type);
  94. // Store the information
  95. fType = type;
  96. fURI = uri;
  97. fPosition = position;
  98. }
  99. //
  100. // Package methods
  101. //
  102. final int getType() {
  103. return fType;
  104. }
  105. final String getURI() {
  106. return fURI;
  107. }
  108. final int getPosition()
  109. {
  110. return fPosition;
  111. }
  112. final void setPosition(int newPosition)
  113. {
  114. fPosition = newPosition;
  115. }
  116. //
  117. // CMNode methods
  118. //
  119. // package
  120. public boolean isNullable()
  121. {
  122. // Leaf nodes are never nullable unless its an epsilon node
  123. return (fPosition == -1);
  124. }
  125. public String toString()
  126. {
  127. StringBuffer strRet = new StringBuffer();
  128. strRet.append("(");
  129. strRet.append("##any:uri=");
  130. strRet.append(fURI);
  131. strRet.append(')');
  132. if (fPosition >= 0)
  133. {
  134. strRet.append
  135. (
  136. " (Pos:"
  137. + new Integer(fPosition).toString()
  138. + ")"
  139. );
  140. }
  141. return strRet.toString();
  142. }
  143. // protected
  144. protected void calcFirstPos(CMStateSet toSet)
  145. {
  146. // If we are an epsilon node, then the first pos is an empty set
  147. if (fPosition == -1)
  148. toSet.zeroBits();
  149. // Otherwise, its just the one bit of our position
  150. else
  151. toSet.setBit(fPosition);
  152. }
  153. protected void calcLastPos(CMStateSet toSet)
  154. {
  155. // If we are an epsilon node, then the last pos is an empty set
  156. if (fPosition == -1)
  157. toSet.zeroBits();
  158. // Otherwise, its just the one bit of our position
  159. else
  160. toSet.setBit(fPosition);
  161. }
  162. } // class CMAny