1 57 58 package org.apache.wsif.schema; 59 60 import java.io.Serializable ; 61 import java.util.List ; 62 import java.util.Map ; 63 64 import javax.xml.namespace.QName ; 65 66 import org.w3c.dom.Element ; 67 import org.w3c.dom.NamedNodeMap ; 68 import org.w3c.dom.Node ; 69 70 import com.ibm.wsdl.util.xml.DOMUtils; 71 72 77 public abstract class SchemaType implements Serializable { 78 79 83 public boolean isComplex() { 84 return false; 85 } 86 87 91 public boolean isSimple() { 92 return false; 93 } 94 95 99 public boolean isElement() { 100 return false; 101 } 102 103 107 public boolean isArray() { 108 return false; 109 } 110 111 115 public QName getArrayType() { 116 return null; 117 } 118 119 123 public int getArrayDimension() { 124 return 0; 125 } 126 127 131 public QName getTypeName() { 132 return null; 133 } 134 135 139 public List getChildren() { 140 return null; 141 } 142 143 149 protected static QName getAttributeQName(Element element, String attr) { 150 151 if (element == null || attr == null) 152 throw new IllegalArgumentException ( 153 "Argument to 'getAttrQName' " + "cannot be null."); 154 155 String name = DOMUtils.getAttribute(element, attr); 156 157 if (name == null) 158 return null; 159 160 int index = name.lastIndexOf(":"); 161 String prefix = null; 162 163 if (index != -1) { 164 prefix = name.substring(0, index); 165 name = name.substring(index + 1); 166 } 167 String uri = DOMUtils.getNamespaceURIFromPrefix(element, prefix); 168 169 return new QName (uri, name); 170 } 171 172 179 protected static QName getAttributeQName(Element element, String attr, String tns) { 180 181 if (element == null || attr == null) 182 throw new IllegalArgumentException ( 183 "Argument to 'getAttrQName' " + "cannot be null."); 184 185 String name = DOMUtils.getAttribute(element, attr); 186 187 if (name == null) 188 return null; 189 190 int index = name.lastIndexOf(":"); 191 String prefix = null; 192 193 if (index != -1) { 194 prefix = name.substring(0, index); 195 name = name.substring(index + 1); 196 } 197 198 String uri = null; 199 if (prefix != null) { 200 uri = DOMUtils.getNamespaceURIFromPrefix(element, prefix); 201 } else { 202 uri = tns; 203 } 204 205 return new QName (uri, name); 206 } 207 208 214 protected static QName getAttributeQName(Element element, QName attr) { 215 216 if (element == null || attr == null) 217 throw new IllegalArgumentException ( 218 "Argument to 'getAttrQName' " + "cannot be null."); 219 220 String ns = attr.getNamespaceURI(); 221 String lp = attr.getLocalPart(); 222 String name = DOMUtils.getAttributeNS(element, ns, lp); 223 224 if (name == null) 225 return null; 226 227 int index = name.lastIndexOf(":"); 228 String prefix = null; 229 230 if (index != -1) { 231 prefix = name.substring(0, index); 232 name = name.substring(index + 1); 233 } 234 String uri = DOMUtils.getNamespaceURIFromPrefix(element, prefix); 235 236 return new QName (uri, name); 237 238 } 239 240 247 protected static void getAllAttributes(Element el, String tns, Map attributes) { 248 NamedNodeMap atts = el.getAttributes(); 249 if (atts != null) { 250 for (int a = 0; a < atts.getLength(); a++) { 251 Node attribute = atts.item(a); 252 String ln = attribute.getLocalName(); 253 String ns = attribute.getNamespaceURI(); 254 255 String name = ""; 256 if (ns != null) { 257 name = DOMUtils.getAttributeNS(el, ns, ln); 258 } else { 259 name = DOMUtils.getAttribute(el, ln); 260 } 261 262 int index = name.lastIndexOf(":"); 263 String prefix = null; 264 265 if (index != -1) { 266 prefix = name.substring(0, index); 267 name = name.substring(index + 1); 268 } 269 270 String uri = null; 271 if (prefix != null || tns == null) { 272 uri = DOMUtils.getNamespaceURIFromPrefix(el, prefix); 273 } else { 274 uri = tns; 275 } 276 attributes.put(new QName (ns, ln) ,new QName (uri, name)); 277 } 278 } 279 } 280 } 281 | Popular Tags |