1 19 20 45 46 package org.netbeans.modules.xml.wsdl.ui.view.wizard; 47 48 public class TemplateGroup { 49 public static final String NAMESPACE = "Namespace"; public static final String PREFIX = "Prefix"; public static final String TEMPLATE = "Template"; 53 private java.lang.String _Namespace; 54 private java.lang.String _Prefix; 55 private java.util.List _Template = new java.util.ArrayList (); private java.lang.String schemaLocation; 57 58 61 public TemplateGroup() { 62 } 63 64 67 public TemplateGroup(org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType[] template) { 68 if (template!= null) { 69 ((java.util.ArrayList ) _Template).ensureCapacity(template.length); 70 for (int i = 0; i < template.length; ++i) { 71 _Template.add(template[i]); 72 } 73 } 74 } 75 76 79 public TemplateGroup(org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateGroup source) { 80 this(source, false); 81 } 82 83 87 public TemplateGroup(org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateGroup source, boolean justData) { 88 _Namespace = source._Namespace; 89 _Prefix = source._Prefix; 90 for (java.util.Iterator it = source._Template.iterator(); 91 it.hasNext(); ) { 92 org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType srcElement = (org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType)it.next(); 93 _Template.add((srcElement == null) ? null : newTemplateType(srcElement, justData)); 94 } 95 schemaLocation = source.schemaLocation; 96 } 97 98 public void setNamespace(java.lang.String value) { 100 _Namespace = value; 101 } 102 103 public java.lang.String getNamespace() { 104 return _Namespace; 105 } 106 107 public void setPrefix(java.lang.String value) { 109 _Prefix = value; 110 } 111 112 public java.lang.String getPrefix() { 113 return _Prefix; 114 } 115 116 public void setTemplate(org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType[] value) { 118 if (value == null) 119 value = new TemplateType[0]; 120 _Template.clear(); 121 ((java.util.ArrayList ) _Template).ensureCapacity(value.length); 122 for (int i = 0; i < value.length; ++i) { 123 _Template.add(value[i]); 124 } 125 } 126 127 public void setTemplate(int index, org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType value) { 128 _Template.set(index, value); 129 } 130 131 public org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType[] getTemplate() { 132 TemplateType[] arr = new TemplateType[_Template.size()]; 133 return (TemplateType[]) _Template.toArray(arr); 134 } 135 136 public java.util.List fetchTemplateList() { 137 return _Template; 138 } 139 140 public org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType getTemplate(int index) { 141 return (TemplateType)_Template.get(index); 142 } 143 144 public int sizeTemplate() { 146 return _Template.size(); 147 } 148 149 public int addTemplate(org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType value) { 150 _Template.add(value); 151 int positionOfNewItem = _Template.size()-1; 152 return positionOfNewItem; 153 } 154 155 158 public int removeTemplate(org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType value) { 159 int pos = _Template.indexOf(value); 160 if (pos >= 0) { 161 _Template.remove(pos); 162 } 163 return pos; 164 } 165 166 public void _setSchemaLocation(String location) { 167 schemaLocation = location; 168 } 169 170 public String _getSchemaLocation() { 171 return schemaLocation; 172 } 173 174 178 public org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType newTemplateType() { 179 return new org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType(); 180 } 181 182 186 public org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType newTemplateType(TemplateType source, boolean justData) { 187 return new org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType(source, justData); 188 } 189 190 public void write(org.openide.filesystems.FileObject fo) throws java.io.IOException { 191 org.openide.filesystems.FileLock lock = fo.lock(); 192 try { 193 java.io.OutputStream out = fo.getOutputStream(lock); 194 write(out); 195 out.close(); 196 } finally { 197 lock.releaseLock(); 198 } 199 } 200 201 public void write(org.openide.filesystems.FileObject dir, String filename) throws java.io.IOException { 202 org.openide.filesystems.FileObject file = dir.getFileObject(filename); 203 if (file == null) { 204 file = dir.createData(filename); 205 } 206 write(file); 207 } 208 209 public void write(java.io.File f) throws java.io.IOException { 210 java.io.OutputStream out = new java.io.FileOutputStream (f); 211 try { 212 write(out); 213 } finally { 214 out.close(); 215 } 216 } 217 218 public void write(java.io.OutputStream out) throws java.io.IOException { 219 write(out, null); 220 } 221 222 public void write(java.io.OutputStream out, String encoding) throws java.io.IOException { 223 java.io.Writer w; 224 if (encoding == null) { 225 encoding = "UTF-8"; } 227 w = new java.io.BufferedWriter (new java.io.OutputStreamWriter (out, encoding)); 228 write(w, encoding); 229 w.flush(); 230 } 231 232 236 public void write(java.io.Writer out, String encoding) throws java.io.IOException { 237 out.write("<?xml version='1.0'"); if (encoding != null) 239 out.write(" encoding='"+encoding+"'"); out.write(" ?>\n"); writeNode(out, "templateGroup", ""); } 243 244 public void writeNode(java.io.Writer out) throws java.io.IOException { 245 String myName; 246 myName = "templateGroup"; 247 writeNode(out, myName, ""); } 249 250 public void writeNode(java.io.Writer out, String nodeName, String indent) throws java.io.IOException { 251 writeNode(out, nodeName, null, indent, new java.util.HashMap ()); 252 } 253 254 257 public void writeNode(java.io.Writer out, String nodeName, String namespace, String indent, java.util.Map namespaceMap) throws java.io.IOException { 258 out.write(indent); 259 out.write("<"); 260 if (namespace != null) { 261 out.write((String )namespaceMap.get(namespace)); 262 out.write(":"); 263 } 264 out.write(nodeName); 265 out.write(" xmlns='"); out.write("http://xml.netbeans.org/schema/templates"); out.write("'"); if (schemaLocation != null) { 269 namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsi"); 270 out.write(" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='"); 271 out.write(schemaLocation); 272 out.write("'"); } 274 writeNodeAttributes(out, nodeName, namespace, indent, namespaceMap); 275 out.write(">\n"); 276 writeNodeChildren(out, nodeName, namespace, indent, namespaceMap); 277 out.write(indent); 278 out.write("</"); 279 if (namespace != null) { 280 out.write((String )namespaceMap.get(namespace)); 281 out.write(":"); 282 } 283 out.write(nodeName); 284 out.write(">\n"); 285 } 286 287 protected void writeNodeAttributes(java.io.Writer out, String nodeName, String namespace, String indent, java.util.Map namespaceMap) throws java.io.IOException { 288 if (_Namespace != null) { 290 out.write(" namespace='"); 291 org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateGroup.writeXML(out, _Namespace, true); 292 out.write("'"); } 294 if (_Prefix != null) { 296 out.write(" prefix='"); 297 org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateGroup.writeXML(out, _Prefix, true); 298 out.write("'"); } 300 } 301 302 protected void writeNodeChildren(java.io.Writer out, String nodeName, String namespace, String indent, java.util.Map namespaceMap) throws java.io.IOException { 303 String nextIndent = indent + " "; 304 for (java.util.Iterator it = _Template.iterator(); it.hasNext(); ) { 305 org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType element = (org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType)it.next(); 306 if (element != null) { 307 element.writeNode(out, "template", null, nextIndent, namespaceMap); 308 } 309 } 310 } 311 312 public static TemplateGroup read(org.openide.filesystems.FileObject fo) throws javax.xml.parsers.ParserConfigurationException , org.xml.sax.SAXException , java.io.IOException { 313 java.io.InputStream in = fo.getInputStream(); 314 try { 315 return read(in); 316 } finally { 317 in.close(); 318 } 319 } 320 321 public static TemplateGroup read(java.io.File f) throws javax.xml.parsers.ParserConfigurationException , org.xml.sax.SAXException , java.io.IOException { 322 java.io.InputStream in = new java.io.FileInputStream (f); 323 try { 324 return read(in); 325 } finally { 326 in.close(); 327 } 328 } 329 330 public static TemplateGroup read(java.io.InputStream in) throws javax.xml.parsers.ParserConfigurationException , org.xml.sax.SAXException , java.io.IOException { 331 return read(new org.xml.sax.InputSource (in), false, null, null); 332 } 333 334 340 public static TemplateGroup readNoEntityResolver(java.io.InputStream in) throws javax.xml.parsers.ParserConfigurationException , org.xml.sax.SAXException , java.io.IOException { 341 return read(new org.xml.sax.InputSource (in), false, 342 new org.xml.sax.EntityResolver () { 343 public org.xml.sax.InputSource resolveEntity(String publicId, String systemId) { 344 java.io.ByteArrayInputStream bin = new java.io.ByteArrayInputStream (new byte[0]); 345 return new org.xml.sax.InputSource (bin); 346 } 347 } 348 , null); 349 } 350 351 public static TemplateGroup read(org.xml.sax.InputSource in, boolean validate, org.xml.sax.EntityResolver er, org.xml.sax.ErrorHandler eh) throws javax.xml.parsers.ParserConfigurationException , org.xml.sax.SAXException , java.io.IOException { 352 javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); 353 dbf.setValidating(validate); 354 dbf.setNamespaceAware(true); 355 javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); 356 if (er != null) db.setEntityResolver(er); 357 if (eh != null) db.setErrorHandler(eh); 358 org.w3c.dom.Document doc = db.parse(in); 359 return read(doc); 360 } 361 362 public static TemplateGroup read(org.w3c.dom.Document document) { 363 TemplateGroup aTemplateGroup = new TemplateGroup(); 364 aTemplateGroup.readFromDocument(document); 365 return aTemplateGroup; 366 } 367 368 protected void readFromDocument(org.w3c.dom.Document document) { 369 readNode(document.getDocumentElement()); 370 } 371 372 public void readNode(org.w3c.dom.Node node) { 373 readNode(node, new java.util.HashMap ()); 374 } 375 376 public void readNode(org.w3c.dom.Node node, java.util.Map namespacePrefixes) { 377 if (node.hasAttributes()) { 378 org.w3c.dom.NamedNodeMap attrs = node.getAttributes(); 379 org.w3c.dom.Attr attr; 380 java.lang.String attrValue; 381 boolean firstNamespaceDef = true; 382 for (int attrNum = 0; attrNum < attrs.getLength(); ++attrNum) { 383 attr = (org.w3c.dom.Attr ) attrs.item(attrNum); 384 String attrName = attr.getName(); 385 if (attrName.startsWith("xmlns:")) { 386 if (firstNamespaceDef) { 387 firstNamespaceDef = false; 388 namespacePrefixes = new java.util.HashMap (namespacePrefixes); 390 } 391 String attrNSPrefix = attrName.substring(6, attrName.length()); 392 namespacePrefixes.put(attrNSPrefix, attr.getValue()); 393 } 394 } 395 String xsiPrefix = "xsi"; 396 for (java.util.Iterator it = namespacePrefixes.keySet().iterator(); 397 it.hasNext(); ) { 398 String prefix = (String ) it.next(); 399 String ns = (String ) namespacePrefixes.get(prefix); 400 if ("http://www.w3.org/2001/XMLSchema-instance".equals(ns)) { 401 xsiPrefix = prefix; 402 break; 403 } 404 } 405 attr = (org.w3c.dom.Attr ) attrs.getNamedItem(""+xsiPrefix+":schemaLocation"); 406 if (attr != null) { 407 attrValue = attr.getValue(); 408 schemaLocation = attrValue; 409 } 410 readNodeAttributes(node, namespacePrefixes, attrs); 411 } 412 readNodeChildren(node, namespacePrefixes); 413 } 414 415 protected void readNodeAttributes(org.w3c.dom.Node node, java.util.Map namespacePrefixes, org.w3c.dom.NamedNodeMap attrs) { 416 org.w3c.dom.Attr attr; 417 java.lang.String attrValue; 418 attr = (org.w3c.dom.Attr ) attrs.getNamedItem("namespace"); 419 if (attr != null) { 420 attrValue = attr.getValue(); 421 _Namespace = attrValue; 422 } 423 attr = (org.w3c.dom.Attr ) attrs.getNamedItem("prefix"); 424 if (attr != null) { 425 attrValue = attr.getValue(); 426 _Prefix = attrValue; 427 } 428 } 429 430 protected void readNodeChildren(org.w3c.dom.Node node, java.util.Map namespacePrefixes) { 431 org.w3c.dom.NodeList children = node.getChildNodes(); 432 for (int i = 0, size = children.getLength(); i < size; ++i) { 433 org.w3c.dom.Node childNode = children.item(i); 434 String childNodeName = (childNode.getLocalName() == null ? childNode.getNodeName().intern() : childNode.getLocalName().intern()); 435 String childNodeValue = ""; 436 if (childNode.getFirstChild() != null) { 437 childNodeValue = childNode.getFirstChild().getNodeValue(); 438 } 439 if (childNodeName == "template") { 440 TemplateType aTemplate = newTemplateType(); 441 aTemplate.readNode(childNode, namespacePrefixes); 442 _Template.add(aTemplate); 443 } 444 else { 445 } 447 } 448 } 449 450 454 public static void writeXML(java.io.Writer out, String msg) throws java.io.IOException { 455 writeXML(out, msg, true); 456 } 457 458 public static void writeXML(java.io.Writer out, String msg, boolean attribute) throws java.io.IOException { 459 if (msg == null) 460 return; 461 int msgLength = msg.length(); 462 for (int i = 0; i < msgLength; ++i) { 463 char c = msg.charAt(i); 464 writeXML(out, c, attribute); 465 } 466 } 467 468 public static void writeXML(java.io.Writer out, char msg, boolean attribute) throws java.io.IOException { 469 if (msg == '&') 470 out.write("&"); 471 else if (msg == '<') 472 out.write("<"); 473 else if (msg == '>') 474 out.write(">"); 475 else if (attribute) { 476 if (msg == '"') 477 out.write("""); 478 else if (msg == '\'') 479 out.write("'"); 480 else if (msg == '\n') 481 out.write("
"); 482 else if (msg == '\t') 483 out.write("	"); 484 else 485 out.write(msg); 486 } 487 else 488 out.write(msg); 489 } 490 491 public void changePropertyByName(String name, Object value) { 492 if (name == null) return; 493 name = name.intern(); 494 if (name == "namespace") 495 setNamespace((java.lang.String )value); 496 else if (name == "prefix") 497 setPrefix((java.lang.String )value); 498 else if (name == "template") 499 addTemplate((TemplateType)value); 500 else if (name == "template[]") 501 setTemplate((TemplateType[]) value); 502 else 503 throw new IllegalArgumentException (name+" is not a valid property name for TemplateGroup"); 504 } 505 506 public Object fetchPropertyByName(String name) { 507 if (name == "namespace") 508 return getNamespace(); 509 if (name == "prefix") 510 return getPrefix(); 511 if (name == "template[]") 512 return getTemplate(); 513 throw new IllegalArgumentException (name+" is not a valid property name for TemplateGroup"); 514 } 515 516 public String nameSelf() { 517 return "/TemplateGroup"; 518 } 519 520 public String nameChild(Object childObj) { 521 return nameChild(childObj, false, false); 522 } 523 524 529 public String nameChild(Object childObj, boolean returnConstName, boolean returnSchemaName) { 530 return nameChild(childObj, returnConstName, returnSchemaName, false); 531 } 532 533 538 public String nameChild(Object childObj, boolean returnConstName, boolean returnSchemaName, boolean returnXPathName) { 539 if (childObj instanceof java.lang.String ) { 540 java.lang.String child = (java.lang.String ) childObj; 541 if (child == _Namespace) { 542 if (returnConstName) { 543 return NAMESPACE; 544 } else if (returnSchemaName) { 545 return "namespace"; 546 } else if (returnXPathName) { 547 return "@namespace"; 548 } else { 549 return "Namespace"; 550 } 551 } 552 if (child == _Prefix) { 553 if (returnConstName) { 554 return PREFIX; 555 } else if (returnSchemaName) { 556 return "prefix"; 557 } else if (returnXPathName) { 558 return "@prefix"; 559 } else { 560 return "Prefix"; 561 } 562 } 563 } 564 if (childObj instanceof TemplateType) { 565 TemplateType child = (TemplateType) childObj; 566 int index = 0; 567 for (java.util.Iterator it = _Template.iterator(); 568 it.hasNext(); ) { 569 org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType element = (org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType)it.next(); 570 if (child == element) { 571 if (returnConstName) { 572 return TEMPLATE; 573 } else if (returnSchemaName) { 574 return "template"; 575 } else if (returnXPathName) { 576 return "template[position()="+index+"]"; 577 } else { 578 return "Template."+Integer.toHexString(index); 579 } 580 } 581 ++index; 582 } 583 } 584 return null; 585 } 586 587 590 public java.lang.Object [] childBeans(boolean recursive) { 591 java.util.List children = new java.util.LinkedList (); 592 childBeans(recursive, children); 593 java.lang.Object [] result = new java.lang.Object [children.size()]; 594 return (java.lang.Object []) children.toArray(result); 595 } 596 597 600 public void childBeans(boolean recursive, java.util.List beans) { 601 for (java.util.Iterator it = _Template.iterator(); it.hasNext(); ) { 602 org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType element = (org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType)it.next(); 603 if (element != null) { 604 if (recursive) { 605 element.childBeans(true, beans); 606 } 607 beans.add(element); 608 } 609 } 610 } 611 612 public boolean equals(Object o) { 613 return o instanceof org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateGroup && equals((org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateGroup) o); 614 } 615 616 public boolean equals(org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateGroup inst) { 617 if (inst == this) { 618 return true; 619 } 620 if (inst == null) { 621 return false; 622 } 623 if (!(_Namespace == null ? inst._Namespace == null : _Namespace.equals(inst._Namespace))) { 624 return false; 625 } 626 if (!(_Prefix == null ? inst._Prefix == null : _Prefix.equals(inst._Prefix))) { 627 return false; 628 } 629 if (sizeTemplate() != inst.sizeTemplate()) 630 return false; 631 for (java.util.Iterator it = _Template.iterator(), it2 = inst._Template.iterator(); 633 it.hasNext() && it2.hasNext(); ) { 634 org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType element = (org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType)it.next(); 635 org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType element2 = (org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType)it2.next(); 636 if (!(element == null ? element2 == null : element.equals(element2))) { 637 return false; 638 } 639 } 640 return true; 641 } 642 643 public int hashCode() { 644 int result = 17; 645 result = 37*result + (_Namespace == null ? 0 : _Namespace.hashCode()); 646 result = 37*result + (_Prefix == null ? 0 : _Prefix.hashCode()); 647 result = 37*result + (_Template == null ? 0 : _Template.hashCode()); 648 return result; 649 } 650 651 } 652 653 654 699 | Popular Tags |