View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2001-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.xni.QName;
24  import com.sun.org.apache.xerces.internal.impl.xs.SubstitutionGroupHandler;
25  import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException;
26  
27  import java.util.Vector;
28  import java.util.ArrayList;
29  
30  /**
31   * XSEmptyCM is a derivative of the abstract content model base class that
32   * handles a content model with no chilren (elements).
33   *
34   * This model validated on the way in.
35   *
36   * @xerces.internal
37   *
38   * @author Elena Litani, Lisa Martin
39   * @author IBM
40   * @version $Id: XSEmptyCM.java,v 1.7 2009/07/28 15:18:11 spericas Exp $
41   */
42  public class XSEmptyCM  implements XSCMValidator {
43  
44      //
45      // Constants
46      //
47  
48      // start the content model: did not see any children
49      private static final short STATE_START = 0;
50  
51      private static final Vector EMPTY = new Vector(0);
52  
53      //
54      // Data
55      //
56  
57      //
58      // XSCMValidator methods
59      //
60  
61      /**
62       * This methods to be called on entering a first element whose type
63       * has this content model. It will return the initial state of the content model
64       *
65       * @return Start state of the content model
66       */
67      public int[] startContentModel(){
68          return (new int[] {STATE_START});
69      }
70  
71  
72      /**
73       * The method corresponds to one transaction in the content model.
74       *
75       * @param elementName the qualified name of the element
76       * @param currentState Current state
77       * @param subGroupHandler the substitution group handler
78       * @return element index corresponding to the element from the Schema grammar
79       */
80      public Object oneTransition (QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler){
81  
82          // error state
83          if (currentState[0] < 0) {
84              currentState[0] = XSCMValidator.SUBSEQUENT_ERROR;
85              return null;
86          }
87  
88          currentState[0] = XSCMValidator.FIRST_ERROR;
89          return null;
90      }
91  
92  
93      /**
94       * The method indicates the end of list of children
95       *
96       * @param currentState Current state of the content model
97       * @return true if the last state was a valid final state
98       */
99      public boolean endContentModel (int[] currentState){
100         boolean isFinal =  false;
101         int state = currentState[0];
102 
103         // restore content model state:
104 
105         // error
106         if (state < 0) {
107             return false;
108         }
109 
110 
111         return true;
112     }
113 
114     /**
115      * check whether this content violates UPA constraint.
116      *
117      * @param subGroupHandler the substitution group handler
118      * @return true if this content model contains other or list wildcard
119      */
120     public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException {
121         return false;
122     }
123 
124     /**
125      * Check which elements are valid to appear at this point. This method also
126      * works if the state is in error, in which case it returns what should
127      * have been seen.
128      *
129      * @param state  the current state
130      * @return       a Vector whose entries are instances of
131      *               either XSWildcardDecl or XSElementDecl.
132      */
133     public Vector whatCanGoHere(int[] state) {
134         return EMPTY;
135     }
136 
137     public ArrayList checkMinMaxBounds() {
138         return null;
139     }
140 
141 } // class XSEmptyCM