1 19 package org.enhydra.zeus.binding; 20 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.BitSet ; 25 import java.util.Vector ; 26 27 43 public class ContainerProperty extends BaseBinding 44 implements Property, Container { 45 46 47 private static BitSet DEFAULT_MODIFIER = new BitSet (); 48 49 static { 50 DEFAULT_MODIFIER.set(Property.ACCESS_PRIVATE); 51 } 52 53 60 61 62 protected BitSet modifier; 63 64 68 protected boolean isCollection; 69 70 71 protected Object defaultValue; 72 73 77 protected List properties; 78 79 97 public ContainerProperty(String xmlName, 98 String xmlNamespaceURI, 99 String xmlType, 100 String xmlTypeNamespaceURI, 101 BitSet modifier) { 102 super(); 103 104 if (xmlName == null) { 106 throw new IllegalArgumentException ("An AtomicProperty cannot " + 107 "have a null XML name."); 108 } 109 if (xmlNamespaceURI == null) { 110 throw new IllegalArgumentException ("An AtomicProperty cannot " + 111 "have a null XML namespace URI. To specify no namespace URI, " + 112 "use the empty String (\"\")"); 113 } 114 if (xmlType == null) { 115 throw new IllegalArgumentException ("An AtomicProperty cannot " + 116 "have a null XML type."); 117 } 118 if (xmlTypeNamespaceURI == null) { 119 throw new IllegalArgumentException ("An AtomicProperty cannot " + 120 "have a null XML type namespace URI. To specify no namespace " + 121 "URI, use the empty String (\"\")"); 122 } 123 if (modifier == null) { 124 throw new IllegalArgumentException ("A Binding cannot have a " + 125 "null set of modifiers."); 126 } 127 128 this.xmlName = xmlName; 129 this.xmlNamespaceURI = xmlNamespaceURI; 130 this.xmlType = xmlType; 131 this.xmlTypeNamespaceURI = xmlTypeNamespaceURI; 132 this.defaultValue = null; 133 this.modifier = modifier; 134 this.isCollection = false; 135 } 136 137 154 public ContainerProperty(String xmlName, 155 String xmlNamespaceURI, 156 String xmlType, 157 String xmlTypeNamespaceURI) { 158 this(xmlName, xmlNamespaceURI, xmlType, xmlTypeNamespaceURI, 159 DEFAULT_MODIFIER); 160 } 161 162 177 public ContainerProperty(String xmlName, 178 String xmlType) { 179 this(xmlName, "", xmlType, "", DEFAULT_MODIFIER); 180 } 181 182 205 public void setModifier(BitSet modifier) { 206 if (modifier == null) { 207 throw new IllegalArgumentException ("A Property cannot have a " + 208 "null set of modifiers."); 209 } 210 this.modifier = modifier; 211 } 212 213 233 public BitSet getModifier() { 234 return modifier; 235 } 236 237 253 public String getModifierString() { 254 StringBuffer modifierString = new StringBuffer (); 255 if (modifier.get(ACCESS_PRIVATE)) { 256 modifierString.append("private"); 257 } else if (modifier.get(ACCESS_PROTECTED)) { 258 modifierString.append("protected"); 259 } else if (modifier.get(ACCESS_PUBLIC)) { 260 modifierString.append("public"); 261 } else { 262 throw new UnsupportedOperationException 263 ("Modifier must set access modifiers."); 264 } 265 266 if (modifier.get(STORAGE_STATIC)) { 267 modifierString.append(" static"); 268 } 269 if (modifier.get(MUTABILITY_VOLATILE)) { 270 modifierString.append(" volatile"); 271 } else if (modifier.get(MUTABILITY_FINAL)) { 272 modifierString.append(" final"); 273 } 274 275 return modifierString.toString(); 276 } 277 278 289 public void setIsCollection(boolean isCollection) { 290 this.isCollection = isCollection; 291 } 292 293 304 public boolean isCollection() { 305 return isCollection; 306 } 307 308 316 public boolean hasDefaultValue() { 317 return (defaultValue != null); 318 } 319 320 352 public void setDefaultValue(Object defaultValue) { 353 this.defaultValue = defaultValue; 354 } 355 356 366 public Object getDefaultValue() { 367 return defaultValue; 368 } 369 370 380 public boolean hasEnumeration() { 381 return false; 382 } 383 384 393 public void setEnumeration(Vector enumeration) { 394 return; 395 } 396 397 407 public Vector getEnumeration() { 408 return null; 409 } 410 411 426 public void addProperty(Property property) { 427 if (property == null) { 428 throw new IllegalArgumentException ("A Container cannot have " + 429 "null properties as children."); 430 } 431 432 if (properties == null) { 433 properties = new LinkedList (); 434 } 435 436 properties.add(property); 437 } 438 439 455 public boolean removeProperty(String javaName) { 456 if (properties == null) { 457 return false; 458 } 459 460 for (Iterator i = properties.iterator(); i.hasNext(); ) { 461 Property property = (Property)i.next(); 462 if (property.getJavaName().equals(javaName)) { 463 i.remove(); 464 return true; 465 } 466 } 467 468 return false; 469 } 470 471 481 public void setProperties(List properties) { 482 if (properties == null) { 483 throw new IllegalArgumentException ("A Container cannot have a " + 484 "null property set."); 485 } 486 487 this.properties = properties; 488 } 489 490 501 public List getProperties() { 502 if (properties == null) { 503 return new LinkedList (); 504 } 505 506 return properties; 507 } 508 509 514 public void clearProperties() { 515 if (properties != null) { 516 properties.clear(); 517 } 518 } 519 } 520 | Popular Tags |