View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * The Apache Software License, Version 1.1
7    *
8    *
9    * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
10   * reserved.
11   *
12   * Redistribution and use in source and binary forms, with or without
13   * modification, are permitted provided that the following conditions
14   * are met:
15   *
16   * 1. Redistributions of source code must retain the above copyright
17   *    notice, this list of conditions and the following disclaimer.
18   *
19   * 2. Redistributions in binary form must reproduce the above copyright
20   *    notice, this list of conditions and the following disclaimer in
21   *    the documentation and/or other materials provided with the
22   *    distribution.
23   *
24   * 3. The end-user documentation included with the redistribution,
25   *    if any, must include the following acknowledgment:
26   *       "This product includes software developed by the
27   *        Apache Software Foundation (http://www.apache.org/)."
28   *    Alternately, this acknowledgment may appear in the software itself,
29   *    if and wherever such third-party acknowledgments normally appear.
30   *
31   * 4. The names "Xerces" and "Apache Software Foundation" must
32   *    not be used to endorse or promote products derived from this
33   *    software without prior written permission. For written
34   *    permission, please contact apache@apache.org.
35   *
36   * 5. Products derived from this software may not be called "Apache",
37   *    nor may "Apache" appear in their name, without prior written
38   *    permission of the Apache Software Foundation.
39   *
40   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
44   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51   * SUCH DAMAGE.
52   * ====================================================================
53   *
54   * This software consists of voluntary contributions made by many
55   * individuals on behalf of the Apache Software Foundation and was
56   * originally based on software copyright (c) 1999, International
57   * Business Machines, Inc., http://www.apache.org.  For more
58   * information on the Apache Software Foundation, please see
59   * <http://www.apache.org/>.
60   */
61  
62  package com.sun.org.apache.xerces.internal.impl.dtd.models;
63  
64  /**
65   * A content model node.
66   *
67   * @xerces.internal
68   *
69   */
70  public abstract class CMNode
71  {
72      // -------------------------------------------------------------------
73      //  Constructors
74      // -------------------------------------------------------------------
75      public CMNode(int type)
76      {
77          fType = type;
78      }
79  
80  
81      // -------------------------------------------------------------------
82      //  Package, abstract methods
83      // -------------------------------------------------------------------
84      // made this public so it could be implemented and used outside this package -neilg.
85      public abstract boolean isNullable() ;
86  
87  
88      // -------------------------------------------------------------------
89      //  Package final methods
90      // -------------------------------------------------------------------
91      public final int type()
92      {
93          return fType;
94      }
95  
96      // made this public so it could be implemented and used outside this package -neilg.
97      public final CMStateSet firstPos()
98      {
99          if (fFirstPos == null)
100         {
101             fFirstPos = new CMStateSet(fMaxStates);
102             calcFirstPos(fFirstPos);
103         }
104         return fFirstPos;
105     }
106 
107     // made this public so it could be implemented and used outside this package -neilg.
108     public final CMStateSet lastPos()
109     {
110         if (fLastPos == null)
111         {
112             fLastPos = new CMStateSet(fMaxStates);
113             calcLastPos(fLastPos);
114         }
115         return fLastPos;
116     }
117 
118     final void setFollowPos(CMStateSet setToAdopt)
119     {
120         fFollowPos = setToAdopt;
121     }
122 
123     public final void setMaxStates(int maxStates)
124     {
125         fMaxStates = maxStates;
126     }
127 
128     /**
129      * Allows the user to set arbitrary data on this content model
130      * node. This is used by the a{n,m} optimization that runs
131      * in constant space.
132      */
133     public void setUserData(Object userData) {
134         fUserData = userData;
135     }
136 
137     /**
138      * Allows the user to get arbitrary data set on this content
139      * model node. This is used by the a{n,m} optimization that runs
140      * in constant space.
141      */
142     public Object getUserData() {
143         return fUserData;
144     }
145 
146     // -------------------------------------------------------------------
147     //  Protected, abstract methods
148     // -------------------------------------------------------------------
149     protected abstract void calcFirstPos(CMStateSet toSet) ;
150 
151     protected abstract void calcLastPos(CMStateSet toSet) ;
152 
153 
154     // -------------------------------------------------------------------
155     //  Private data members
156     //
157     //  fType
158     //      The type of node. This indicates whether its a leaf or an
159     //      operation. Though we also do derived classes for these types,
160     //      it is too expensive to use runtime typing to find this out.
161     //      This is one of the ContentSpecNode.NODE_XXX types.
162     //
163     //  fFirstPos
164     //      The set of NFA states that represent the entry states of this
165     //      node in the DFA.
166     //
167     //  fFollowPos
168     //      The set of NFA states that can be gotten to from from this
169     //      node in the DFA.
170     //
171     //  fLastPos
172     //      The set of NFA states that represent the final states of this
173     //      node in the DFA.
174     //
175     //  fMaxStates
176     //      The maximum number of states that the NFA has, which means the
177     //      max number of NFA states that have to be traced in the state
178     //      sets during the building of the DFA. Its unfortunate that it
179     //      has to be stored redundantly, but we need to fault in the
180     //      state set members and they have to be sized to this size. We
181     //      init to to -1 so it will cause an error if its used without
182     //      being initialized.
183     // -------------------------------------------------------------------
184     private int         fType;
185     private CMStateSet  fFirstPos   = null;
186     private CMStateSet  fFollowPos  = null;
187     private CMStateSet  fLastPos    = null;
188     private int         fMaxStates  = -1;
189     private Object      fUserData   = null;
190 };