1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001-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.dv.XSSimpleType; 25 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 26 import com.sun.org.apache.xerces.internal.xni.QName; 27 import com.sun.org.apache.xerces.internal.xs.ShortList; 28 import com.sun.org.apache.xerces.internal.xs.XSAnnotation; 29 import com.sun.org.apache.xerces.internal.xs.XSAttributeDeclaration; 30 import com.sun.org.apache.xerces.internal.xs.XSComplexTypeDefinition; 31 import com.sun.org.apache.xerces.internal.xs.XSConstants; 32 import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem; 33 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 34 import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition; 35 36 /** 37 * The XML representation for an attribute declaration 38 * schema component is an <attribute> element information item 39 * 40 * @xerces.internal 41 * 42 * @author Elena Litani, IBM 43 * @author Sandy Gao, IBM 44 */ 45 public class XSAttributeDecl implements XSAttributeDeclaration { 46 47 // scopes 48 public final static short SCOPE_ABSENT = 0; 49 public final static short SCOPE_GLOBAL = 1; 50 public final static short SCOPE_LOCAL = 2; 51 52 // the name of the attribute 53 String fName = null; 54 // the target namespace of the attribute 55 String fTargetNamespace = null; 56 // the simple type of the attribute 57 XSSimpleType fType = null; 58 public QName fUnresolvedTypeName = null; 59 // value constraint type: default, fixed or !specified 60 short fConstraintType = XSConstants.VC_NONE; 61 // scope 62 short fScope = XSConstants.SCOPE_ABSENT; 63 // enclosing complex type, when the scope is local 64 XSComplexTypeDecl fEnclosingCT = null; 65 // optional annotations 66 XSObjectList fAnnotations = null; 67 // value constraint value 68 ValidatedInfo fDefault = null; 69 // The namespace schema information item corresponding to the target namespace 70 // of the attribute declaration, if it is globally declared; or null otherwise. 71 private XSNamespaceItem fNamespaceItem = null; 72 73 public void setValues(String name, String targetNamespace, 74 XSSimpleType simpleType, short constraintType, short scope, 75 ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT, 76 XSObjectList annotations) { 77 fName = name; 78 fTargetNamespace = targetNamespace; 79 fType = simpleType; 80 fConstraintType = constraintType; 81 fScope = scope; 82 fDefault = valInfo; 83 fEnclosingCT = enclosingCT; 84 fAnnotations = annotations; 85 } 86 87 public void reset(){ 88 fName = null; 89 fTargetNamespace = null; 90 fType = null; 91 fUnresolvedTypeName = null; 92 fConstraintType = XSConstants.VC_NONE; 93 fScope = XSConstants.SCOPE_ABSENT; 94 fDefault = null; 95 fAnnotations = null; 96 } 97 98 /** 99 * Get the type of the object, i.e ELEMENT_DECLARATION. 100 */ 101 public short getType() { 102 return XSConstants.ATTRIBUTE_DECLARATION; 103 } 104 105 /** 106 * The <code>name</code> of this <code>XSObject</code> depending on the 107 * <code>XSObject</code> type. 108 */ 109 public String getName() { 110 return fName; 111 } 112 113 /** 114 * The namespace URI of this node, or <code>null</code> if it is 115 * unspecified. defines how a namespace URI is attached to schema 116 * components. 117 */ 118 public String getNamespace() { 119 return fTargetNamespace; 120 } 121 122 /** 123 * A simple type definition 124 */ 125 public XSSimpleTypeDefinition getTypeDefinition() { 126 return fType; 127 } 128 129 /** 130 * Optional. Either global or a complex type definition ( 131 * <code>ctDefinition</code>). This property is absent in the case of 132 * declarations within attribute group definitions: their scope will be 133 * determined when they are used in the construction of complex type 134 * definitions. 135 */ 136 public short getScope() { 137 return fScope; 138 } 139 140 /** 141 * Locally scoped declarations are available for use only within the 142 * complex type definition identified by the <code>scope</code> 143 * property. 144 */ 145 public XSComplexTypeDefinition getEnclosingCTDefinition() { 146 return fEnclosingCT; 147 } 148 149 /** 150 * Value constraint: one of default, fixed. 151 */ 152 public short getConstraintType() { 153 return fConstraintType; 154 } 155 156 /** 157 * Value constraint: The actual value (with respect to the {type 158 * definition}) Should we return Object instead of DOMString? 159 */ 160 public String getConstraintValue() { 161 // REVISIT: SCAPI: what's the proper representation 162 return getConstraintType() == XSConstants.VC_NONE ? 163 null : 164 fDefault.stringValue(); 165 } 166 167 /** 168 * Optional. Annotation. 169 */ 170 public XSAnnotation getAnnotation() { 171 return (fAnnotations != null) ? (XSAnnotation) fAnnotations.item(0) : null; 172 } 173 174 /** 175 * Optional. Annotations. 176 */ 177 public XSObjectList getAnnotations() { 178 return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST; 179 } 180 181 public ValidatedInfo getValInfo() { 182 return fDefault; 183 } 184 185 /** 186 * @see org.apache.xerces.xs.XSObject#getNamespaceItem() 187 */ 188 public XSNamespaceItem getNamespaceItem() { 189 return fNamespaceItem; 190 } 191 192 void setNamespaceItem(XSNamespaceItem namespaceItem) { 193 fNamespaceItem = namespaceItem; 194 } 195 196 public Object getActualVC() { 197 return getConstraintType() == XSConstants.VC_NONE ? 198 null : 199 fDefault.actualValue; 200 } 201 202 public short getActualVCType() { 203 return getConstraintType() == XSConstants.VC_NONE ? 204 XSConstants.UNAVAILABLE_DT : 205 fDefault.actualValueType; 206 } 207 208 public ShortList getItemValueTypes() { 209 return getConstraintType() == XSConstants.VC_NONE ? 210 null : 211 fDefault.itemValueTypes; 212 } 213 214 } // class XSAttributeDecl