1 package org.columba.core.context.base; 2 3 import java.util.Collection ; 4 import java.util.Hashtable ; 5 import java.util.List ; 6 import java.util.Vector ; 7 8 import org.columba.core.context.base.api.IAttributeType; 9 import org.columba.core.context.base.api.IName; 10 import org.columba.core.context.base.api.IStructureType; 11 import org.columba.core.context.base.api.MULTIPLICITY; 12 13 public class StructureType implements IStructureType { 14 15 private String name; 16 17 private String namespace; 18 19 private MULTIPLICITY cardinality; 20 21 private final List <IStructureType> typeList = new Vector <IStructureType>(); 22 23 private final List <IAttributeType> attributeList = new Vector <IAttributeType>(); 24 25 private final Hashtable <IName, IStructureType> typeMap = new Hashtable <IName, IStructureType>(); 26 27 private final Hashtable <IName, IAttributeType> attributeMap = new Hashtable <IName, IAttributeType>(); 28 29 public StructureType(final String theName, final String theNamespace) { 30 this.name = theName; 31 this.namespace = theNamespace; 32 33 this.cardinality = MULTIPLICITY.ONE_TO_ONE; 34 } 35 36 37 public String getName() { 38 return name; 39 } 40 41 public String getNamespace() { 42 return namespace; 43 } 44 45 public MULTIPLICITY getCardinality() { 46 return cardinality; 47 } 48 49 public IStructureType removeChild(final String theName, final String theNamespace) { 50 final IStructureType type = typeMap.remove(new Name(theName, theNamespace)); 51 typeList.remove(type); 52 return type; 53 } 54 55 public Collection <IStructureType> getChildren() { 56 return typeMap.values(); 57 } 58 59 public IAttributeType addAttribute(final String theName, final String theNamespace) { 60 final IAttributeType attr = new AttributeType(theName, theNamespace); 61 attributeMap.put(new Name(theName, theNamespace), attr); 62 attributeList.add(attr); 63 return attr; 64 } 65 66 public IAttributeType getAttribute(final String theName, final String theNamespace) { 67 return attributeMap.get(new Name(theName, theNamespace)); 68 } 69 70 public Collection <IAttributeType> getAttributes() { 71 return attributeList; 72 } 73 74 public IStructureType addChild(final String theName, final String theNamespace) { 75 final IStructureType type = new StructureType(theName, theNamespace); 76 typeMap.put(new Name(theName, theNamespace), type); 77 typeList.add(type); 78 79 return type; 80 } 81 82 public IStructureType addChild(final IStructureType type) { 83 typeMap.put(new Name(type.getName(), type.getNamespace()), type); 84 typeList.add(type); 85 return type; 86 } 87 88 public IStructureType getChild(final String theName, final String theNamespace) { 89 return typeMap.get(new Name(theName, theNamespace)); 90 } 91 92 public void setCardinality(final MULTIPLICITY theCardinality) { 93 this.cardinality = theCardinality; 94 } 95 96 @Override 97 public String toString() { 98 final StringBuilder buf = new StringBuilder (); 99 buf.append("StructureType["); buf.append("name="+getName()); buf.append("namespace"+getNamespace()); buf.append(']'); 103 return buf.toString(); 104 } 105 106 107 108 } 109 | Popular Tags |