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  */
  40 public class XSAttributeUseImpl implements XSAttributeUse {
  41 
  42     // the referred attribute decl
  43     public XSAttributeDecl fAttrDecl = null;
  44     // use information: SchemaSymbols.USE_OPTIONAL, REQUIRED, PROHIBITED
  45     public short fUse = SchemaSymbols.USE_OPTIONAL;
  46     // value constraint type: default, fixed or !specified
  47     public short fConstraintType = XSConstants.VC_NONE;
  48     // value constraint value
  49     public ValidatedInfo fDefault = null;
  50     // optional annotation
  51     public XSObjectList fAnnotations = null;
  52 
  53     public void reset(){
  54         fDefault = null;
  55         fAttrDecl = null;
  56         fUse = SchemaSymbols.USE_OPTIONAL;
  57         fConstraintType = XSConstants.VC_NONE;
  58         fAnnotations = null;
  59     }
  60 
  61     /**
  62      * Get the type of the object, i.e ELEMENT_DECLARATION.
  63      */
  64     public short getType() {
  65         return XSConstants.ATTRIBUTE_USE;
  66     }
  67 
  68     /**
  69      * The <code>name</code> of this <code>XSObject</code> depending on the
  70      * <code>XSObject</code> type.
  71      */
  72     public String getName() {
  73         return null;
  74     }
  75 
  76     /**
  77      * The namespace URI of this node, or <code>null</code> if it is
  78      * unspecified.  defines how a namespace URI is attached to schema
  79      * components.
  80      */
  81     public String getNamespace() {
  82         return null;
  83     }
  84 
  85     /**
  86      * {required} determines whether this use of an attribute declaration
  87      * requires an appropriate attribute information item to be present, or
  88      * merely allows it.
  89      */
  90     public boolean getRequired() {
  91         return fUse == SchemaSymbols.USE_REQUIRED;
  92     }
  93 
  94     /**
  95      * {attribute declaration} provides the attribute declaration itself,
  96      * which will in turn determine the simple type definition used.
  97      */
  98     public XSAttributeDeclaration getAttrDeclaration() {
  99         return fAttrDecl;
 100     }
 101 
 102     /**
 103      * Value Constraint: one of default, fixed.
 104      */
 105     public short getConstraintType() {
 106         return fConstraintType;
 107     }
 108 
 109     /**
 110      * Value Constraint: The actual value (with respect to the {type
 111      * definition}).
 112      */
 113     public String getConstraintValue() {
 114         // REVISIT: SCAPI: what's the proper representation
 115         return getConstraintType() == XSConstants.VC_NONE ?
 116                null :
 117                fDefault.stringValue();
 118     }
 119 
 120     /**
 121      * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
 122      */
 123     public XSNamespaceItem getNamespaceItem() {
 124         return null;
 125     }
 126 
 127     public Object getActualVC() {
 128         return getConstraintType() == XSConstants.VC_NONE ?
 129                null :
 130                fDefault.actualValue;
 131     }
 132 
 133     public short getActualVCType() {
 134         return getConstraintType() == XSConstants.VC_NONE ?
 135                XSConstants.UNAVAILABLE_DT :
 136                fDefault.actualValueType;
 137     }
 138 
 139     public ShortList getItemValueTypes() {
 140         return getConstraintType() == XSConstants.VC_NONE ?
 141                null :
 142                fDefault.itemValueTypes;
 143     }
 144 
 145     /**
 146      * Optional. Annotations.
 147      */
 148     public XSObjectList getAnnotations() {
 149         return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
 150     }
 151 
 152 } // class XSAttributeUseImpl