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