KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > dtd > models > CMLeaf


1 /*
2  * Copyright 1999-2002,2004,2005 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.dtd.models;
18
19 import org.apache.xerces.impl.dtd.XMLContentSpec;
20 import org.apache.xerces.xni.QName;
21
22 /**
23  * Content model leaf node.
24  *
25  * @xerces.internal
26  *
27  * @version $Id: CMLeaf.java,v 1.5 2005/03/08 05:40:15 mrglavas Exp $
28  */

29 public class CMLeaf
30     extends CMNode {
31
32     //
33
// Data
34
//
35

36     /** This is the element that this leaf represents. */
37     private QName fElement = new QName();
38
39     /**
40      * Part of the algorithm to convert a regex directly to a DFA
41      * numbers each leaf sequentially. If its -1, that means its an
42      * epsilon node. Zero and greater are non-epsilon positions.
43      */

44     private int fPosition = -1;
45
46     //
47
// Constructors
48
//
49

50     /** Constructs a content model leaf. */
51     public CMLeaf(QName element, int position) {
52         super(XMLContentSpec.CONTENTSPECNODE_LEAF);
53
54         // Store the element index and position
55
fElement.setValues(element);
56         fPosition = position;
57     }
58
59     /** Constructs a content model leaf. */
60     public CMLeaf(QName element) {
61         super(XMLContentSpec.CONTENTSPECNODE_LEAF);
62
63         // Store the element index and position
64
fElement.setValues(element);
65     }
66
67     //
68
// Package methods
69
//
70

71     final QName getElement()
72     {
73         return fElement;
74     }
75
76     final int getPosition()
77     {
78         return fPosition;
79     }
80
81     final void setPosition(int newPosition)
82     {
83         fPosition = newPosition;
84     }
85
86     //
87
// CMNode methods
88
//
89

90     // package
91

92     public boolean isNullable()
93     {
94         // Leaf nodes are never nullable unless its an epsilon node
95
return (fPosition == -1);
96     }
97
98     public String JavaDoc toString()
99     {
100         StringBuffer JavaDoc strRet = new StringBuffer JavaDoc(fElement.toString());
101         strRet.append(" (");
102         strRet.append(fElement.uri);
103         strRet.append(',');
104         strRet.append(fElement.localpart);
105         strRet.append(')');
106         if (fPosition >= 0)
107         {
108             strRet.append
109             (
110                 " (Pos:"
111                 + Integer.toString(fPosition)
112                 + ")"
113             );
114         }
115         return strRet.toString();
116     }
117
118     // protected
119

120     protected void calcFirstPos(CMStateSet toSet)
121     {
122         // If we are an epsilon node, then the first pos is an empty set
123
if (fPosition == -1)
124             toSet.zeroBits();
125
126         // Otherwise, its just the one bit of our position
127
else
128             toSet.setBit(fPosition);
129     }
130
131     protected void calcLastPos(CMStateSet toSet)
132     {
133         // If we are an epsilon node, then the last pos is an empty set
134
if (fPosition == -1)
135             toSet.zeroBits();
136
137         // Otherwise, its just the one bit of our position
138
else
139             toSet.setBit(fPosition);
140     }
141
142 } // class CMLeaf
143

144
145
Popular Tags