1 22 23 package org.xquark.schema; 24 25 import java.util.*; 26 27 48 public class ElementDeclaration extends Declaration { 49 private static final String RCSRevision = "$Revision: 1.1 $"; 50 private static final String RCSName = "$Name: $"; 51 52 private boolean nillable = false; 53 private boolean abs = false; 54 private int block = 0; 55 private int fin = 0; 56 private SchemaComponent substitutionGroup = null; 57 private ArrayList substitutionElementList = null; 58 private HashMap identityConstraints = null; 59 60 68 public ElementDeclaration(Schema schema, String name, SchemaScope scope) { 69 super(schema, name, scope); 70 } 71 72 public void accept(SchemaVisitor visitor) throws SchemaException { 73 visitor.visit(this); 74 } 75 76 public boolean isAbstract() { 77 return abs; 78 } 79 80 85 public boolean isNillable() { 86 return nillable; 87 } 88 89 public int getBlock() { 90 return block; 91 } 92 93 public int getFinal() { 94 return fin; 95 } 96 97 103 public SchemaComponent getSubstitutionGroup() { 104 return substitutionGroup; 105 } 106 107 public List getSubstitutionElementList() { 108 if (scope.isGlobalScope()) return substitutionElementList; 116 else return null; 117 } 118 119 public void setAbstract(boolean abs) { 120 this.abs = abs; 121 } 122 123 public void setNillable(boolean nillable) { 124 this.nillable = nillable; 125 } 126 127 public void setBlock(int block) { 128 this.block = block; 129 } 130 131 public void setFinal(int fin) { 132 this.fin = fin; 133 } 134 135 public void setSubstitutionGroup(SchemaComponent substitutionGroup) { 136 this.substitutionGroup = substitutionGroup; 137 } 138 139 void addSubstitutionMember(ElementDeclaration anElement) { 140 if (substitutionElementList == null) 141 substitutionElementList = new ArrayList(); 142 substitutionElementList.add(anElement); 143 } 144 145 public ElementDeclaration getSubstitutionElement(String namespace, String localName) 146 { 147 List list = getSubstitutionElementList(); 148 if (list == null) return null; 149 Iterator it = list.iterator(); 150 while (it.hasNext()) { 151 ElementDeclaration anElement = (ElementDeclaration)it.next(); 152 if (anElement.hasName(namespace, localName)) return anElement; 154 } 155 156 return null; 157 } 158 159 public void fillAllConcreteSubstitutionElements(List result) { 160 List list = getSubstitutionElementList(); 161 if ( list == null ) return; 162 Iterator it = list.iterator(); 163 while (it.hasNext()) { 164 ElementDeclaration anElement = (ElementDeclaration)it.next(); 165 if (!anElement.isAbstract()) result.add(anElement); 166 } 167 } 168 169 public void register(IdentityConstraint identityConstraint) { 171 if ( identityConstraints == null ) identityConstraints = new HashMap(); 172 identityConstraints.put(identityConstraint.getName(), identityConstraint); 173 } 174 175 180 public Collection getIdentityConstraints() { 181 if ( identityConstraints == null ) return null; 182 return identityConstraints.values(); 183 } 184 185 public IdentityConstraint getIdentityConstraint(String name) { 186 if ( identityConstraints == null ) return null; 187 if ( name.indexOf(':') != -1 ) { 188 name = name.substring(name.indexOf(':') + 1); 189 } 190 IdentityConstraint result = (IdentityConstraint)identityConstraints.get(name); 191 return result; 192 } 193 194 boolean equals(ElementDeclaration decl) { 195 if ( this == decl ) return true; 196 if ( decl == null ) return false; 197 if ( this.getName().equals(decl.getName()) == false ) return false; 198 if ( this.getNamespace() == null && decl.getNamespace() != null ) return false; 199 if ( this.getNamespace() != null && !(this.getNamespace().equals(decl.getNamespace())) ) 200 return false; 201 if ( this.abs != decl.abs ) return false; 202 if ( this.nillable != decl.nillable ) return false; 203 if ( this.fin != decl.fin ) return false; 204 if ( this.block != decl.block ) return false; 205 if ( this.defaultValue == null && decl.defaultValue != null ) return false; 206 if ( this.defaultValue != null && !(this.defaultValue.equals(decl.defaultValue)) ) return false; 207 if ( this.fixedValue == null && decl.fixedValue != null ) return false; 208 if ( this.fixedValue != null && !(this.fixedValue.equals(decl.fixedValue)) ) return false; 209 if ( this.getType() == decl.getType() ) return true; 210 else return false; 211 } 212 213 boolean overlapUPAC(Object obj) { 214 if ( obj == null ) return false; 215 if ( obj instanceof ElementDeclaration ) 216 return overlapUPAC((ElementDeclaration)obj); 217 else if ( obj instanceof Wildcard ) 218 return overlapUPAC((Wildcard)obj); 219 else 220 return false; 221 } 222 223 boolean overlapUPAC(ElementDeclaration decl) { 224 if ( this == decl ) return true; 225 if ( decl == null ) return false; 226 227 if ( this.getName().equals(decl.getName()) && 228 ( ( this.getNamespace() == null && decl.getNamespace() == null ) || 229 ( this.getNamespace() != null && this.getNamespace().equals(decl.getNamespace())) ) ) 230 return true; 231 232 if ( this.substitutionGroup == decl || this == decl.substitutionGroup ) return true; 234 235 return false; 236 } 237 238 boolean overlapUPAC(Wildcard wild) { 239 if ( wild == null ) return false; 240 241 if ( wild.isAllowed(this.getNamespace()) ) return true; 242 243 if ( this.getSubstitutionElementList() != null ) { 250 java.util.Iterator it = this.getSubstitutionElementList().iterator(); 251 while ( it.hasNext() ) { 252 ElementDeclaration subElement = (ElementDeclaration)it.next(); 253 if ( wild.isAllowed(subElement.getNamespace()) ) return true; 254 } 255 } 256 257 return false; 258 } 259 260 } 261 262 | Popular Tags |