1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package com.sun.org.apache.xerces.internal.dom; 19 20import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo; 21import com.sun.org.apache.xerces.internal.impl.xs.ElementPSVImpl; 22import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl; 23import com.sun.org.apache.xerces.internal.xs.*; 24import com.sun.org.apache.xerces.internal.xs.ElementPSVI; 25import java.io.IOException; 26import java.io.NotSerializableException; 27import java.io.ObjectInputStream; 28import java.io.ObjectOutputStream; 29 30/** 31 * Element namespace implementation; stores PSVI element items. 32 * 33 * @xerces.internal 34 * 35 * @author Sandy Gao, IBM 36 * 37 */ 38public class PSVIElementNSImpl extends ElementNSImpl implements ElementPSVI { 39 40 /** Serialization version. */ 41 static final long serialVersionUID = 6815489624636016068L; 42 43 /** 44 * Construct an element node. 45 */ 46 public PSVIElementNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI, 47 String qualifiedName, String localName) { 48 super(ownerDocument, namespaceURI, qualifiedName, localName); 49 } 50 51 /** 52 * Construct an element node. 53 */ 54 public PSVIElementNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI, 55 String qualifiedName) { 56 super(ownerDocument, namespaceURI, qualifiedName); 57 } 58 59 /** element declaration */ 60 protected XSElementDeclaration fDeclaration = null; 61 62 /** type of element, could be xsi:type */ 63 protected XSTypeDefinition fTypeDecl = null; 64 65 /** true if clause 3.2 of Element Locally Valid (Element) (3.3.4) 66 * is satisfied, otherwise false 67 */ 68 protected boolean fNil = false; 69 70 /** false if the element value was provided by the schema; true otherwise. 71 */ 72 protected boolean fSpecified = true; 73 74 /** Schema value */ 75 protected ValidatedInfo fValue = new ValidatedInfo(); 76 77 /** http://www.w3.org/TR/xmlschema-1/#e-notation*/ 78 protected XSNotationDeclaration fNotation = null; 79 80 /** validation attempted: none, partial, full */ 81 protected short fValidationAttempted = ElementPSVI.VALIDATION_NONE; 82 83 /** validity: valid, invalid, unknown */ 84 protected short fValidity = ElementPSVI.VALIDITY_NOTKNOWN; 85 86 /** error codes */ 87 protected StringList fErrorCodes = null; 88 89 /** error messages */ 90 protected StringList fErrorMessages = null; 91 92 /** validation context: could be QName or XPath expression*/ 93 protected String fValidationContext = null; 94 95 /** the schema information property */ 96 protected XSModel fSchemaInformation = null; 97 98 // 99 // ElementPSVI methods 100 // 101 102 /* (non-Javadoc) 103 * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#constant() 104 */ 105 public ItemPSVI constant() { 106 return new ElementPSVImpl(true, this); 107 } 108 109 /* (non-Javadoc) 110 * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#isConstant() 111 */ 112 public boolean isConstant() { 113 return false; 114 } 115 116 /** 117 * [schema default] 118 * 119 * @return The canonical lexical representation of the declaration's {value constraint} value. 120 * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_default>XML Schema Part 1: Structures [schema default]</a> 121 */ 122 public String getSchemaDefault() { 123 return fDeclaration == null ? null : fDeclaration.getConstraintValue(); 124 } 125 126 /** 127 * [schema normalized value] 128 * 129 * 130 * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_normalized_value>XML Schema Part 1: Structures [schema normalized value]</a> 131 * @return the normalized value of this item after validation 132 */ 133 public String getSchemaNormalizedValue() { 134 return fValue.getNormalizedValue(); 135 } 136 137 /** 138 * [schema specified] 139 * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a> 140 * @return false value was specified in schema, true value comes from the infoset 141 */ 142 public boolean getIsSchemaSpecified() { 143 return fSpecified; 144 } 145 146 /** 147 * Determines the extent to which the document has been validated 148 * 149 * @return return the [validation attempted] property. The possible values are 150 * NO_VALIDATION, PARTIAL_VALIDATION and FULL_VALIDATION 151 */ 152 public short getValidationAttempted() { 153 return fValidationAttempted; 154 } 155 156 /** 157 * Determine the validity of the node with respect 158 * to the validation being attempted 159 * 160 * @return return the [validity] property. Possible values are: 161 * UNKNOWN_VALIDITY, INVALID_VALIDITY, VALID_VALIDITY 162 */ 163 public short getValidity() { 164 return fValidity; 165 } 166 167 /** 168 * A list of error codes generated from validation attempts. 169 * Need to find all the possible subclause reports that need reporting 170 * 171 * @return Array of error codes 172 */ 173 public StringList getErrorCodes() { 174 if (fErrorCodes != null) { 175 return fErrorCodes; 176 } 177 return StringListImpl.EMPTY_LIST; 178 } 179 180 /** 181 * A list of error messages generated from the validation attempt or 182 * an empty <code>StringList</code> if no errors occurred during the 183 * validation attempt. The indices of error messages in this list are 184 * aligned with those in the <code>[schema error code]</code> list. 185 */ 186 public StringList getErrorMessages() { 187 if (fErrorMessages != null) { 188 return fErrorMessages; 189 } 190 return StringListImpl.EMPTY_LIST; 191 } 192 193 // This is the only information we can provide in a pipeline. 194 public String getValidationContext() { 195 return fValidationContext; 196 } 197 198 /** 199 * [nil] 200 * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-nil>XML Schema Part 1: Structures [nil]</a> 201 * @return true if clause 3.2 of Element Locally Valid (Element) (3.3.4) above is satisfied, otherwise false 202 */ 203 public boolean getNil() { 204 return fNil; 205 } 206 207 /** 208 * [notation] 209 * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-notation>XML Schema Part 1: Structures [notation]</a> 210 * @return The notation declaration. 211 */ 212 public XSNotationDeclaration getNotation() { 213 return fNotation; 214 } 215 216 /** 217 * An item isomorphic to the type definition used to validate this element. 218 * 219 * @return a type declaration 220 */ 221 public XSTypeDefinition getTypeDefinition() { 222 return fTypeDecl; 223 } 224 225 /** 226 * If and only if that type definition is a simple type definition 227 * with {variety} union, or a complex type definition whose {content type} 228 * is a simple thype definition with {variety} union, then an item isomorphic 229 * to that member of the union's {member type definitions} which actually 230 * validated the element item's normalized value. 231 * 232 * @return a simple type declaration 233 */ 234 public XSSimpleTypeDefinition getMemberTypeDefinition() { 235 return fValue.getMemberTypeDefinition(); 236 } 237 238 /** 239 * An item isomorphic to the element declaration used to validate 240 * this element. 241 * 242 * @return an element declaration 243 */ 244 public XSElementDeclaration getElementDeclaration() { 245 return fDeclaration; 246 } 247 248 /** 249 * [schema information] 250 * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_information">XML Schema Part 1: Structures [schema information]</a> 251 * @return The schema information property if it's the validation root, 252 * null otherwise. 253 */ 254 public XSModel getSchemaInformation() { 255 return fSchemaInformation; 256 } 257 258 /** 259 * Copy PSVI properties from another psvi item. 260 * 261 * @param elem the source of element PSVI items 262 */ 263 public void setPSVI(ElementPSVI elem) { 264 this.fDeclaration = elem.getElementDeclaration(); 265 this.fNotation = elem.getNotation(); 266 this.fValidationContext = elem.getValidationContext(); 267 this.fTypeDecl = elem.getTypeDefinition(); 268 this.fSchemaInformation = elem.getSchemaInformation(); 269 this.fValidity = elem.getValidity(); 270 this.fValidationAttempted = elem.getValidationAttempted(); 271 this.fErrorCodes = elem.getErrorCodes(); 272 this.fErrorMessages = elem.getErrorMessages(); 273 if (fTypeDecl instanceof XSSimpleTypeDefinition || 274 fTypeDecl instanceof XSComplexTypeDefinition && 275 ((XSComplexTypeDefinition)fTypeDecl).getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE) { 276 this.fValue.copyFrom(elem.getSchemaValue()); 277 } 278 else { 279 this.fValue.reset(); 280 } 281 this.fSpecified = elem.getIsSchemaSpecified(); 282 this.fNil = elem.getNil(); 283 } 284 285 /* (non-Javadoc) 286 * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValue() 287 */ 288 public Object getActualNormalizedValue() { 289 return fValue.getActualValue(); 290 } 291 292 /* (non-Javadoc) 293 * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValueType() 294 */ 295 public short getActualNormalizedValueType() { 296 return fValue.getActualValueType(); 297 } 298 299 /* (non-Javadoc) 300 * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getItemValueTypes() 301 */ 302 public ShortList getItemValueTypes() { 303 return fValue.getListValueTypes(); 304 } 305 306 /* (non-Javadoc) 307 * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getSchemaValue() 308 */ 309 public XSValue getSchemaValue() { 310 return fValue; 311 } 312 313 // REVISIT: Forbid serialization of PSVI DOM until 314 // we support object serialization of grammars -- mrglavas 315 316 private void writeObject(ObjectOutputStream out) 317 throws IOException { 318 throw new NotSerializableException(getClass().getName()); 319 } 320 321 private void readObject(ObjectInputStream in) 322 throws IOException, ClassNotFoundException { 323 throw new NotSerializableException(getClass().getName()); 324 } 325} 326