1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2001-2003 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) 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.impl.dv.XSSimpleType;
  59. import com.sun.org.apache.xerces.internal.xs.*;
  60. import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;
  61. /**
  62. * The XML representation for an attribute declaration
  63. * schema component is an <attribute> element information item
  64. *
  65. * @author Elena Litani, IBM
  66. * @author Sandy Gao, IBM
  67. * @version $Id: XSAttributeDecl.java,v 1.15 2003/11/12 23:17:33 sandygao Exp $
  68. */
  69. public class XSAttributeDecl implements XSAttributeDeclaration {
  70. // scopes
  71. public final static short SCOPE_ABSENT = 0;
  72. public final static short SCOPE_GLOBAL = 1;
  73. public final static short SCOPE_LOCAL = 2;
  74. // the name of the attribute
  75. String fName = null;
  76. // the target namespace of the attribute
  77. String fTargetNamespace = null;
  78. // the simple type of the attribute
  79. XSSimpleType fType = null;
  80. // value constraint type: default, fixed or !specified
  81. short fConstraintType = XSConstants.VC_NONE;
  82. // scope
  83. short fScope = XSConstants.SCOPE_ABSENT;
  84. // enclosing complex type, when the scope is local
  85. XSComplexTypeDecl fEnclosingCT = null;
  86. // optional annotation
  87. XSAnnotationImpl fAnnotation = null;
  88. // value constraint value
  89. ValidatedInfo fDefault = null;
  90. public void setValues(String name, String targetNamespace,
  91. XSSimpleType simpleType, short constraintType, short scope,
  92. ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT,
  93. XSAnnotationImpl annotation) {
  94. fName = name;
  95. fTargetNamespace = targetNamespace;
  96. fType = simpleType;
  97. fConstraintType = constraintType;
  98. fScope = scope;
  99. fDefault = valInfo;
  100. fEnclosingCT = enclosingCT;
  101. fAnnotation = annotation;
  102. }
  103. public void reset(){
  104. fName = null;
  105. fTargetNamespace = null;
  106. fType = null;
  107. fConstraintType = XSConstants.VC_NONE;
  108. fScope = XSConstants.SCOPE_ABSENT;
  109. fDefault = null;
  110. fAnnotation = null;
  111. }
  112. /**
  113. * Get the type of the object, i.e ELEMENT_DECLARATION.
  114. */
  115. public short getType() {
  116. return XSConstants.ATTRIBUTE_DECLARATION;
  117. }
  118. /**
  119. * The <code>name</code> of this <code>XSObject</code> depending on the
  120. * <code>XSObject</code> type.
  121. */
  122. public String getName() {
  123. return fName;
  124. }
  125. /**
  126. * The namespace URI of this node, or <code>null</code> if it is
  127. * unspecified. defines how a namespace URI is attached to schema
  128. * components.
  129. */
  130. public String getNamespace() {
  131. return fTargetNamespace;
  132. }
  133. /**
  134. * A simple type definition
  135. */
  136. public XSSimpleTypeDefinition getTypeDefinition() {
  137. return fType;
  138. }
  139. /**
  140. * Optional. Either global or a complex type definition (
  141. * <code>ctDefinition</code>). This property is absent in the case of
  142. * declarations within attribute group definitions: their scope will be
  143. * determined when they are used in the construction of complex type
  144. * definitions.
  145. */
  146. public short getScope() {
  147. return fScope;
  148. }
  149. /**
  150. * Locally scoped declarations are available for use only within the
  151. * complex type definition identified by the <code>scope</code>
  152. * property.
  153. */
  154. public XSComplexTypeDefinition getEnclosingCTDefinition() {
  155. return fEnclosingCT;
  156. }
  157. /**
  158. * Value constraint: one of default, fixed.
  159. */
  160. public short getConstraintType() {
  161. return fConstraintType;
  162. }
  163. /**
  164. * Value constraint: The actual value (with respect to the {type
  165. * definition}) Should we return Object instead of DOMString?
  166. */
  167. public String getConstraintValue() {
  168. // REVISIT: SCAPI: what's the proper representation
  169. return getConstraintType() == XSConstants.VC_NONE ?
  170. null :
  171. fDefault.stringValue();
  172. }
  173. /**
  174. * Optional. Annotation.
  175. */
  176. public XSAnnotation getAnnotation() {
  177. return fAnnotation;
  178. }
  179. public ValidatedInfo getValInfo() {
  180. return fDefault;
  181. }
  182. /**
  183. * @see com.sun.org.apache.xerces.internal.xs.XSObject#getNamespaceItem()
  184. */
  185. public XSNamespaceItem getNamespaceItem() {
  186. // REVISIT: implement
  187. return null;
  188. }
  189. public Object getActualVC() {
  190. return fDefault.actualValue;
  191. }
  192. public short getActualVCType() {
  193. return fDefault.actualValueType;
  194. }
  195. public ShortList getItemValueTypes() {
  196. return fDefault.itemValueTypes;
  197. }
  198. } // class XSAttributeDecl