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.XSAttributeDeclaration;
  61. import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition;
  62. import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
  63. import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl;
  64. import com.sun.org.apache.xerces.internal.xs.AttributePSVI;
  65. import com.sun.org.apache.xerces.internal.xs.XSConstants;
  66. /**
  67. * Attribute PSV infoset augmentations implementation.
  68. * The PSVI information for attributes will be available at the startElement call.
  69. *
  70. * @author Elena Litani IBM
  71. * @version $Id: AttributePSVImpl.java,v 1.20 2003/11/12 23:17:33 sandygao Exp $
  72. */
  73. public class AttributePSVImpl implements AttributePSVI {
  74. /** attribute declaration */
  75. protected XSAttributeDeclaration fDeclaration = null;
  76. /** type of attribute, simpleType */
  77. protected XSTypeDefinition fTypeDecl = null;
  78. /** If this attribute was explicitly given a
  79. * value in the original document, this is false; otherwise, it is true */
  80. protected boolean fSpecified = false;
  81. /** schema normalized value property */
  82. protected String fNormalizedValue = null;
  83. /** schema actual value */
  84. protected Object fActualValue = null;
  85. /** schema actual value type */
  86. protected short fActualValueType = XSConstants.UNAVAILABLE_DT;
  87. /** actual value types if the value is a list */
  88. protected ShortList fItemValueTypes = null;
  89. /** member type definition against which attribute was validated */
  90. protected XSSimpleTypeDefinition fMemberType = null;
  91. /** validation attempted: none, partial, full */
  92. protected short fValidationAttempted = AttributePSVI.VALIDATION_NONE;
  93. /** validity: valid, invalid, unknown */
  94. protected short fValidity = AttributePSVI.VALIDITY_NOTKNOWN;
  95. /** error codes */
  96. protected String[] fErrorCodes = null;
  97. /** validation context: could be QName or XPath expression*/
  98. protected String fValidationContext = null;
  99. //
  100. // AttributePSVI methods
  101. //
  102. /**
  103. * [schema default]
  104. *
  105. * @return The canonical lexical representation of the declaration's {value constraint} value.
  106. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_default>XML Schema Part 1: Structures [schema default]</a>
  107. */
  108. public String getSchemaDefault() {
  109. return fDeclaration == null ? null : fDeclaration.getConstraintValue();
  110. }
  111. /**
  112. * [schema normalized value]
  113. *
  114. *
  115. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_normalized_value>XML Schema Part 1: Structures [schema normalized value]</a>
  116. * @return the normalized value of this item after validation
  117. */
  118. public String getSchemaNormalizedValue() {
  119. return fNormalizedValue;
  120. }
  121. /**
  122. * [schema specified]
  123. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
  124. * @return true - value was specified in schema, false - value comes from the infoset
  125. */
  126. public boolean getIsSchemaSpecified() {
  127. return fSpecified;
  128. }
  129. /**
  130. * Determines the extent to which the document has been validated
  131. *
  132. * @return return the [validation attempted] property. The possible values are
  133. * NO_VALIDATION, PARTIAL_VALIDATION and FULL_VALIDATION
  134. */
  135. public short getValidationAttempted() {
  136. return fValidationAttempted;
  137. }
  138. /**
  139. * Determine the validity of the node with respect
  140. * to the validation being attempted
  141. *
  142. * @return return the [validity] property. Possible values are:
  143. * UNKNOWN_VALIDITY, INVALID_VALIDITY, VALID_VALIDITY
  144. */
  145. public short getValidity() {
  146. return fValidity;
  147. }
  148. /**
  149. * A list of error codes generated from validation attempts.
  150. * Need to find all the possible subclause reports that need reporting
  151. *
  152. * @return list of error codes
  153. */
  154. public StringList getErrorCodes() {
  155. if (fErrorCodes == null)
  156. return null;
  157. return new StringListImpl(fErrorCodes, fErrorCodes.length);
  158. }
  159. // This is the only information we can provide in a pipeline.
  160. public String getValidationContext() {
  161. return fValidationContext;
  162. }
  163. /**
  164. * An item isomorphic to the type definition used to validate this element.
  165. *
  166. * @return a type declaration
  167. */
  168. public XSTypeDefinition getTypeDefinition() {
  169. return fTypeDecl;
  170. }
  171. /**
  172. * If and only if that type definition is a simple type definition
  173. * with {variety} union, or a complex type definition whose {content type}
  174. * is a simple thype definition with {variety} union, then an item isomorphic
  175. * to that member of the union's {member type definitions} which actually
  176. * validated the element item's normalized value.
  177. *
  178. * @return a simple type declaration
  179. */
  180. public XSSimpleTypeDefinition getMemberTypeDefinition() {
  181. return fMemberType;
  182. }
  183. /**
  184. * An item isomorphic to the attribute declaration used to validate
  185. * this attribute.
  186. *
  187. * @return an attribute declaration
  188. */
  189. public XSAttributeDeclaration getAttributeDeclaration() {
  190. return fDeclaration;
  191. }
  192. /* (non-Javadoc)
  193. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValue()
  194. */
  195. public Object getActualNormalizedValue() {
  196. return this.fActualValue;
  197. }
  198. /* (non-Javadoc)
  199. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValueType()
  200. */
  201. public short getActualNormalizedValueType() {
  202. return this.fActualValueType;
  203. }
  204. /* (non-Javadoc)
  205. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getItemValueTypes()
  206. */
  207. public ShortList getItemValueTypes() {
  208. return this.fItemValueTypes;
  209. }
  210. /**
  211. * Reset()
  212. */
  213. public void reset() {
  214. fNormalizedValue = null;
  215. fActualValue = null;
  216. fActualValueType = XSConstants.UNAVAILABLE_DT;
  217. fItemValueTypes = null;
  218. fDeclaration = null;
  219. fTypeDecl = null;
  220. fSpecified = false;
  221. fMemberType = null;
  222. fValidationAttempted = AttributePSVI.VALIDATION_NONE;
  223. fValidity = AttributePSVI.VALIDITY_NOTKNOWN;
  224. fErrorCodes = null;
  225. fValidationContext = null;
  226. }
  227. }