1 22 package org.jboss.xb.binding.metadata; 23 24 import java.util.HashMap ; 25 import java.util.Collections ; 26 import java.util.Map ; 27 import javax.xml.namespace.QName ; 28 29 33 public class XsdElement 34 { 35 public static final QName QNAME_NAME = new QName ("name"); 36 37 private final QName qName; 38 private Map attributes = Collections.EMPTY_MAP; 39 private Map children = Collections.EMPTY_MAP; 40 private String data; 41 42 public XsdElement(QName qName) 43 { 44 this.qName = qName; 45 } 46 47 public String getAttribute(QName qName) 48 { 49 return (String )attributes.get(qName); 50 } 51 52 public void addAttribute(QName qName, String value) 53 { 54 switch(attributes.size()) 55 { 56 case 0: 57 attributes = Collections.singletonMap(qName, value); 58 break; 59 case 1: 60 attributes = new HashMap (attributes); 61 default: 62 attributes.put(qName, value); 63 } 64 } 65 66 public XsdElement getChild(QName qName) 67 { 68 return (XsdElement)children.get(qName); 69 } 70 71 public void addChild(XsdElement child) 72 { 73 switch(children.size()) 74 { 75 case 0: 76 children = Collections.singletonMap(child.qName, child); 77 break; 78 case 1: 79 children = new HashMap (children); 80 default: 81 children.put(child.qName, child); 82 } 83 } 84 85 public String getData() 86 { 87 return data; 88 } 89 90 public void setData(String data) 91 { 92 this.data = data; 93 } 94 95 public QName getQName() 96 { 97 return qName; 98 } 99 100 public String getNameAttribute() 101 { 102 return getAttribute(QNAME_NAME); 103 } 104 105 public void setNameAttribute(String name) 106 { 107 addAttribute(QNAME_NAME, name); 108 } 109 110 public boolean equals(Object o) 111 { 112 if(this == o) 113 { 114 return true; 115 } 116 if(!(o instanceof XsdElement)) 117 { 118 return false; 119 } 120 121 final XsdElement xsdElement = (XsdElement)o; 122 123 if(!qName.equals(xsdElement.qName)) 124 { 125 return false; 126 } 127 128 return true; 129 } 130 131 public int hashCode() 132 { 133 return qName.hashCode(); 134 } 135 } 136 | Popular Tags |