1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2002-2004 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.dom;
  58. import java.io.IOException;
  59. import java.io.NotSerializableException;
  60. import java.io.ObjectInputStream;
  61. import java.io.ObjectOutputStream;
  62. import com.sun.org.apache.xerces.internal.xs.ElementPSVI;
  63. import com.sun.org.apache.xerces.internal.xs.*;
  64. /**
  65. * Element namespace implementation; stores PSVI element items.
  66. *
  67. * @author Sandy Gao, IBM
  68. *
  69. * @version $Id: PSVIElementNSImpl.java,v 1.7 2004/02/05 18:26:31 mrglavas Exp $
  70. */
  71. public class PSVIElementNSImpl extends ElementNSImpl implements ElementPSVI {
  72. /** Serialization version. */
  73. static final long serialVersionUID = 6815489624636016068L;
  74. /**
  75. * Construct an element node.
  76. */
  77. public PSVIElementNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI,
  78. String qualifiedName, String localName) {
  79. super(ownerDocument, namespaceURI, qualifiedName, localName);
  80. }
  81. /**
  82. * Construct an element node.
  83. */
  84. public PSVIElementNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI,
  85. String qualifiedName) {
  86. super(ownerDocument, namespaceURI, qualifiedName);
  87. }
  88. /** element declaration */
  89. protected XSElementDeclaration fDeclaration = null;
  90. /** type of element, could be xsi:type */
  91. protected XSTypeDefinition fTypeDecl = null;
  92. /** true if clause 3.2 of Element Locally Valid (Element) (3.3.4)
  93. * is satisfied, otherwise false
  94. */
  95. protected boolean fNil = false;
  96. /** false if the element value was provided by the schema; true otherwise.
  97. */
  98. protected boolean fSpecified = true;
  99. /** schema normalized value property */
  100. protected String fNormalizedValue = null;
  101. /** schema actual value */
  102. protected Object fActualValue = null;
  103. /** schema actual value type */
  104. protected short fActualValueType = XSConstants.UNAVAILABLE_DT;
  105. /** actual value types if the value is a list */
  106. protected ShortList fItemValueTypes = null;
  107. /** http://www.w3.org/TR/xmlschema-1/#e-notation*/
  108. protected XSNotationDeclaration fNotation = null;
  109. /** member type definition against which element was validated */
  110. protected XSSimpleTypeDefinition fMemberType = null;
  111. /** validation attempted: none, partial, full */
  112. protected short fValidationAttempted = ElementPSVI.VALIDATION_NONE;
  113. /** validity: valid, invalid, unknown */
  114. protected short fValidity = ElementPSVI.VALIDITY_NOTKNOWN;
  115. /** error codes */
  116. protected StringList fErrorCodes = null;
  117. /** validation context: could be QName or XPath expression*/
  118. protected String fValidationContext = null;
  119. /** the schema information property */
  120. protected XSModel fSchemaInformation = null;
  121. //
  122. // ElementPSVI methods
  123. //
  124. /**
  125. * [schema default]
  126. *
  127. * @return The canonical lexical representation of the declaration's {value constraint} value.
  128. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_default>XML Schema Part 1: Structures [schema default]</a>
  129. */
  130. public String getSchemaDefault() {
  131. return fDeclaration == null ? null : fDeclaration.getConstraintValue();
  132. }
  133. /**
  134. * [schema normalized value]
  135. *
  136. *
  137. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_normalized_value>XML Schema Part 1: Structures [schema normalized value]</a>
  138. * @return the normalized value of this item after validation
  139. */
  140. public String getSchemaNormalizedValue() {
  141. return fNormalizedValue;
  142. }
  143. /**
  144. * [schema specified]
  145. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
  146. * @return false value was specified in schema, true value comes from the infoset
  147. */
  148. public boolean getIsSchemaSpecified() {
  149. return fSpecified;
  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. * Determine the validity of the node with respect
  162. * to the validation being attempted
  163. *
  164. * @return return the [validity] property. Possible values are:
  165. * UNKNOWN_VALIDITY, INVALID_VALIDITY, VALID_VALIDITY
  166. */
  167. public short getValidity() {
  168. return fValidity;
  169. }
  170. /**
  171. * A list of error codes generated from validation attempts.
  172. * Need to find all the possible subclause reports that need reporting
  173. *
  174. * @return Array of error codes
  175. */
  176. public StringList getErrorCodes() {
  177. return fErrorCodes;
  178. }
  179. // This is the only information we can provide in a pipeline.
  180. public String getValidationContext() {
  181. return fValidationContext;
  182. }
  183. /**
  184. * [nil]
  185. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-nil>XML Schema Part 1: Structures [nil]</a>
  186. * @return true if clause 3.2 of Element Locally Valid (Element) (3.3.4) above is satisfied, otherwise false
  187. */
  188. public boolean getNil() {
  189. return fNil;
  190. }
  191. /**
  192. * [notation]
  193. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-notation>XML Schema Part 1: Structures [notation]</a>
  194. * @return The notation declaration.
  195. */
  196. public XSNotationDeclaration getNotation() {
  197. return fNotation;
  198. }
  199. /**
  200. * An item isomorphic to the type definition used to validate this element.
  201. *
  202. * @return a type declaration
  203. */
  204. public XSTypeDefinition getTypeDefinition() {
  205. return fTypeDecl;
  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. * An item isomorphic to the element declaration used to validate
  221. * this element.
  222. *
  223. * @return an element declaration
  224. */
  225. public XSElementDeclaration getElementDeclaration() {
  226. return fDeclaration;
  227. }
  228. /**
  229. * [schema information]
  230. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_information">XML Schema Part 1: Structures [schema information]</a>
  231. * @return The schema information property if it's the validation root,
  232. * null otherwise.
  233. */
  234. public XSModel getSchemaInformation() {
  235. return fSchemaInformation;
  236. }
  237. /**
  238. * Copy PSVI properties from another psvi item.
  239. *
  240. * @param attr the source of attribute PSVI items
  241. */
  242. public void setPSVI(ElementPSVI elem) {
  243. this.fDeclaration = elem.getElementDeclaration();
  244. this.fNotation = elem.getNotation();
  245. this.fValidationContext = elem.getValidationContext();
  246. this.fTypeDecl = elem.getTypeDefinition();
  247. this.fSchemaInformation = elem.getSchemaInformation();
  248. this.fValidity = elem.getValidity();
  249. this.fValidationAttempted = elem.getValidationAttempted();
  250. this.fErrorCodes = elem.getErrorCodes();
  251. this.fNormalizedValue = elem.getSchemaNormalizedValue();
  252. this.fActualValue = elem.getActualNormalizedValue();
  253. this.fActualValueType = elem.getActualNormalizedValueType();
  254. this.fItemValueTypes = elem.getItemValueTypes();
  255. this.fMemberType = elem.getMemberTypeDefinition();
  256. this.fSpecified = elem.getIsSchemaSpecified();
  257. }
  258. /* (non-Javadoc)
  259. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValue()
  260. */
  261. public Object getActualNormalizedValue() {
  262. return this.fActualValue;
  263. }
  264. /* (non-Javadoc)
  265. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValueType()
  266. */
  267. public short getActualNormalizedValueType() {
  268. return this.fActualValueType;
  269. }
  270. /* (non-Javadoc)
  271. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getItemValueTypes()
  272. */
  273. public ShortList getItemValueTypes() {
  274. return this.fItemValueTypes;
  275. }
  276. // REVISIT: Forbid serialization of PSVI DOM until
  277. // we support object serialization of grammars -- mrglavas
  278. private void writeObject(ObjectOutputStream out)
  279. throws IOException {
  280. throw new NotSerializableException(getClass().getName());
  281. }
  282. private void readObject(ObjectInputStream in)
  283. throws IOException, ClassNotFoundException {
  284. throw new NotSerializableException(getClass().getName());
  285. }
  286. }