001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2000 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.xerces.validators.common;
059:
060: import org.apache.xerces.framework.XMLContentSpec;
061: import org.apache.xerces.utils.ImplementationMessages;
062: import org.apache.xerces.utils.QName;
063: import org.apache.xerces.utils.StringPool;
064:
065: /**
066: * Content model any node.
067: *
068: * @version $Id: CMAny.java,v 1.3 2001/06/25 14:47:12 sandygao Exp $
069: */
070: public class CMAny extends CMNode {
071:
072: //
073: // Data
074: //
075:
076: /**
077: * The any content model type. This value is one of the following:
078: * XMLContentSpec.CONTENTSPECNODE_ANY,
079: * XMLContentSpec.CONTENTSPECNODE_ANY_OTHER,
080: * XMLContentSpec.CONTENTSPECNODE_ANY_NS.
081: */
082: private int fType;
083:
084: /**
085: * URI of the any content model. This value is set if the type is
086: * of the following:
087: * XMLContentSpec.CONTENTSPECNODE_ANY,
088: * XMLContentSpec.CONTENTSPECNODE_ANY_OTHER.
089: */
090: private int fURI;
091:
092: /**
093: * Part of the algorithm to convert a regex directly to a DFA
094: * numbers each leaf sequentially. If its -1, that means its an
095: * epsilon node. Zero and greater are non-epsilon positions.
096: */
097: private int fPosition = -1;
098:
099: //
100: // Constructors
101: //
102:
103: /** Constructs a content model any. */
104: public CMAny(int type, int uri, int position) throws CMException {
105: super (type);
106:
107: // Store the information
108: fType = type;
109: fURI = uri;
110: fPosition = position;
111: }
112:
113: //
114: // Package methods
115: //
116:
117: final int getType() {
118: return fType;
119: }
120:
121: final int getURI() {
122: return fURI;
123: }
124:
125: final int getPosition() {
126: return fPosition;
127: }
128:
129: final void setPosition(int newPosition) {
130: fPosition = newPosition;
131: }
132:
133: //
134: // CMNode methods
135: //
136:
137: // package
138:
139: boolean isNullable() throws CMException {
140: // Leaf nodes are never nullable unless its an epsilon node
141: return (fPosition == -1);
142: }
143:
144: String toString(StringPool stringPool) {
145: StringBuffer strRet = new StringBuffer();
146: strRet.append("(");
147: switch (fType & 0x0f) {
148: case XMLContentSpec.CONTENTSPECNODE_ANY:
149: strRet.append("##any");
150: break;
151: case XMLContentSpec.CONTENTSPECNODE_ANY_NS:
152: strRet.append("##any:uri=" + stringPool.toString(fURI));
153: break;
154: case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER:
155: strRet.append("##other:uri=" + stringPool.toString(fURI));
156: break;
157: }
158: strRet.append(stringPool.toString(fURI));
159: strRet.append(')');
160: if (fPosition >= 0) {
161: strRet.append(" (Pos:" + new Integer(fPosition).toString()
162: + ")");
163: }
164: return strRet.toString();
165: }
166:
167: // protected
168:
169: protected void calcFirstPos(CMStateSet toSet) throws CMException {
170: // If we are an epsilon node, then the first pos is an empty set
171: if (fPosition == -1)
172: toSet.zeroBits();
173:
174: // Otherwise, its just the one bit of our position
175: else
176: toSet.setBit(fPosition);
177: }
178:
179: protected void calcLastPos(CMStateSet toSet) throws CMException {
180: // If we are an epsilon node, then the last pos is an empty set
181: if (fPosition == -1)
182: toSet.zeroBits();
183:
184: // Otherwise, its just the one bit of our position
185: else
186: toSet.setBit(fPosition);
187: }
188:
189: } // class CMAny
|