View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 1999-2002,2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package com.sun.org.apache.xerces.internal.impl.xs;
22  
23  import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;
24  import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl;
25  import com.sun.org.apache.xerces.internal.xs.ShortList;
26  import com.sun.org.apache.xerces.internal.xs.XSAttributeDeclaration;
27  import com.sun.org.apache.xerces.internal.xs.XSAttributeUse;
28  import com.sun.org.apache.xerces.internal.xs.XSConstants;
29  import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem;
30  import com.sun.org.apache.xerces.internal.xs.XSObjectList;
31  
32  /**
33   * The XML representation for an attribute use
34   * schema component is a local <attribute> element information item
35   *
36   * @xerces.internal
37   *
38   * @author Sandy Gao, IBM
39   * @version $Id: XSAttributeUseImpl.java,v 1.7 2010-11-01 04:39:55 joehw Exp $
40   */
41  public class XSAttributeUseImpl implements XSAttributeUse {
42  
43      // the referred attribute decl
44      public XSAttributeDecl fAttrDecl = null;
45      // use information: SchemaSymbols.USE_OPTIONAL, REQUIRED, PROHIBITED
46      public short fUse = SchemaSymbols.USE_OPTIONAL;
47      // value constraint type: default, fixed or !specified
48      public short fConstraintType = XSConstants.VC_NONE;
49      // value constraint value
50      public ValidatedInfo fDefault = null;
51      // optional annotation
52      public XSObjectList fAnnotations = null;
53  
54      public void reset(){
55          fDefault = null;
56          fAttrDecl = null;
57          fUse = SchemaSymbols.USE_OPTIONAL;
58          fConstraintType = XSConstants.VC_NONE;
59          fAnnotations = null;
60      }
61  
62      /**
63       * Get the type of the object, i.e ELEMENT_DECLARATION.
64       */
65      public short getType() {
66          return XSConstants.ATTRIBUTE_USE;
67      }
68  
69      /**
70       * The <code>name</code> of this <code>XSObject</code> depending on the
71       * <code>XSObject</code> type.
72       */
73      public String getName() {
74          return null;
75      }
76  
77      /**
78       * The namespace URI of this node, or <code>null</code> if it is
79       * unspecified.  defines how a namespace URI is attached to schema
80       * components.
81       */
82      public String getNamespace() {
83          return null;
84      }
85  
86      /**
87       * {required} determines whether this use of an attribute declaration
88       * requires an appropriate attribute information item to be present, or
89       * merely allows it.
90       */
91      public boolean getRequired() {
92          return fUse == SchemaSymbols.USE_REQUIRED;
93      }
94  
95      /**
96       * {attribute declaration} provides the attribute declaration itself,
97       * which will in turn determine the simple type definition used.
98       */
99      public XSAttributeDeclaration getAttrDeclaration() {
100         return fAttrDecl;
101     }
102 
103     /**
104      * Value Constraint: one of default, fixed.
105      */
106     public short getConstraintType() {
107         return fConstraintType;
108     }
109 
110     /**
111      * Value Constraint: The actual value (with respect to the {type
112      * definition}).
113      */
114     public String getConstraintValue() {
115         // REVISIT: SCAPI: what's the proper representation
116         return getConstraintType() == XSConstants.VC_NONE ?
117                null :
118                fDefault.stringValue();
119     }
120 
121     /**
122      * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
123      */
124     public XSNamespaceItem getNamespaceItem() {
125         return null;
126     }
127 
128     public Object getActualVC() {
129         return getConstraintType() == XSConstants.VC_NONE ?
130                null :
131                fDefault.actualValue;
132     }
133 
134     public short getActualVCType() {
135         return getConstraintType() == XSConstants.VC_NONE ?
136                XSConstants.UNAVAILABLE_DT :
137                fDefault.actualValueType;
138     }
139 
140     public ShortList getItemValueTypes() {
141         return getConstraintType() == XSConstants.VC_NONE ?
142                null :
143                fDefault.itemValueTypes;
144     }
145 
146     /**
147      * Optional. Annotations.
148      */
149     public XSObjectList getAnnotations() {
150         return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
151     }
152 
153 } // class XSAttributeUseImpl