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.AttributePSVI;
  63. import com.sun.org.apache.xerces.internal.xs.*;
  64. /**
  65. * Attribute namespace implementation; stores PSVI attribute items.
  66. *
  67. * @author Sandy Gao, IBM
  68. *
  69. * @version $Id: PSVIAttrNSImpl.java,v 1.7 2004/02/05 18:26:31 mrglavas Exp $
  70. */
  71. public class PSVIAttrNSImpl extends AttrNSImpl implements AttributePSVI {
  72. /** Serialization version. */
  73. static final long serialVersionUID = -3241738699421018889L;
  74. /**
  75. * Construct an attribute node.
  76. */
  77. public PSVIAttrNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI,
  78. String qualifiedName, String localName) {
  79. super(ownerDocument, namespaceURI, qualifiedName, localName);
  80. }
  81. /**
  82. * Construct an attribute node.
  83. */
  84. public PSVIAttrNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI,
  85. String qualifiedName) {
  86. super(ownerDocument, namespaceURI, qualifiedName);
  87. }
  88. /** attribute declaration */
  89. protected XSAttributeDeclaration fDeclaration = null;
  90. /** type of attribute, simpleType */
  91. protected XSTypeDefinition fTypeDecl = null;
  92. /** If this attribute was explicitly given a
  93. * value in the original document, this is true; otherwise, it is false */
  94. protected boolean fSpecified = true;
  95. /** schema normalized value property */
  96. protected String fNormalizedValue = null;
  97. /** schema actual value */
  98. protected Object fActualValue = null;
  99. /** schema actual value type */
  100. protected short fActualValueType = XSConstants.UNAVAILABLE_DT;
  101. /** actual value types if the value is a list */
  102. protected ShortList fItemValueTypes = null;
  103. /** member type definition against which attribute was validated */
  104. protected XSSimpleTypeDefinition fMemberType = null;
  105. /** validation attempted: none, partial, full */
  106. protected short fValidationAttempted = AttributePSVI.VALIDATION_NONE;
  107. /** validity: valid, invalid, unknown */
  108. protected short fValidity = AttributePSVI.VALIDITY_NOTKNOWN;
  109. /** error codes */
  110. protected StringList fErrorCodes = null;
  111. /** validation context: could be QName or XPath expression*/
  112. protected String fValidationContext = null;
  113. //
  114. // AttributePSVI methods
  115. //
  116. /**
  117. * [schema default]
  118. *
  119. * @return The canonical lexical representation of the declaration's {value constraint} value.
  120. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_default>XML Schema Part 1: Structures [schema default]</a>
  121. */
  122. public String getSchemaDefault() {
  123. return fDeclaration == null ? null : fDeclaration.getConstraintValue();
  124. }
  125. /**
  126. * [schema normalized value]
  127. *
  128. *
  129. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_normalized_value>XML Schema Part 1: Structures [schema normalized value]</a>
  130. * @return the normalized value of this item after validation
  131. */
  132. public String getSchemaNormalizedValue() {
  133. return fNormalizedValue;
  134. }
  135. /**
  136. * [schema specified]
  137. * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
  138. * @return false value was specified in schema, true value comes from the infoset
  139. */
  140. public boolean getIsSchemaSpecified() {
  141. return fSpecified;
  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. * Determine the validity of the node with respect
  154. * to the validation being attempted
  155. *
  156. * @return return the [validity] property. Possible values are:
  157. * UNKNOWN_VALIDITY, INVALID_VALIDITY, VALID_VALIDITY
  158. */
  159. public short getValidity() {
  160. return fValidity;
  161. }
  162. /**
  163. * A list of error codes generated from validation attempts.
  164. * Need to find all the possible subclause reports that need reporting
  165. *
  166. * @return list of error codes
  167. */
  168. public StringList getErrorCodes() {
  169. return fErrorCodes;
  170. }
  171. // This is the only information we can provide in a pipeline.
  172. public String getValidationContext() {
  173. return fValidationContext;
  174. }
  175. /**
  176. * An item isomorphic to the type definition used to validate this element.
  177. *
  178. * @return a type declaration
  179. */
  180. public XSTypeDefinition getTypeDefinition() {
  181. return fTypeDecl;
  182. }
  183. /**
  184. * If and only if that type definition is a simple type definition
  185. * with {variety} union, or a complex type definition whose {content type}
  186. * is a simple thype definition with {variety} union, then an item isomorphic
  187. * to that member of the union's {member type definitions} which actually
  188. * validated the element item's normalized value.
  189. *
  190. * @return a simple type declaration
  191. */
  192. public XSSimpleTypeDefinition getMemberTypeDefinition() {
  193. return fMemberType;
  194. }
  195. /**
  196. * An item isomorphic to the attribute declaration used to validate
  197. * this attribute.
  198. *
  199. * @return an attribute declaration
  200. */
  201. public XSAttributeDeclaration getAttributeDeclaration() {
  202. return fDeclaration;
  203. }
  204. /**
  205. * Copy PSVI properties from another psvi item.
  206. *
  207. * @param attr the source of attribute PSVI items
  208. */
  209. public void setPSVI(AttributePSVI attr) {
  210. this.fDeclaration = attr.getAttributeDeclaration();
  211. this.fValidationContext = attr.getValidationContext();
  212. this.fValidity = attr.getValidity();
  213. this.fValidationAttempted = attr.getValidationAttempted();
  214. this.fErrorCodes = attr.getErrorCodes();
  215. this.fNormalizedValue = attr.getSchemaNormalizedValue();
  216. this.fActualValue = attr.getActualNormalizedValue();
  217. this.fActualValueType = attr.getActualNormalizedValueType();
  218. this.fItemValueTypes = attr.getItemValueTypes();
  219. this.fTypeDecl = attr.getTypeDefinition();
  220. this.fMemberType = attr.getMemberTypeDefinition();
  221. this.fSpecified = attr.getIsSchemaSpecified();
  222. }
  223. /* (non-Javadoc)
  224. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValue()
  225. */
  226. public Object getActualNormalizedValue() {
  227. return this.fActualValue;
  228. }
  229. /* (non-Javadoc)
  230. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getActualNormalizedValueType()
  231. */
  232. public short getActualNormalizedValueType() {
  233. return this.fActualValueType;
  234. }
  235. /* (non-Javadoc)
  236. * @see com.sun.org.apache.xerces.internal.xs.ItemPSVI#getItemValueTypes()
  237. */
  238. public ShortList getItemValueTypes() {
  239. return this.fItemValueTypes;
  240. }
  241. // REVISIT: Forbid serialization of PSVI DOM until
  242. // we support object serialization of grammars -- mrglavas
  243. private void writeObject(ObjectOutputStream out)
  244. throws IOException {
  245. throw new NotSerializableException(getClass().getName());
  246. }
  247. private void readObject(ObjectInputStream in)
  248. throws IOException, ClassNotFoundException {
  249. throw new NotSerializableException(getClass().getName());
  250. }
  251. }