View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 1999-2002,2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package com.sun.org.apache.xerces.internal.impl.xs.models;
22  
23  import com.sun.org.apache.xerces.internal.impl.dtd.models.CMNode;
24  import com.sun.org.apache.xerces.internal.impl.dtd.models.CMStateSet;
25  
26  /**
27   * Content model leaf node.
28   *
29   * @xerces.internal
30   *
31   * @author Neil Graham, IBM
32   */
33  public class XSCMLeaf
34      extends CMNode {
35  
36      //
37      // Data
38      //
39  
40      /** This is the leaf: element decl or wildcard decl. */
41      private Object fLeaf = null;
42  
43      /**
44       * Identify the particle: for UPA checking
45       */
46      private int fParticleId = -1;
47  
48      /**
49       * Part of the algorithm to convert a regex directly to a DFA
50       * numbers each leaf sequentially. If its -1, that means its an
51       * epsilon node. Zero and greater are non-epsilon positions.
52       */
53      private int fPosition = -1;
54  
55      //
56      // Constructors
57      //
58  
59      /** Constructs a content model leaf. */
60      public XSCMLeaf(int type, Object leaf, int id, int position)  {
61          super(type);
62  
63          // Store the element index and position
64          fLeaf = leaf;
65          fParticleId = id;
66          fPosition = position;
67      }
68  
69      //
70      // Package methods
71      //
72  
73      final Object getLeaf() {
74          return fLeaf;
75      }
76  
77      final int getParticleId() {
78          return fParticleId;
79      }
80  
81      final int getPosition() {
82          return fPosition;
83      }
84  
85      final void setPosition(int newPosition) {
86          fPosition = newPosition;
87      }
88  
89      //
90      // CMNode methods
91      //
92  
93      // package
94  
95      public boolean isNullable() {
96          // Leaf nodes are never nullable unless its an epsilon node
97          return (fPosition == -1);
98      }
99  
100     public String toString() {
101         StringBuffer strRet = new StringBuffer(fLeaf.toString());
102         if (fPosition >= 0) {
103             strRet.append
104             (
105                 " (Pos:"
106                 + Integer.toString(fPosition)
107                 + ")"
108             );
109         }
110         return strRet.toString();
111     }
112 
113     // protected
114 
115     protected void calcFirstPos(CMStateSet toSet) {
116         // If we are an epsilon node, then the first pos is an empty set
117         if (fPosition == -1)
118             toSet.zeroBits();
119 
120         // Otherwise, its just the one bit of our position
121         else
122             toSet.setBit(fPosition);
123     }
124 
125     protected void calcLastPos(CMStateSet toSet) {
126         // If we are an epsilon node, then the last pos is an empty set
127         if (fPosition == -1)
128             toSet.zeroBits();
129 
130         // Otherwise, its just the one bit of our position
131         else
132             toSet.setBit(fPosition);
133     }
134 
135 } // class XSCMLeaf