1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2000-2002 The Apache Software Foundation.
  6. * All rights 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) 2001, 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.impl.xs;
  58. import com.sun.org.apache.xerces.internal.xs.ShortList;
  59. import com.sun.org.apache.xerces.internal.xs.StringList;
  60. import com.sun.org.apache.xerces.internal.xs.XSElementDeclaration;
  61. import com.sun.org.apache.xerces.internal.xs.XSModel;
  62. import com.sun.org.apache.xerces.internal.xs.XSNotationDeclaration;
  63. import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition;
  64. import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
  65. import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl;
  66. import com.sun.org.apache.xerces.internal.xs.ElementPSVI;
  67. import com.sun.org.apache.xerces.internal.xs.XSConstants;
  68. /**
  69. * Element PSV infoset augmentations implementation.
  70. * The following information will be available at the startElement call:
  71. * name, namespace, type, notation, validation context
  72. *
  73. * The following information will be available at the endElement call:
  74. * nil, specified, normalized value, member type, validity, error codes,
  75. * default
  76. *
  77. * @author Elena Litani IBM
  78. * @version $Id: ElementPSVImpl.java,v 1.24 2003/11/12 23:17:33 sandygao Exp $
  79. */
  80. public class ElementPSVImpl implements ElementPSVI {
  81. /** element declaration */
  82. protected XSElementDeclaration fDeclaration = null;
  83. /** type of element, could be xsi:type */
  84. protected XSTypeDefinition fTypeDecl = null;
  85. /** true if clause 3.2 of Element Locally Valid (Element) (3.3.4)
  86. * is satisfied, otherwise false
  87. */
  88. protected boolean fNil = false;
  89. /** true if the element value was provided by the schema; false otherwise.
  90. */
  91. protected boolean fSpecified = false;
  92. /** schema normalized value property */
  93. protected String fNormalizedValue = null;
  94. /** schema actual value */
  95. protected Object fActualValue = null;
  96. /** schema actual value type */
  97. protected short fActualValueType = XSConstants.UNAVAILABLE_DT;
  98. /** actual value types if the value is a list */
  99. protected ShortList fItemValueTypes = null;
  100. /** http://www.w3.org/TR/xmlschema-1/#e-notation*/
  101. protected XSNotationDeclaration fNotation = null;
  102. /** member type definition against which element was validated */
  103. protected XSSimpleTypeDefinition fMemberType = null;
  104. /** validation attempted: none, partial, full */
  105. protected short fValidationAttempted = ElementPSVI.VALIDATION_NONE;
  106. /** validity: valid, invalid, unknown */
  107. protected short fValidity = ElementPSVI.VALIDITY_NOTKNOWN;
  108. /** error codes */
  109. protected String[] fErrorCodes = null;
  110. /** validation context: could be QName or XPath expression*/
  111. protected String fValidationContext = null;
  112. /** the schema information property */
  113. protected XSModel fSchemaInformation = null;
  114. //
  115. // ElementPSVI methods
  116. //
  117. /**
  118. * [schema default]
  119. *
  120. * @return The canonical lexical representation of the declaration's {value constraint} value.
  121. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_default>XML Schema Part 1: Structures [schema default]</a>
  122. */
  123. public String getSchemaDefault() {
  124. return fDeclaration == null ? null : fDeclaration.getConstraintValue();
  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 fNormalizedValue;
  135. }
  136. /**
  137. * [schema specified]
  138. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
  139. * @return true - value was specified in schema, false - value comes from the infoset
  140. */
  141. public boolean getIsSchemaSpecified() {
  142. return fSpecified;
  143. }
  144. /**
  145. * Determines the extent to which the document has been validated
  146. *
  147. * @return return the [validation attempted] property. The possible values are
  148. * NO_VALIDATION, PARTIAL_VALIDATION and FULL_VALIDATION
  149. */
  150. public short getValidationAttempted() {
  151. return fValidationAttempted;
  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. * A list of error codes generated from validation attempts.
  165. * Need to find all the possible subclause reports that need reporting
  166. *
  167. * @return Array of error codes
  168. */
  169. public StringList getErrorCodes() {
  170. if (fErrorCodes == null)
  171. return null;
  172. return new StringListImpl(fErrorCodes, fErrorCodes.length);
  173. }
  174. // This is the only information we can provide in a pipeline.
  175. public String getValidationContext() {
  176. return fValidationContext;
  177. }
  178. /**
  179. * [nil]
  180. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-nil>XML Schema Part 1: Structures [nil]</a>
  181. * @return true if clause 3.2 of Element Locally Valid (Element) (3.3.4) above is satisfied, otherwise false
  182. */
  183. public boolean getNil() {
  184. return fNil;
  185. }
  186. /**
  187. * [notation]
  188. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-notation>XML Schema Part 1: Structures [notation]</a>
  189. * @return The notation declaration.
  190. */
  191. public XSNotationDeclaration getNotation() {
  192. return fNotation;
  193. }
  194. /**
  195. * An item isomorphic to the type definition used to validate this element.
  196. *
  197. * @return a type declaration
  198. */
  199. public XSTypeDefinition getTypeDefinition() {
  200. return fTypeDecl;
  201. }
  202. /**
  203. * If and only if that type definition is a simple type definition
  204. * with {variety} union, or a complex type definition whose {content type}
  205. * is a simple thype definition with {variety} union, then an item isomorphic
  206. * to that member of the union's {member type definitions} which actually
  207. * validated the element item's normalized value.
  208. *
  209. * @return a simple type declaration
  210. */
  211. public XSSimpleTypeDefinition getMemberTypeDefinition() {
  212. return fMemberType;
  213. }
  214. /**
  215. * An item isomorphic to the element declaration used to validate
  216. * this element.
  217. *
  218. * @return an element declaration
  219. */
  220. public XSElementDeclaration getElementDeclaration() {
  221. return fDeclaration;
  222. }
  223. /**
  224. * [schema information]
  225. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_information">XML Schema Part 1: Structures [schema information]</a>
  226. * @return The schema information property if it's the validation root,
  227. * null otherwise.
  228. */
  229. public XSModel getSchemaInformation() {
  230. return fSchemaInformation;
  231. }
  232. /* (non-Javadoc)
  233. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValue()
  234. */
  235. public Object getActualNormalizedValue() {
  236. return this.fActualValue;
  237. }
  238. /* (non-Javadoc)
  239. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValueType()
  240. */
  241. public short getActualNormalizedValueType() {
  242. return this.fActualValueType;
  243. }
  244. /* (non-Javadoc)
  245. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getItemValueTypes()
  246. */
  247. public ShortList getItemValueTypes() {
  248. return this.fItemValueTypes;
  249. }
  250. /**
  251. * Reset() should be called in validator startElement(..) method.
  252. */
  253. public void reset() {
  254. fDeclaration = null;
  255. fTypeDecl = null;
  256. fNil = false;
  257. fSpecified = false;
  258. fNotation = null;
  259. fMemberType = null;
  260. fValidationAttempted = ElementPSVI.VALIDATION_NONE;
  261. fValidity = ElementPSVI.VALIDITY_NOTKNOWN;
  262. fErrorCodes = null;
  263. fValidationContext = null;
  264. fNormalizedValue = null;
  265. fActualValue = null;
  266. fActualValueType = XSConstants.UNAVAILABLE_DT;
  267. fItemValueTypes = null;
  268. }
  269. }