1 /* 2 * Copyright (c) 2006, 2017, 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 22 package com.sun.org.apache.xerces.internal.impl.xs.models; 23 24 import com.sun.org.apache.xerces.internal.impl.xs.SubstitutionGroupHandler; 25 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException; 26 import com.sun.org.apache.xerces.internal.xni.QName; 27 import java.util.ArrayList; 28 import java.util.List; 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 * @LastModified: Oct 2017 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 List<Object> EMPTY = new ArrayList<>(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 */ startContentModel()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 */ oneTransition(QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler)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 */ endContentModel(int[] currentState)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 */ checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler)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 list whose entries are instances of 131 * either XSWildcardDecl or XSElementDecl. 132 */ whatCanGoHere(int[] state)133 public List<Object> whatCanGoHere(int[] state) { 134 return EMPTY; 135 } 136 checkMinMaxBounds()137 public List<String> checkMinMaxBounds() { 138 return null; 139 } 140 occurenceInfo(int[] state)141 public int [] occurenceInfo(int[] state) { 142 return null; 143 } 144 getTermName(int termId)145 public String getTermName(int termId) { 146 return null; 147 } 148 isCompactedForUPA()149 public boolean isCompactedForUPA() { 150 return false; 151 } 152 } // class XSEmptyCM 153