1 19 package org.netbeans.modules.xml.xsd; 20 21 import org.w3c.dom.Element ; 22 import org.xml.sax.Attributes ; 23 import org.xml.sax.helpers.AttributesImpl ; 24 import java.util.List ; 25 import java.util.ArrayList ; 26 27 31 class SchemaElement extends AbstractResultNode implements Element { 32 33 34 protected final String namespaceURI; 35 36 protected final String qname; 37 38 protected final Attributes attributes; 39 40 protected final List subelements; 41 42 private String prefix; 43 44 45 private String schemaPrefix; 46 47 48 protected SchemaElement() { 49 this.namespaceURI = null; 50 this.qname = null; 51 this.attributes = null; 52 this.subelements = null; 53 this.schemaPrefix = null; 54 } 55 56 57 protected SchemaElement(String namespaceURI, String qname, Attributes attributes, String schemaPrefix) { 58 this.namespaceURI = namespaceURI; 59 this.qname = qname; 60 this.attributes = (attributes == null ? null : new AttributesImpl (attributes)); 61 this.subelements = new ArrayList (); 62 this.schemaPrefix = schemaPrefix; 63 } 64 65 66 public static final SchemaElement createSchemaElement(String namespaceURI, String qname, Attributes attributes, String schemaPrefix) { 67 String simpleType = null; 68 String complexType = null; 69 70 if (schemaPrefix == null) { 71 simpleType = Type.XS_SIMPLE_TYPE; 72 complexType = Type.XS_COMPLEX_TYPE; 73 } else { 74 simpleType = schemaPrefix + ':' + Type.XS_SIMPLE_TYPE; 75 complexType = schemaPrefix + ':' + Type.XS_COMPLEX_TYPE; 76 } 77 78 if (qname.equalsIgnoreCase(simpleType) || qname.equalsIgnoreCase(complexType)) { 79 return new Type(namespaceURI, qname, attributes, schemaPrefix); 80 } else { 81 return new SchemaElement(namespaceURI, qname, attributes, schemaPrefix); 82 } 83 } 84 85 public final void addSubelement(SchemaElement e) { 86 subelements.add(e); 87 } 88 89 public final java.util.Iterator getSubelements() { 90 return subelements.iterator(); 91 } 92 93 public final boolean isComposite() { 94 String sequenceToken = getSchemaPrefix() == null ? "sequence" : getSchemaPrefix() + ':' + "sequence"; 95 return (this instanceof Type) || getQname().equalsIgnoreCase(sequenceToken); 96 } 97 98 public String toString() { 99 StringBuffer sb = new StringBuffer (100); 100 sb.append("SchemaElement ").append(qname); 101 102 if (attributes != null) { 103 sb.append("Attrs size: ").append(attributes.getLength()); 104 for (int i = 0; i < attributes.getLength(); i++) { 105 sb.append("\n Attr[").append(i).append("] localname: "). 106 append(attributes.getLocalName(i)). 107 append(" qname: ").append(attributes.getQName(i)). 108 append(" value: ").append(attributes.getValue(i)). 109 append(" URI: ").append(attributes.getURI(i)). 110 append(" type: ").append(attributes.getType(i)); 111 } 112 } 113 114 return sb.toString(); 115 } 116 117 121 public java.lang.String getQname() { 122 return qname; 123 } 124 125 129 public org.xml.sax.Attributes getSAXAttributes() { 130 return attributes; 131 } 132 133 135 public short getNodeType() { 136 return org.w3c.dom.Node.ELEMENT_NODE; 137 } 138 139 public String getNodeName() { 140 String name = getSAXAttributes().getValue("name"); 141 if (prefix != null) { 142 name = prefix + ':' + name; 143 } 144 return name; 145 } 146 147 public String getTagName() { 148 return this.getNodeName(); 149 } 150 151 public void setPrefix(String str) throws org.w3c.dom.DOMException { 152 this.prefix = str; 153 } 154 155 public String getPrefix() { 156 return prefix; 157 } 158 159 163 public java.lang.String getSchemaPrefix() { 164 return schemaPrefix; 165 } 166 167 171 public void setSchemaPrefix(java.lang.String schemaPrefix) { 172 this.schemaPrefix = schemaPrefix; 173 } 174 175 } 176 | Popular Tags |