001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.xs;
019:
020: import org.apache.xerces.impl.dv.XSSimpleType;
021: import org.apache.xerces.xs.*;
022: import org.apache.xerces.impl.dv.ValidatedInfo;
023: import org.apache.xerces.impl.xs.util.XSObjectListImpl;
024:
025: /**
026: * The XML representation for an attribute declaration
027: * schema component is an <attribute> element information item
028: *
029: * @xerces.internal
030: *
031: * @author Elena Litani, IBM
032: * @author Sandy Gao, IBM
033: * @version $Id: XSAttributeDecl.java 449424 2006-09-24 16:22:30Z mrglavas $
034: */
035: public class XSAttributeDecl implements XSAttributeDeclaration {
036:
037: // scopes
038: public final static short SCOPE_ABSENT = 0;
039: public final static short SCOPE_GLOBAL = 1;
040: public final static short SCOPE_LOCAL = 2;
041:
042: // the name of the attribute
043: String fName = null;
044: // the target namespace of the attribute
045: String fTargetNamespace = null;
046: // the simple type of the attribute
047: XSSimpleType fType = null;
048: // value constraint type: default, fixed or !specified
049: short fConstraintType = XSConstants.VC_NONE;
050: // scope
051: short fScope = XSConstants.SCOPE_ABSENT;
052: // enclosing complex type, when the scope is local
053: XSComplexTypeDecl fEnclosingCT = null;
054: // optional annotations
055: XSObjectList fAnnotations = null;
056: // value constraint value
057: ValidatedInfo fDefault = null;
058:
059: public void setValues(String name, String targetNamespace,
060: XSSimpleType simpleType, short constraintType, short scope,
061: ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT,
062: XSObjectList annotations) {
063: fName = name;
064: fTargetNamespace = targetNamespace;
065: fType = simpleType;
066: fConstraintType = constraintType;
067: fScope = scope;
068: fDefault = valInfo;
069: fEnclosingCT = enclosingCT;
070: fAnnotations = annotations;
071: }
072:
073: public void reset() {
074: fName = null;
075: fTargetNamespace = null;
076: fType = null;
077: fConstraintType = XSConstants.VC_NONE;
078: fScope = XSConstants.SCOPE_ABSENT;
079: fDefault = null;
080: fAnnotations = null;
081: }
082:
083: /**
084: * Get the type of the object, i.e ELEMENT_DECLARATION.
085: */
086: public short getType() {
087: return XSConstants.ATTRIBUTE_DECLARATION;
088: }
089:
090: /**
091: * The <code>name</code> of this <code>XSObject</code> depending on the
092: * <code>XSObject</code> type.
093: */
094: public String getName() {
095: return fName;
096: }
097:
098: /**
099: * The namespace URI of this node, or <code>null</code> if it is
100: * unspecified. defines how a namespace URI is attached to schema
101: * components.
102: */
103: public String getNamespace() {
104: return fTargetNamespace;
105: }
106:
107: /**
108: * A simple type definition
109: */
110: public XSSimpleTypeDefinition getTypeDefinition() {
111: return fType;
112: }
113:
114: /**
115: * Optional. Either global or a complex type definition (
116: * <code>ctDefinition</code>). This property is absent in the case of
117: * declarations within attribute group definitions: their scope will be
118: * determined when they are used in the construction of complex type
119: * definitions.
120: */
121: public short getScope() {
122: return fScope;
123: }
124:
125: /**
126: * Locally scoped declarations are available for use only within the
127: * complex type definition identified by the <code>scope</code>
128: * property.
129: */
130: public XSComplexTypeDefinition getEnclosingCTDefinition() {
131: return fEnclosingCT;
132: }
133:
134: /**
135: * Value constraint: one of default, fixed.
136: */
137: public short getConstraintType() {
138: return fConstraintType;
139: }
140:
141: /**
142: * Value constraint: The actual value (with respect to the {type
143: * definition}) Should we return Object instead of DOMString?
144: */
145: public String getConstraintValue() {
146: // REVISIT: SCAPI: what's the proper representation
147: return getConstraintType() == XSConstants.VC_NONE ? null
148: : fDefault.stringValue();
149: }
150:
151: /**
152: * Optional. Annotation.
153: */
154: public XSAnnotation getAnnotation() {
155: return (fAnnotations != null) ? (XSAnnotation) fAnnotations
156: .item(0) : null;
157: }
158:
159: /**
160: * Optional. Annotations.
161: */
162: public XSObjectList getAnnotations() {
163: return (fAnnotations != null) ? fAnnotations
164: : XSObjectListImpl.EMPTY_LIST;
165: }
166:
167: public ValidatedInfo getValInfo() {
168: return fDefault;
169: }
170:
171: /**
172: * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
173: */
174: public XSNamespaceItem getNamespaceItem() {
175: // REVISIT: implement
176: return null;
177: }
178:
179: public Object getActualVC() {
180: return getConstraintType() == XSConstants.VC_NONE ? null
181: : fDefault.actualValue;
182: }
183:
184: public short getActualVCType() {
185: return getConstraintType() == XSConstants.VC_NONE ? XSConstants.UNAVAILABLE_DT
186: : fDefault.actualValueType;
187: }
188:
189: public ShortList getItemValueTypes() {
190: return getConstraintType() == XSConstants.VC_NONE ? null
191: : fDefault.itemValueTypes;
192: }
193:
194: } // class XSAttributeDecl
|