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