1/*
2 * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
3 */
4/*
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements.  See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License.  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
22package com.sun.org.apache.xerces.internal.impl.xs.models;
23
24import com.sun.org.apache.xerces.internal.xni.QName;
25import com.sun.org.apache.xerces.internal.impl.xs.SubstitutionGroupHandler;
26import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException;
27import java.util.ArrayList;
28
29/**
30 * XSEmptyCM is a derivative of the abstract content model base class that
31 * handles a content model with no chilren (elements).
32 *
33 * This model validated on the way in.
34 *
35 * @xerces.internal
36 *
37 * @author Elena Litani, Lisa Martin
38 * @author IBM
39 */
40public class XSEmptyCM  implements XSCMValidator {
41
42    //
43    // Constants
44    //
45
46    // start the content model: did not see any children
47    private static final short STATE_START = 0;
48
49    private static final ArrayList EMPTY = new ArrayList(0);
50
51    //
52    // Data
53    //
54
55    //
56    // XSCMValidator methods
57    //
58
59    /**
60     * This methods to be called on entering a first element whose type
61     * has this content model. It will return the initial state of the content model
62     *
63     * @return Start state of the content model
64     */
65    public int[] startContentModel(){
66        return (new int[] {STATE_START});
67    }
68
69
70    /**
71     * The method corresponds to one transaction in the content model.
72     *
73     * @param elementName the qualified name of the element
74     * @param currentState Current state
75     * @param subGroupHandler the substitution group handler
76     * @return element index corresponding to the element from the Schema grammar
77     */
78    public Object oneTransition (QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler){
79
80        // error state
81        if (currentState[0] < 0) {
82            currentState[0] = XSCMValidator.SUBSEQUENT_ERROR;
83            return null;
84        }
85
86        currentState[0] = XSCMValidator.FIRST_ERROR;
87        return null;
88    }
89
90
91    /**
92     * The method indicates the end of list of children
93     *
94     * @param currentState Current state of the content model
95     * @return true if the last state was a valid final state
96     */
97    public boolean endContentModel (int[] currentState){
98        boolean isFinal =  false;
99        int state = currentState[0];
100
101        // restore content model state:
102
103        // error
104        if (state < 0) {
105            return false;
106        }
107
108
109        return true;
110    }
111
112    /**
113     * check whether this content violates UPA constraint.
114     *
115     * @param subGroupHandler the substitution group handler
116     * @return true if this content model contains other or list wildcard
117     */
118    public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException {
119        return false;
120    }
121
122    /**
123     * Check which elements are valid to appear at this point. This method also
124     * works if the state is in error, in which case it returns what should
125     * have been seen.
126     *
127     * @param state  the current state
128     * @return       a list whose entries are instances of
129     *               either XSWildcardDecl or XSElementDecl.
130     */
131    public ArrayList whatCanGoHere(int[] state) {
132        return EMPTY;
133    }
134
135    public ArrayList checkMinMaxBounds() {
136        return null;
137    }
138
139    public int [] occurenceInfo(int[] state) {
140        return null;
141    }
142
143    public String getTermName(int termId) {
144        return null;
145    }
146
147    public boolean isCompactedForUPA() {
148        return false;
149    }
150} // class XSEmptyCM
151