KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > validators > common > CMAny


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2000 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
58 package org.enhydra.apache.xerces.validators.common;
59
60 import org.enhydra.apache.xerces.framework.XMLContentSpec;
61 import org.enhydra.apache.xerces.utils.StringPool;
62
63 /**
64  * Content model any node.
65  *
66  * @version $Id: CMAny.java,v 1.2 2005/01/26 08:28:44 jkjome Exp $
67  */

68 public class CMAny
69     extends CMNode {
70
71     //
72
// Data
73
//
74

75     /**
76      * The any content model type. This value is one of the following:
77      * XMLContentSpec.CONTENTSPECNODE_ANY,
78      * XMLContentSpec.CONTENTSPECNODE_ANY_OTHER,
79      * XMLContentSpec.CONTENTSPECNODE_ANY_NS.
80      */

81     private int fType;
82
83     /**
84      * URI of the any content model. This value is set if the type is
85      * of the following:
86      * XMLContentSpec.CONTENTSPECNODE_ANY,
87      * XMLContentSpec.CONTENTSPECNODE_ANY_OTHER.
88      */

89     private int fURI;
90
91     /**
92      * Part of the algorithm to convert a regex directly to a DFA
93      * numbers each leaf sequentially. If its -1, that means its an
94      * epsilon node. Zero and greater are non-epsilon positions.
95      */

96     private int fPosition = -1;
97
98     //
99
// Constructors
100
//
101

102     /** Constructs a content model any. */
103     public CMAny(int type, int uri, int position) throws CMException {
104         super(type);
105
106         // Store the information
107
fType = type;
108         fURI = uri;
109         fPosition = position;
110     }
111
112     //
113
// Package methods
114
//
115

116     final int getType() {
117         return fType;
118     }
119
120     final int getURI() {
121         return fURI;
122     }
123
124     final int getPosition()
125     {
126         return fPosition;
127     }
128
129     final void setPosition(int newPosition)
130     {
131         fPosition = newPosition;
132     }
133
134     //
135
// CMNode methods
136
//
137

138     // package
139

140     boolean isNullable() throws CMException
141     {
142         // Leaf nodes are never nullable unless its an epsilon node
143
return (fPosition == -1);
144     }
145
146     String JavaDoc toString(StringPool stringPool)
147     {
148         StringBuffer JavaDoc strRet = new StringBuffer JavaDoc();
149         strRet.append("(");
150         switch (fType & 0x0f) {
151         case XMLContentSpec.CONTENTSPECNODE_ANY:
152             strRet.append("##any");
153             break;
154         case XMLContentSpec.CONTENTSPECNODE_ANY_NS:
155             strRet.append("##any:uri=" + stringPool.toString(fURI));
156             break;
157         case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER:
158             strRet.append("##other:uri=" + stringPool.toString(fURI));
159             break;
160         }
161         strRet.append(stringPool.toString(fURI));
162         strRet.append(')');
163         if (fPosition >= 0)
164         {
165             strRet.append
166             (
167                 " (Pos:"
168                 + new Integer JavaDoc(fPosition).toString()
169                 + ")"
170             );
171         }
172         return strRet.toString();
173     }
174
175     // protected
176

177     protected void calcFirstPos(CMStateSet toSet) throws CMException
178     {
179         // If we are an epsilon node, then the first pos is an empty set
180
if (fPosition == -1)
181             toSet.zeroBits();
182
183         // Otherwise, its just the one bit of our position
184
else
185             toSet.setBit(fPosition);
186     }
187
188     protected void calcLastPos(CMStateSet toSet) throws CMException
189     {
190         // If we are an epsilon node, then the last pos is an empty set
191
if (fPosition == -1)
192             toSet.zeroBits();
193
194         // Otherwise, its just the one bit of our position
195
else
196             toSet.setBit(fPosition);
197     }
198
199 } // class CMAny
200
Popular Tags