KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > xs > XSAttributeDecl


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
58 package com.sun.org.apache.xerces.internal.impl.xs;
59
60 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
61 import com.sun.org.apache.xerces.internal.xs.*;
62 import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;
63
64 /**
65  * The XML representation for an attribute declaration
66  * schema component is an <attribute> element information item
67  *
68  * @author Elena Litani, IBM
69  * @author Sandy Gao, IBM
70  * @version $Id: XSAttributeDecl.java,v 1.15 2003/11/12 23:17:33 sandygao Exp $
71  */

72 public class XSAttributeDecl implements XSAttributeDeclaration {
73
74     // scopes
75
public final static short SCOPE_ABSENT = 0;
76     public final static short SCOPE_GLOBAL = 1;
77     public final static short SCOPE_LOCAL = 2;
78
79     // the name of the attribute
80
String JavaDoc fName = null;
81     // the target namespace of the attribute
82
String JavaDoc fTargetNamespace = null;
83     // the simple type of the attribute
84
XSSimpleType fType = null;
85     // value constraint type: default, fixed or !specified
86
short fConstraintType = XSConstants.VC_NONE;
87     // scope
88
short fScope = XSConstants.SCOPE_ABSENT;
89     // enclosing complex type, when the scope is local
90
XSComplexTypeDecl fEnclosingCT = null;
91     // optional annotation
92
XSAnnotationImpl fAnnotation = null;
93     // value constraint value
94
ValidatedInfo fDefault = null;
95
96     public void setValues(String JavaDoc name, String JavaDoc targetNamespace,
97             XSSimpleType simpleType, short constraintType, short scope,
98             ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT,
99             XSAnnotationImpl annotation) {
100         fName = name;
101         fTargetNamespace = targetNamespace;
102         fType = simpleType;
103         fConstraintType = constraintType;
104         fScope = scope;
105         fDefault = valInfo;
106         fEnclosingCT = enclosingCT;
107         fAnnotation = annotation;
108     }
109
110     public void reset(){
111         fName = null;
112         fTargetNamespace = null;
113         fType = null;
114         fConstraintType = XSConstants.VC_NONE;
115         fScope = XSConstants.SCOPE_ABSENT;
116         fDefault = null;
117         fAnnotation = null;
118     }
119
120     /**
121      * Get the type of the object, i.e ELEMENT_DECLARATION.
122      */

123     public short getType() {
124         return XSConstants.ATTRIBUTE_DECLARATION;
125     }
126
127     /**
128      * The <code>name</code> of this <code>XSObject</code> depending on the
129      * <code>XSObject</code> type.
130      */

131     public String JavaDoc getName() {
132         return fName;
133     }
134
135     /**
136      * The namespace URI of this node, or <code>null</code> if it is
137      * unspecified. defines how a namespace URI is attached to schema
138      * components.
139      */

140     public String JavaDoc getNamespace() {
141         return fTargetNamespace;
142     }
143
144     /**
145      * A simple type definition
146      */

147     public XSSimpleTypeDefinition getTypeDefinition() {
148         return fType;
149     }
150
151     /**
152      * Optional. Either global or a complex type definition (
153      * <code>ctDefinition</code>). This property is absent in the case of
154      * declarations within attribute group definitions: their scope will be
155      * determined when they are used in the construction of complex type
156      * definitions.
157      */

158     public short getScope() {
159         return fScope;
160     }
161
162     /**
163      * Locally scoped declarations are available for use only within the
164      * complex type definition identified by the <code>scope</code>
165      * property.
166      */

167     public XSComplexTypeDefinition getEnclosingCTDefinition() {
168         return fEnclosingCT;
169     }
170
171     /**
172      * Value constraint: one of default, fixed.
173      */

174     public short getConstraintType() {
175         return fConstraintType;
176     }
177
178     /**
179      * Value constraint: The actual value (with respect to the {type
180      * definition}) Should we return Object instead of DOMString?
181      */

182     public String JavaDoc getConstraintValue() {
183         // REVISIT: SCAPI: what's the proper representation
184
return getConstraintType() == XSConstants.VC_NONE ?
185                null :
186                fDefault.stringValue();
187     }
188
189     /**
190      * Optional. Annotation.
191      */

192     public XSAnnotation getAnnotation() {
193         return fAnnotation;
194     }
195     
196     public ValidatedInfo getValInfo() {
197         return fDefault;
198     }
199     /**
200      * @see com.sun.org.apache.xerces.internal.xs.XSObject#getNamespaceItem()
201      */

202     public XSNamespaceItem getNamespaceItem() {
203         // REVISIT: implement
204
return null;
205     }
206
207     public Object JavaDoc getActualVC() {
208         return fDefault.actualValue;
209     }
210
211     public short getActualVCType() {
212         return fDefault.actualValueType;
213     }
214
215     public ShortList getItemValueTypes() {
216         return fDefault.itemValueTypes;
217     }
218
219 } // class XSAttributeDecl
220
Popular Tags