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.ValidatedInfo;
021: import org.apache.xerces.impl.xs.util.XSObjectListImpl;
022: import org.apache.xerces.xs.ShortList;
023: import org.apache.xerces.xs.XSAttributeDeclaration;
024: import org.apache.xerces.xs.XSAttributeUse;
025: import org.apache.xerces.xs.XSConstants;
026: import org.apache.xerces.xs.XSNamespaceItem;
027: import org.apache.xerces.xs.XSObjectList;
028:
029: /**
030: * The XML representation for an attribute use
031: * schema component is a local <attribute> element information item
032: *
033: * @xerces.internal
034: *
035: * @author Sandy Gao, IBM
036: * @version $Id: XSAttributeUseImpl.java 545988 2007-06-11 02:00:30Z mrglavas $
037: */
038: public class XSAttributeUseImpl implements XSAttributeUse {
039:
040: // the referred attribute decl
041: public XSAttributeDecl fAttrDecl = null;
042: // use information: SchemaSymbols.USE_OPTIONAL, REQUIRED, PROHIBITED
043: public short fUse = SchemaSymbols.USE_OPTIONAL;
044: // value constraint type: default, fixed or !specified
045: public short fConstraintType = XSConstants.VC_NONE;
046: // value constraint value
047: public ValidatedInfo fDefault = null;
048: // optional annotation
049: public XSObjectList fAnnotations = null;
050:
051: public void reset() {
052: fDefault = null;
053: fAttrDecl = null;
054: fUse = SchemaSymbols.USE_OPTIONAL;
055: fConstraintType = XSConstants.VC_NONE;
056: fAnnotations = null;
057: }
058:
059: /**
060: * Get the type of the object, i.e ELEMENT_DECLARATION.
061: */
062: public short getType() {
063: return XSConstants.ATTRIBUTE_USE;
064: }
065:
066: /**
067: * The <code>name</code> of this <code>XSObject</code> depending on the
068: * <code>XSObject</code> type.
069: */
070: public String getName() {
071: return null;
072: }
073:
074: /**
075: * The namespace URI of this node, or <code>null</code> if it is
076: * unspecified. defines how a namespace URI is attached to schema
077: * components.
078: */
079: public String getNamespace() {
080: return null;
081: }
082:
083: /**
084: * {required} determines whether this use of an attribute declaration
085: * requires an appropriate attribute information item to be present, or
086: * merely allows it.
087: */
088: public boolean getRequired() {
089: return fUse == SchemaSymbols.USE_REQUIRED;
090: }
091:
092: /**
093: * {attribute declaration} provides the attribute declaration itself,
094: * which will in turn determine the simple type definition used.
095: */
096: public XSAttributeDeclaration getAttrDeclaration() {
097: return fAttrDecl;
098: }
099:
100: /**
101: * Value Constraint: one of default, fixed.
102: */
103: public short getConstraintType() {
104: return fConstraintType;
105: }
106:
107: /**
108: * Value Constraint: The actual value (with respect to the {type
109: * definition}).
110: */
111: public String getConstraintValue() {
112: // REVISIT: SCAPI: what's the proper representation
113: return getConstraintType() == XSConstants.VC_NONE ? null
114: : fDefault.stringValue();
115: }
116:
117: /**
118: * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
119: */
120: public XSNamespaceItem getNamespaceItem() {
121: return null;
122: }
123:
124: public Object getActualVC() {
125: return getConstraintType() == XSConstants.VC_NONE ? null
126: : fDefault.actualValue;
127: }
128:
129: public short getActualVCType() {
130: return getConstraintType() == XSConstants.VC_NONE ? XSConstants.UNAVAILABLE_DT
131: : fDefault.actualValueType;
132: }
133:
134: public ShortList getItemValueTypes() {
135: return getConstraintType() == XSConstants.VC_NONE ? null
136: : fDefault.itemValueTypes;
137: }
138:
139: /**
140: * Optional. Annotations.
141: */
142: public XSObjectList getAnnotations() {
143: return (fAnnotations != null) ? fAnnotations
144: : XSObjectListImpl.EMPTY_LIST;
145: }
146:
147: } // class XSAttributeUseImpl
|