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