KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > models > XSCMLeaf


1 /*
2  * Copyright 1999-2002,2004 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.xs.models;
18
19 import org.apache.xerces.impl.dtd.models.CMNode;
20 import org.apache.xerces.impl.dtd.models.CMStateSet;
21
22 /**
23  * Content model leaf node.
24  *
25  * @xerces.internal
26  *
27  * @author Neil Graham, IBM
28  * @version $$
29  */

30 public class XSCMLeaf
31     extends CMNode {
32
33     //
34
// Data
35
//
36

37     /** This is the leaf: element decl or wildcard decl. */
38     private Object JavaDoc fLeaf = null;
39     
40     /**
41      * Identify the particle: for UPA checking
42      */

43     private int fParticleId = -1;
44
45     /**
46      * Part of the algorithm to convert a regex directly to a DFA
47      * numbers each leaf sequentially. If its -1, that means its an
48      * epsilon node. Zero and greater are non-epsilon positions.
49      */

50     private int fPosition = -1;
51
52     //
53
// Constructors
54
//
55

56     /** Constructs a content model leaf. */
57     public XSCMLeaf(int type, Object JavaDoc leaf, int id, int position) {
58         super(type);
59
60         // Store the element index and position
61
fLeaf = leaf;
62         fParticleId = id;
63         fPosition = position;
64     }
65
66     //
67
// Package methods
68
//
69

70     final Object JavaDoc getLeaf() {
71         return fLeaf;
72     }
73     
74     final int getParticleId() {
75         return fParticleId;
76     }
77
78     final int getPosition() {
79         return fPosition;
80     }
81
82     final void setPosition(int newPosition) {
83         fPosition = newPosition;
84     }
85
86     //
87
// CMNode methods
88
//
89

90     // package
91

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

112     protected void calcFirstPos(CMStateSet toSet) {
113         // If we are an epsilon node, then the first pos is an empty set
114
if (fPosition == -1)
115             toSet.zeroBits();
116
117         // Otherwise, its just the one bit of our position
118
else
119             toSet.setBit(fPosition);
120     }
121
122     protected void calcLastPos(CMStateSet toSet) {
123         // If we are an epsilon node, then the last pos is an empty set
124
if (fPosition == -1)
125             toSet.zeroBits();
126
127         // Otherwise, its just the one bit of our position
128
else
129             toSet.setBit(fPosition);
130     }
131
132 } // class XSCMLeaf
133

134
135
Popular Tags