KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > XSAttributeDecl


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.impl.xs;
18
19 import org.apache.xerces.impl.dv.XSSimpleType;
20 import org.apache.xerces.xs.*;
21 import org.apache.xerces.impl.dv.ValidatedInfo;
22
23 /**
24  * The XML representation for an attribute declaration
25  * schema component is an <attribute> element information item
26  *
27  * @xerces.internal
28  *
29  * @author Elena Litani, IBM
30  * @author Sandy Gao, IBM
31  * @version $Id: XSAttributeDecl.java,v 1.18 2004/12/07 18:11:27 sandygao Exp $
32  */

33 public class XSAttributeDecl implements XSAttributeDeclaration {
34
35     // scopes
36
public final static short SCOPE_ABSENT = 0;
37     public final static short SCOPE_GLOBAL = 1;
38     public final static short SCOPE_LOCAL = 2;
39
40     // the name of the attribute
41
String JavaDoc fName = null;
42     // the target namespace of the attribute
43
String JavaDoc fTargetNamespace = null;
44     // the simple type of the attribute
45
XSSimpleType fType = null;
46     // value constraint type: default, fixed or !specified
47
short fConstraintType = XSConstants.VC_NONE;
48     // scope
49
short fScope = XSConstants.SCOPE_ABSENT;
50     // enclosing complex type, when the scope is local
51
XSComplexTypeDecl fEnclosingCT = null;
52     // optional annotation
53
XSAnnotationImpl fAnnotation = null;
54     // value constraint value
55
ValidatedInfo fDefault = null;
56
57     public void setValues(String JavaDoc name, String JavaDoc targetNamespace,
58             XSSimpleType simpleType, short constraintType, short scope,
59             ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT,
60             XSAnnotationImpl annotation) {
61         fName = name;
62         fTargetNamespace = targetNamespace;
63         fType = simpleType;
64         fConstraintType = constraintType;
65         fScope = scope;
66         fDefault = valInfo;
67         fEnclosingCT = enclosingCT;
68         fAnnotation = annotation;
69     }
70
71     public void reset(){
72         fName = null;
73         fTargetNamespace = null;
74         fType = null;
75         fConstraintType = XSConstants.VC_NONE;
76         fScope = XSConstants.SCOPE_ABSENT;
77         fDefault = null;
78         fAnnotation = null;
79     }
80
81     /**
82      * Get the type of the object, i.e ELEMENT_DECLARATION.
83      */

84     public short getType() {
85         return XSConstants.ATTRIBUTE_DECLARATION;
86     }
87
88     /**
89      * The <code>name</code> of this <code>XSObject</code> depending on the
90      * <code>XSObject</code> type.
91      */

92     public String JavaDoc getName() {
93         return fName;
94     }
95
96     /**
97      * The namespace URI of this node, or <code>null</code> if it is
98      * unspecified. defines how a namespace URI is attached to schema
99      * components.
100      */

101     public String JavaDoc getNamespace() {
102         return fTargetNamespace;
103     }
104
105     /**
106      * A simple type definition
107      */

108     public XSSimpleTypeDefinition getTypeDefinition() {
109         return fType;
110     }
111
112     /**
113      * Optional. Either global or a complex type definition (
114      * <code>ctDefinition</code>). This property is absent in the case of
115      * declarations within attribute group definitions: their scope will be
116      * determined when they are used in the construction of complex type
117      * definitions.
118      */

119     public short getScope() {
120         return fScope;
121     }
122
123     /**
124      * Locally scoped declarations are available for use only within the
125      * complex type definition identified by the <code>scope</code>
126      * property.
127      */

128     public XSComplexTypeDefinition getEnclosingCTDefinition() {
129         return fEnclosingCT;
130     }
131
132     /**
133      * Value constraint: one of default, fixed.
134      */

135     public short getConstraintType() {
136         return fConstraintType;
137     }
138
139     /**
140      * Value constraint: The actual value (with respect to the {type
141      * definition}) Should we return Object instead of DOMString?
142      */

143     public String JavaDoc getConstraintValue() {
144         // REVISIT: SCAPI: what's the proper representation
145
return getConstraintType() == XSConstants.VC_NONE ?
146                null :
147                fDefault.stringValue();
148     }
149
150     /**
151      * Optional. Annotation.
152      */

153     public XSAnnotation getAnnotation() {
154         return fAnnotation;
155     }
156     
157     public ValidatedInfo getValInfo() {
158         return fDefault;
159     }
160     /**
161      * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
162      */

163     public XSNamespaceItem getNamespaceItem() {
164         // REVISIT: implement
165
return null;
166     }
167
168     public Object JavaDoc getActualVC() {
169         return getConstraintType() == XSConstants.VC_NONE ?
170                null :
171                fDefault.actualValue;
172     }
173
174     public short getActualVCType() {
175         return getConstraintType() == XSConstants.VC_NONE ?
176                XSConstants.UNAVAILABLE_DT :
177                fDefault.actualValueType;
178     }
179
180     public ShortList getItemValueTypes() {
181         return getConstraintType() == XSConstants.VC_NONE ?
182                null :
183                fDefault.itemValueTypes;
184     }
185
186 } // class XSAttributeDecl
187
Popular Tags