001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.xs.models;
019:
020: import org.apache.xerces.xni.QName;
021: import org.apache.xerces.impl.xs.SubstitutionGroupHandler;
022: import org.apache.xerces.impl.xs.XMLSchemaException;
023:
024: import java.util.Vector;
025:
026: /**
027: * XSEmptyCM is a derivative of the abstract content model base class that
028: * handles a content model with no children (elements).
029: *
030: * This model validated on the way in.
031: *
032: * @xerces.internal
033: *
034: * @author Elena Litani, IBM
035: * @author Lisa Martin, IBM
036: * @version $Id: XSEmptyCM.java 573322 2007-09-06 16:48:47Z peterjm $
037: */
038: public class XSEmptyCM implements XSCMValidator {
039:
040: //
041: // Constants
042: //
043:
044: // start the content model: did not see any children
045: private static final short STATE_START = 0;
046:
047: private static final Vector EMPTY = new Vector(0);
048:
049: //
050: // Data
051: //
052:
053: //
054: // XSCMValidator methods
055: //
056:
057: /**
058: * This methods to be called on entering a first element whose type
059: * has this content model. It will return the initial state of the content model
060: *
061: * @return Start state of the content model
062: */
063: public int[] startContentModel() {
064: return (new int[] { STATE_START });
065: }
066:
067: /**
068: * The method corresponds to one transaction in the content model.
069: *
070: * @param elementName the qualified name of the element
071: * @param currentState Current state
072: * @param subGroupHandler the substitution group handler
073: * @return element index corresponding to the element from the Schema grammar
074: */
075: public Object oneTransition(QName elementName, int[] currentState,
076: SubstitutionGroupHandler subGroupHandler) {
077:
078: // error state
079: if (currentState[0] < 0) {
080: currentState[0] = XSCMValidator.SUBSEQUENT_ERROR;
081: return null;
082: }
083:
084: currentState[0] = XSCMValidator.FIRST_ERROR;
085: return null;
086: }
087:
088: /**
089: * The method indicates the end of list of children
090: *
091: * @param currentState Current state of the content model
092: * @return true if the last state was a valid final state
093: */
094: public boolean endContentModel(int[] currentState) {
095: boolean isFinal = false;
096: int state = currentState[0];
097:
098: // restore content model state:
099:
100: // error
101: if (state < 0) {
102: return false;
103: }
104:
105: return true;
106: }
107:
108: /**
109: * check whether this content violates UPA constraint.
110: *
111: * @param subGroupHandler the substitution group handler
112: * @return true if this content model contains other or list wildcard
113: */
114: public boolean checkUniqueParticleAttribution(
115: SubstitutionGroupHandler subGroupHandler)
116: throws XMLSchemaException {
117: return false;
118: }
119:
120: /**
121: * Check which elements are valid to appear at this point. This method also
122: * works if the state is in error, in which case it returns what should
123: * have been seen.
124: *
125: * @param state the current state
126: * @return a Vector whose entries are instances of
127: * either XSWildcardDecl or XSElementDecl.
128: */
129: public Vector whatCanGoHere(int[] state) {
130: return EMPTY;
131: }
132:
133: public boolean isCompactedForUPA() {
134: return false;
135: }
136: } // class XSEmptyCM
|