1 /* Copyright 2004 The Apache Software Foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 package org.apache.xmlbeans.impl.validator; 16 17 import org.apache.xmlbeans.SchemaType; 18 import org.apache.xmlbeans.SchemaLocalElement; 19 import org.apache.xmlbeans.SchemaParticle; 20 import org.apache.xmlbeans.SchemaLocalAttribute; 21 import org.apache.xmlbeans.SchemaAttributeModel; 22 import org.apache.xmlbeans.GDate; 23 import org.apache.xmlbeans.GDuration; 24 25 import javax.xml.stream.XMLStreamReader; 26 import javax.xml.stream.XMLStreamException; 27 import javax.xml.stream.events.XMLEvent; 28 import javax.xml.namespace.QName; 29 import java.math.BigDecimal; 30 import java.util.List; 31 32 /** 33 * Extension of {@link ValidatingXMLStreamReader} to provide Post Schema Validation Info 34 * over an XMLStreamReader. 35 * 36 * @author Cezar Andrei (cezar.andrei at bea.com) 37 * Date: Aug 17, 2004 38 */ 39 public class ValidatingInfoXMLStreamReader 40 extends ValidatingXMLStreamReader 41 implements XMLStreamReader 42 { 43 public ValidatingInfoXMLStreamReader() 44 { 45 super(); 46 } 47 48 private int _attCount = -1; 49 private int _attIndex = 0; 50 51 public int nextWithAttributes() 52 throws XMLStreamException 53 { 54 if (_attIndex < _attCount) 55 { 56 validate_attribute(_attIndex); 57 _attIndex ++; 58 return XMLEvent.ATTRIBUTE; 59 } 60 else 61 return next(); 62 } 63 64 protected void validate_attributes(int attCount) 65 { 66 _attCount = attCount; 67 _attIndex = 0; 68 } 69 70 71 /** 72 * @return Returns the SchemaType of the current element. 73 * This can be different than getCurrentElement().getType() if xsi:type attribute is used. 74 * Null is returned if no schema type is available. 75 * For attribute types use {@link #getCurrentAttribute()}.getType(). 76 * Warning: the returned SchemaType can be an {@link org.apache.xmlbeans.XmlBeans#NO_TYPE}, 77 * see {@link org.apache.xmlbeans.SchemaType#isNoType}. Or can be the parent type, for unrecognized elements 78 * that are part of wildcards. 79 */ 80 public SchemaType getCurrentElementSchemaType() 81 { 82 return _validator==null ? null : _validator.getCurrentElementSchemaType(); 83 } 84 85 /** 86 * @return Returns the curent local element, null if one is not available, see {@link #getCurrentWildcardElement()}. 87 */ 88 public SchemaLocalElement getCurrentElement ( ) 89 { 90 return _validator==null ? null : _validator.getCurrentElement(); 91 } 92 93 /** 94 * @return Returns the current particle, if this is a wildcard particle 95 * {@link org.apache.xmlbeans.SchemaParticle#WILDCARD} method {@link #getCurrentElement()} 96 * might return null if wildcard's processContents is skip or lax. 97 */ 98 public SchemaParticle getCurrentWildcardElement() 99 { 100 return _validator==null ? null : _validator.getCurrentWildcardElement(); 101 } 102 103 /** 104 * @return Returns the curent local attribute, global attribute if the current attribute is part of an 105 * attribute wildcard, or null if none is available. 106 */ 107 public SchemaLocalAttribute getCurrentAttribute() 108 { 109 return _validator==null ? null : _validator.getCurrentAttribute(); 110 } 111 112 /** 113 * @return Returns the attribute model for attributes if available, else null is returned. 114 */ 115 public SchemaAttributeModel getCurrentWildcardAttribute() 116 { 117 return _validator==null ? null : _validator.getCurrentWildcardAttribute(); 118 } 119 120 public String getStringValue() 121 { 122 return _validator==null ? null : _validator.getStringValue(); 123 } 124 125 public BigDecimal getDecimalValue() 126 { 127 return _validator==null ? null : _validator.getDecimalValue(); 128 } 129 130 public boolean getBooleanValue() 131 { 132 return _validator==null ? false : _validator.getBooleanValue(); 133 } 134 135 public float getFloatValue() 136 { 137 return _validator==null ? 0 : _validator.getFloatValue(); 138 } 139 140 public double getDoubleValue() 141 { 142 return _validator==null ? 0 : _validator.getDoubleValue(); 143 } 144 145 public QName getQNameValue() 146 { 147 return _validator==null ? null : _validator.getQNameValue(); 148 } 149 150 public GDate getGDateValue() 151 { 152 return _validator==null ? null : _validator.getGDateValue(); 153 } 154 155 public GDuration getGDurationValue() 156 { 157 return _validator==null ? null : _validator.getGDurationValue(); 158 } 159 160 public byte[] getByteArrayValue() 161 { 162 return _validator==null ? null : _validator.getByteArrayValue(); 163 } 164 165 public List getListValue() 166 { 167 return _validator==null ? null : _validator.getListValue(); 168 } 169 170 public List getListTypes() 171 { 172 return _validator==null ? null : _validator.getListTypes(); 173 } 174 175 public SchemaType getUnionType() 176 { 177 return _validator==null ? null : _validator.getUnionType(); 178 } 179 }