home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 January / INTERNET98.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / java.spl < prev    next >
Encoding:
INI File  |  2002-09-15  |  29.5 KB  |  1,009 lines

  1. [
  2. '-----------------------------------------------------------
  3. ' Java XML Project Template
  4. '
  5. ' Copyright (C) 2002 Altova GmbH - The XML Spy Company
  6. ' All rights reserved.
  7. '
  8. ' XML Spy generates Java classes based on this template.
  9. ' Refer to the XML Spy Documentation for further details.
  10. '
  11. ' http://www.xmlspy.com
  12. '-----------------------------------------------------------
  13.  
  14. map type "boolean"                to "SchemaBoolean"
  15.  
  16. map type "byte"                    to "SchemaInteger"
  17. map type "unsignedByte"            to "SchemaInteger"
  18. map type "short"                to "SchemaInteger"
  19. map type "unsignedShort"        to "SchemaInteger"
  20. map type "int"                    to "SchemaInteger"
  21. map type "unsignedInt"            to "SchemaInteger"
  22. map type "long"                    to "SchemaInteger"
  23. map type "unsignedLong"            to "SchemaInteger"
  24.  
  25. map type "integer"                to "SchemaInteger"
  26. map type "nonPositiveInteger"    to "SchemaInteger"
  27. map type "negativeInteger"        to "SchemaInteger"
  28. map type "positiveInteger"        to "SchemaInteger"
  29. map type "nonNegativeInteger"    to "SchemaInteger"
  30. map type "decimal"                to "SchemaInteger"
  31.  
  32. map type "float"                to "SchemaDouble"
  33. map type "double"                to "SchemaDouble"
  34.  
  35. map type "duration"                to "SchemaString"
  36. map type "gYear"                to "SchemaInteger"
  37. map type "gDay"                    to "SchemaInteger"
  38. map type "gMonth"                to "SchemaInteger"
  39. map type "gYearMonth"            to "SchemaString"
  40. map type "gMonthDay"            to "SchemaString"
  41. map type "date"                    to "SchemaString"
  42. map type "time"                    to "SchemaString"
  43. map type "dateTime"                to "SchemaString"
  44.  
  45. map type "string"                to "SchemaString"
  46. map type "hexBinary"            to "SchemaString"
  47. map type "base64Binary"            to "SchemaString"
  48. map type "anyURI"                to "SchemaString"
  49. map type "QName"                to "SchemaString"
  50. map type "NOTATION"                to "SchemaString"
  51. map type "normalizedString"        to "SchemaString"
  52. map type "token"                to "SchemaString"
  53. map type "language"                to "SchemaString"
  54. map type "IDREF"                to "SchemaString"
  55. map type "ENTITY"                to "SchemaString"
  56. map type "NMTOKEN"                to "SchemaString"
  57. map type "Name"                    to "SchemaString"
  58. map type "NCName"                to "SchemaString"
  59. map type "ID"                    to "SchemaString"
  60. map type "IDREFS"                to "SchemaString"
  61. map type "ENTITIES"                to "SchemaString"
  62. map type "NMTOKENS"                to "SchemaString"
  63.  
  64. default "ValidFirstCharSet"            is "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  65. default "ValidCharSet"                is "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789"
  66. default "InvalidCharReplacement"    is "_"
  67. default "AnonTypePrefix"            is ""
  68. default "AnonTypeSuffix"            is "Type"
  69. default "ClassNamePrefix"            is ""
  70. default "ClassNameSuffix"            is ""
  71.  
  72. reserve "abstract"
  73. reserve "boolean"
  74. reserve "break"
  75. reserve "byte"
  76. reserve "case"
  77. reserve "catch"
  78. reserve "char"
  79. reserve "class"
  80. reserve "const"
  81. reserve "continue"
  82. reserve "default"
  83. reserve "do"
  84. reserve "double"
  85. reserve "else"
  86. reserve "extends"
  87. reserve "false"
  88. reserve "final"
  89. reserve "finally"
  90. reserve "float"
  91. reserve "for"
  92. reserve "goto"
  93. reserve "if"
  94. reserve "implements"
  95. reserve "import"
  96. reserve "instanceof"
  97. reserve "int"
  98. reserve "interface"
  99. reserve "long"
  100. reserve "native"
  101. reserve "new"
  102. reserve "null"
  103. reserve "package"
  104. reserve "private"
  105. reserve "protected"
  106. reserve "public"
  107. reserve "return"
  108. reserve "short"
  109. reserve "static"
  110. reserve "strictfp"
  111. reserve "super"
  112. reserve "switch"
  113. reserve "synchronized"
  114. reserve "this"
  115. reserve "throw"
  116. reserve "throws"
  117. reserve "transient"
  118. reserve "true"
  119. reserve "try"
  120. reserve "void"
  121. reserve "volatile"
  122. reserve "while"
  123.  
  124. $JavaPackageName = "com.schema"
  125. $JavaPackageDir = "com/schema"
  126.  
  127. create $outputpath & "/" & $JavaPackageDir & "/" & $module & "Test.java"
  128. ]/**
  129.  * [=$module]Test.java
  130.  *
  131.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  132.  * All rights reserved.
  133.  *
  134.  * This file was generated by XML Spy.
  135.  * Refer to the XML Spy Documentation for further details.
  136.  * http://www.xmlspy.com
  137.  */
  138.  
  139.  
  140. package [=$JavaPackageName];
  141.  
  142. import com.altova.xml.types.*;
  143.  
  144. public class [=$module]Test {
  145.     protected static void sample() {
  146.         // TODO:
  147.         //   Place your code here...
  148.     }
  149.  
  150.     public static void main(String args\[\]) {
  151.         try {
  152.             System.out.println("[=$module] Test Application");
  153.             sample();
  154.             System.out.println("OK");
  155.         } catch (Exception e) {
  156.             e.printStackTrace();
  157.         }
  158.     }
  159. }
  160. [
  161. close
  162. create $outputpath & "/" & $JavaPackageDir & "/Document.java"
  163. ]/**
  164.  * Document.java
  165.  *
  166.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  167.  * All rights reserved.
  168.  *
  169.  * This file was generated by XML Spy.
  170.  * DO NOT ALTER THIS FILE.
  171.  *
  172.  * Refer to the XML Spy Documentation for further details.
  173.  * http://www.xmlspy.com
  174.  */
  175.  
  176.  
  177. package [=$JavaPackageName];
  178.  
  179. public class Document extends com.altova.xml.Document {
  180.     public void declareNamespaces(com.altova.xml.Node node) {
  181. [foreach $namespace in $namespaces
  182.     if $namespace.URI <> ""
  183. ]        declareNamespace(node, "[=$namespace.Prefix]", "[=$namespace.URI]");
  184. [    endif
  185. next
  186. ]    }
  187. }
  188. [
  189. close
  190. 'foreach $namespace in $namespaces
  191.     foreach $class in $classes        
  192.         $FullPackageDir = " "
  193.         $FullPackageName = " "
  194.  
  195.         if $class.NamespacePrefix = ""
  196.             $FullPackageDir  = $JavaPackageDir
  197.             $FullPackageName = $JavaPackageName
  198.         else            
  199.             $FullPackageDir  = $JavaPackageDir  & "/" & $class.NamespacePrefix
  200.             $FullPackageName = $JavaPackageName & "." & $class.NamespacePrefix
  201.         endif
  202.         if not $class.IsInternal
  203.             create $outputpath & "/" & $FullPackageDir & "/" & $class.Name & ".java"
  204. ]/**
  205.  * [=$class.Name].java
  206.  *
  207.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  208.  * All rights reserved.
  209.  *
  210.  * This file was generated by XML Spy.
  211.  * DO NOT ALTER THIS FILE.
  212.  *
  213.  * Refer to the XML Spy Documentation for further details.
  214.  * http://www.xmlspy.com
  215.  */
  216.  
  217.  
  218. [            if $class.IsComplexType
  219. ]package [=$FullPackageName];
  220.  
  221. import com.altova.xml.types.*;
  222.  
  223. public class [=$class.Name] extends com.altova.xml.Node {
  224.     public [=$class.Name]() {
  225.         super();
  226.     }
  227.  
  228.     public [=$class.Name]([=$class.Name] node) {
  229.         super(node);
  230.     }
  231.  
  232.     public [=$class.Name](org.w3c.dom.Node node) {
  233.         super(node);
  234.     }
  235.  
  236.     public [=$class.Name](org.w3c.dom.Document doc) {
  237.         super(doc);
  238.     }
  239. [                if $class.IsComplexFromSimpleType
  240. ]
  241.     public [=$class.Base] getValue() {
  242.         return new [=$class.Base](getDomNodeValue(domNode));
  243.     }
  244.  
  245.     public void setValue([=$class.Base] value) {
  246.         setDomNodeValue(domNode, value.asString());
  247.     }
  248. [                endif
  249.  
  250.                 foreach $member in $class.Members
  251.                     if $member.HasTypeObject
  252.                         if $member.TypeObject.NamespacePrefix <> $class.NamespacePrefix
  253.                             if $member.TypeObject.NamespacePrefix <> ""
  254.                                 $QualifiedType = $JavaPackageName & "." & $member.TypeObject.NamespacePrefix & "." & $member.Type
  255.                             else
  256.                                 $QualifiedType = $JavaPackageName & "." & $member.Type
  257.                             endif
  258.                         else
  259.                             $QualifiedType = $member.Type
  260.                         endif
  261.                     else
  262.                         $QualifiedType = $member.Type
  263.                     endif
  264.  
  265.                     if $member.NamespaceURI = ""
  266.                         $MemberNamespaceURI = "null"
  267.                     else
  268.                         $MemberNamespaceURI = "\"" & $member.NamespaceURI & "\""
  269.                     endif
  270. ]
  271.     public int get[=$member.Name]MinCount() {
  272.         return [=$member.MinOcc];
  273.     }
  274.  
  275.     public int get[=$member.Name]MaxCount() {
  276.         return [if $member.MaxOcc = -1]Integer.MAX_VALUE[else][=$member.MaxOcc][endif];
  277.     }
  278.  
  279.     public int get[=$member.Name]Count() {
  280.         return getDomChildCount([=$member.NodeType], [=$MemberNamespaceURI], "[=$member.Name]");
  281.     }
  282.  
  283.     boolean has[=$member.Name]() {
  284.         return get[=$member.Name]Count() > 0;
  285.     }
  286.  
  287.     public [=$QualifiedType] get[=$member.Name]At(int index) {
  288. [                    if $member.IsSimpleType
  289. ]        return new [=$QualifiedType](getDomNodeValue(getDomChildAt([=$member.NodeType], [=$MemberNamespaceURI], "[=$member.Name]", index)));
  290. [                    else
  291. ]        return new [=$QualifiedType](getDomChildAt([=$member.NodeType], [=$MemberNamespaceURI], "[=$member.Name]", index));
  292. [                    endif
  293. ]    }
  294.  
  295.     public [=$QualifiedType] get[=$member.Name]() {
  296.         return get[=$member.Name]At(0);
  297.     }
  298.  
  299.     public void remove[=$member.Name]At(int nIndex) {
  300. [                    if $member.MaxOcc > 1
  301. ]        remove[=$member.Name]At(0);
  302. [                    else
  303. ]        while (has[=$member.Name]())
  304.             remove[=$member.Name]At(0);
  305. [                    endif
  306. ]    }
  307.  
  308.     public void remove[=$member.Name]() {
  309.         remove[=$member.Name]At(0);
  310.     }
  311.  
  312.     public void add[=$member.Name]([=$QualifiedType] value) {
  313. [                    if $member.IsSimpleType
  314. ]        setDomChild([=$member.NodeType], [=$MemberNamespaceURI], "[=$member.Name]", value.asString());
  315. [                    else
  316. ]        cloneDomElement([=$MemberNamespaceURI], "[=$member.Name]", value);
  317. [                    endif
  318. ]    }
  319. [                next
  320. ]}
  321. [            else
  322.                 if $class.IsSimpleType and not $class.IsInternal
  323.                     if $class.Base = $class.BuiltInBase
  324.                         $IsDirectChild = true
  325.                     else
  326.                         $IsDirectChild = false
  327.                     endif
  328. ]package [=$FullPackageName];
  329.  
  330. import com.altova.xml.types.*;
  331.  
  332. public class [=$class.Name] extends [=$class.Base] {
  333.     public [=$class.Name](String newValue) {
  334.         super(newValue);
  335.         validate();
  336.     }
  337.  
  338.     public void validate() {
  339. [
  340.                     if not $IsDirectChild
  341. ]        super.validate();
  342. [
  343.                     endif
  344.                     foreach $facet in $class.Facets
  345.                         if $facet.IsMinLength
  346. ]        if( value.length() < getMinLength() )
  347.             throw new com.altova.xml.XmlException("Too short");
  348. [                        else:if $facet.IsMaxLength
  349. ]        if( value.length() > getMaxLength() )
  350.             throw new com.altova.xml.XmlException("Too long");
  351. [                        else:if $facet.IsLength]
  352.         if( value.length() != getRequiredLength() )
  353.             throw new com.altova.xml.XmlException("Invalid length");
  354. [                        else:if $facet.IsMinInclusive]
  355.         if( value < getMinInclusive() )
  356.             throw new com.altova.xml.XmlException("Out of range");
  357. [                        else:if $facet.IsMinExclusive]
  358.         if( value <= getMinExclusive() )
  359.             throw new com.altova.xml.XmlException("Out of range");
  360. [                        else:if $facet.IsMaxExclusive]
  361.         if( value >= getMaxExclusive() )
  362.             throw new com.altova.xml.XmlException("Out of range");
  363. [                        else:if $facet.IsMaxInclusive]
  364.         if( value > getMaxInclusive() )
  365.             throw new com.altova.xml.XmlException("Out of range");
  366. [                        endif:endif:endif:endif:endif:endif:endif
  367.                     next
  368. ]    }
  369. [
  370.                     foreach $facet in $class.Facets
  371.                         if $facet.IsMinLength
  372. ]    public int getMinLength() {
  373.         return [=$facet.Constraint];
  374.     }
  375. [                        else:if $facet.IsMaxLength
  376. ]    public int getMaxLength() {
  377.         return [=$facet.Constraint];
  378.     }
  379. [                        else:if $facet.IsLength
  380. ]    public int getRequiredLength() {
  381.         return [=$facet.Constraint];
  382.     }
  383. [                        else:if $facet.IsMinInclusive
  384. ]    public int getMinInclusive() {
  385.         return [=$facet.Constraint];
  386.     }
  387. [                        else:if $facet.IsMinExclusive
  388. ]    public int getMinExclusive() {
  389.         return [=$facet.Constraint];
  390.     }
  391. [                        else:if $facet.IsMaxExclusive
  392. ]    public int getMaxExclusive() {
  393.         return [=$facet.Constraint];
  394.     }
  395. [                        else:if $facet.IsMaxInclusive
  396. ]    public int getMaxInclusive() {
  397.         return [=$facet.Constraint];
  398.     }
  399. [                        endif:endif:endif:endif:endif:endif:endif
  400.                     next
  401. ]}
  402. [                endif
  403.             endif
  404.             close
  405.         endif
  406.     next
  407. 'next
  408. '-----BEGIN ALTOVA XML CLASSES-----
  409. create $outputpath & "/com/altova/xml/types/SchemaBoolean.java"
  410. ]/**
  411.  * SchemaBoolean.java
  412.  *
  413.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  414.  * All rights reserved.
  415.  *
  416.  * Refer to the XML Spy Documentation for further details.
  417.  * http://www.xmlspy.com
  418.  */
  419.  
  420.  
  421. package com.altova.xml.types;
  422.  
  423.  
  424. public class SchemaBoolean extends SchemaType
  425. {
  426.     protected boolean value;
  427.  
  428.     public SchemaBoolean(boolean newvalue) {
  429.         value = newvalue;
  430.     }
  431.  
  432.     public SchemaBoolean(String newvalue) {
  433.         value = newvalue == "true" || newvalue == "1";
  434.     }
  435.  
  436.     public boolean getValue() {
  437.         return value;
  438.     }
  439.  
  440.     public String asString() {
  441.         return value ? "true" : "false";
  442.     }
  443. }
  444. [
  445. close
  446. create $outputpath & "/com/altova/xml/types/SchemaDouble.java"
  447. ]/**
  448.  * SchemaDouble.java
  449.  *
  450.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  451.  * All rights reserved.
  452.  *
  453.  * Refer to the XML Spy Documentation for further details.
  454.  * http://www.xmlspy.com
  455.  */
  456.  
  457.  
  458. package com.altova.xml.types;
  459.  
  460.  
  461. public class SchemaDouble extends SchemaType
  462. {
  463.     protected double value;
  464.  
  465.     public SchemaDouble(double newvalue) {
  466.         value = newvalue;
  467.     }
  468.  
  469.     public SchemaDouble(String newvalue) {
  470.         value = Double.parseDouble(newvalue);
  471.     }
  472.  
  473.     public double getValue() {
  474.         return value;
  475.     }
  476.  
  477.     public String asString() {
  478.         return Double.toString(value);
  479.     }
  480. }
  481. [
  482. close
  483. create $outputpath & "/com/altova/xml/types/SchemaInteger.java"
  484. ]/**
  485.  * SchemaInteger.java
  486.  *
  487.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  488.  * All rights reserved.
  489.  *
  490.  * Refer to the XML Spy Documentation for further details.
  491.  * http://www.xmlspy.com
  492.  */
  493.  
  494.  
  495. package com.altova.xml.types;
  496.  
  497.  
  498. public class SchemaInteger extends SchemaType
  499. {
  500.     protected int value;
  501.  
  502.     public SchemaInteger(int newvalue) {
  503.         value = newvalue;
  504.     }
  505.  
  506.     public SchemaInteger(String newvalue) {
  507.         value = Integer.parseInt(newvalue);
  508.     }
  509.  
  510.     public int getValue() {
  511.         return value;
  512.     }
  513.  
  514.     public String asString() {
  515.         return Integer.toString(value);
  516.     }
  517. }
  518. [
  519. close
  520. create $outputpath & "/com/altova/xml/types/SchemaString.java"
  521. ]/**
  522.  * SchemaString.java
  523.  *
  524.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  525.  * All rights reserved.
  526.  *
  527.  * Refer to the XML Spy Documentation for further details.
  528.  * http://www.xmlspy.com
  529.  */
  530.  
  531.  
  532. package com.altova.xml.types;
  533.  
  534.  
  535. public class SchemaString extends SchemaType
  536. {
  537.     protected String value;
  538.  
  539.     public SchemaString(String value) {
  540.         this.value = value;
  541.     }
  542.  
  543.     public String asString() {
  544.         return value;
  545.     }
  546. }
  547. [
  548. close
  549. create $outputpath & "/com/altova/xml/types/SchemaType.java"
  550. ]/**
  551.  * SchemaType.java
  552.  *
  553.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  554.  * All rights reserved.
  555.  *
  556.  * Refer to the XML Spy Documentation for further details.
  557.  * http://www.xmlspy.com
  558.  */
  559.  
  560.  
  561. package com.altova.xml.types;
  562.  
  563.  
  564. public abstract class SchemaType implements java.io.Serializable {
  565.     public abstract String asString();
  566. }
  567. [
  568. close
  569. create $outputpath & "/com/altova/xml/Document.java"
  570. ]/**
  571.  * Document.java
  572.  *
  573.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  574.  * All rights reserved.
  575.  *
  576.  * Refer to the XML Spy Documentation for further details.
  577.  * http://www.xmlspy.com
  578.  */
  579.  
  580.  
  581. package com.altova.xml;
  582.  
  583.  
  584. public abstract class Document implements java.io.Serializable {
  585.     protected static javax.xml.parsers.DocumentBuilderFactory factory        = null;
  586.     protected static javax.xml.parsers.DocumentBuilder        builder        = null;
  587.     protected static org.w3c.dom.Document                     tmpDocument    = null;
  588.     protected static org.w3c.dom.DocumentFragment             tmpFragment    = null;
  589.     protected static int                                      tmpNameCounter = 0;
  590.  
  591.     protected static synchronized javax.xml.parsers.DocumentBuilder getDomBuilder() {
  592.         try {
  593.             if (builder == null) {
  594.                 if (factory == null) {
  595.                     factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
  596.                     factory.setNamespaceAware(true);
  597.                     //factory.setValidating(true);
  598.                 }
  599.                 builder = factory.newDocumentBuilder();
  600.  
  601.                 builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
  602.                     public void warning(org.xml.sax.SAXParseException e) {
  603.                     }
  604.                     public void error(org.xml.sax.SAXParseException e) throws XmlException {
  605.                         throw new XmlException(e);
  606.                     }
  607.                     public void fatalError(org.xml.sax.SAXParseException e) throws XmlException {
  608.                         throw new XmlException(e);
  609.                     }
  610.                 });
  611.             }
  612.             return builder;
  613.         } catch (javax.xml.parsers.ParserConfigurationException e) {
  614.             throw new XmlException(e);
  615.         }
  616.     }
  617.  
  618.     protected static synchronized org.w3c.dom.Document getTemporaryDocument() {
  619.         if (tmpDocument == null)
  620.             tmpDocument = getDomBuilder().newDocument();
  621.         return tmpDocument;
  622.     }
  623.  
  624.     protected static synchronized org.w3c.dom.Node createTemporaryDomNode() {
  625.         String tmpName = "_" + tmpNameCounter++;
  626.         if (tmpFragment == null) {
  627.             tmpFragment = getTemporaryDocument().createDocumentFragment();
  628.             tmpDocument.appendChild(tmpFragment);
  629.         }
  630.         org.w3c.dom.Node node = getTemporaryDocument().createElement(tmpName);
  631.         tmpFragment.appendChild(node);
  632.         return node;
  633.     }
  634.  
  635.     protected String rootElementName = null;
  636.     protected String namespaceURI    = null;
  637.     protected String schemaLocation  = null;
  638.  
  639.     public Document() {
  640.     }
  641.  
  642.     public void setRootElementName(String namespaceURI, String rootElementName) {
  643.         this.namespaceURI    = namespaceURI;
  644.         this.rootElementName = rootElementName;
  645.     }
  646.  
  647.     public void setSchemaLocation(String schemaLocation) {
  648.         this.schemaLocation = schemaLocation;
  649.     }
  650.  
  651.     public org.w3c.dom.Node load(String filename) {
  652.         try {
  653.             return getDomBuilder().parse(new java.io.File(filename)).getDocumentElement();
  654.         } catch (org.xml.sax.SAXException e) {
  655.             throw new XmlException(e);
  656.         } catch (java.io.IOException e) {
  657.             throw new XmlException(e);
  658.         }
  659.     }
  660.  
  661.     public void save(String filename, Node node) {
  662.         try {
  663.             finalizeRootElement(node);
  664.             java.io.FileOutputStream os = new java.io.FileOutputStream(filename);
  665.             java.util.Properties prop =  org.apache.xalan.templates.OutputProperties.getDefaultMethodProperties("xml");
  666.             prop.setProperty(javax.xml.transform.OutputKeys.METHOD, "xml");
  667.             org.apache.xalan.serialize.Serializer serializer = org.apache.xalan.serialize.SerializerFactory.getSerializer(prop);
  668.             serializer.setOutputStream(os);
  669.             serializer.asDOMSerializer().serialize(node.domNode.getOwnerDocument());
  670.         } catch (java.io.IOException e) {
  671.             throw new XmlException(e);
  672.         }
  673.     }
  674.  
  675.     protected void finalizeRootElement(Node root) {
  676.         if (root.domNode.getParentNode().getNodeType() != org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE)
  677.             return;
  678.  
  679.         if (rootElementName == null || rootElementName == "")
  680.             throw new XmlException("Call setRootElementName first");
  681.  
  682.         org.w3c.dom.Document doc = getDomBuilder().newDocument();
  683.         org.w3c.dom.Element newRootElement = doc.createElementNS(namespaceURI, rootElementName);
  684.         root.cloneInto(newRootElement);
  685.         doc.appendChild(newRootElement);
  686.  
  687.         newRootElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
  688.         if (namespaceURI == null || namespaceURI == "") {
  689.             if (schemaLocation != null && schemaLocation != "")
  690.                 newRootElement.setAttribute("xsi:noNamespaceSchemaLocation", schemaLocation);
  691.         } else {
  692.             if (schemaLocation != null && schemaLocation != "")
  693.                 newRootElement.setAttribute("xsi:schemaLocation", namespaceURI + " " + schemaLocation);
  694.         }
  695.  
  696.         root.domNode = newRootElement;
  697.         declareNamespaces(root);
  698.     }
  699.  
  700.     public abstract void declareNamespaces(Node node);
  701.  
  702.     protected void declareNamespace(Node node, String prefix, String URI) {
  703.         node.declareNamespace(prefix, URI);
  704.     }
  705. }
  706. [
  707. close
  708. create $outputpath & "/com/altova/xml/Node.java"
  709. ]/**
  710.  * Node.java
  711.  *
  712.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  713.  * All rights reserved.
  714.  *
  715.  * Refer to the XML Spy Documentation for further details.
  716.  * http://www.xmlspy.com
  717.  */
  718.  
  719.  
  720. package com.altova.xml;
  721.  
  722.  
  723. public abstract class Node implements java.io.Serializable {
  724.     final protected static short Attribute = 0;
  725.     final protected static short Element   = 1;
  726.  
  727.     protected static String getDomNodeValue(org.w3c.dom.Node node) {
  728.         if (node == null)
  729.             return null;
  730.         String value = node.getNodeValue();
  731.         if (value != null)
  732.             return value;
  733.         org.w3c.dom.Node child = node.getFirstChild();
  734.         if (child != null && child.getNodeType() == org.w3c.dom.Node.TEXT_NODE)
  735.             return child.getNodeValue();
  736.         else
  737.             return null;
  738.     }
  739.  
  740.     protected static void setDomNodeValue(org.w3c.dom.Node node, String value) {
  741.         if (node == null)
  742.             return;
  743.         if (node.getNodeValue() != null) {
  744.             node.setNodeValue(value);
  745.             return;
  746.         }
  747.         org.w3c.dom.Node child = node.getFirstChild();
  748.         if (child == null || child.getNodeType() != org.w3c.dom.Node.TEXT_NODE) {
  749.             node.appendChild(node.getOwnerDocument().createTextNode(value));
  750.             return;
  751.         }
  752.     }
  753.  
  754.     protected org.w3c.dom.Node domNode = null;
  755.  
  756.     public Node() {
  757.         domNode = Document.createTemporaryDomNode();
  758.     }
  759.  
  760.     public Node(Node node) {
  761.         domNode = node.domNode;
  762.     }
  763.  
  764.     public Node(org.w3c.dom.Node domNode) {
  765.         this.domNode = domNode;
  766.     }
  767.  
  768.     public Node(org.w3c.dom.Document domDocument) {
  769.         this.domNode = domDocument.getDocumentElement();
  770.     }
  771.     
  772.     public org.w3c.dom.Node getDomNode() {
  773.         return domNode;
  774.     }
  775.  
  776.     protected void declareNamespace(String prefix, String URI) {
  777.         if (URI == null || URI == "")
  778.             return;
  779.         
  780.         org.w3c.dom.Element root = domNode.getOwnerDocument().getDocumentElement();
  781.         if (prefix == null || prefix == "")
  782.             root.setAttribute("xmlns", URI);
  783.         else
  784.             root.setAttribute("xmlns:" + prefix, URI);
  785.     }
  786.  
  787.     protected org.w3c.dom.Node appendDomChild(int type, String namespaceURI, String name, String value) {
  788.         switch (type) {
  789.         case Attribute:
  790.             org.w3c.dom.Attr attribute = domNode.getOwnerDocument().createAttributeNS(namespaceURI, name);
  791.             attribute.setNodeValue(value);
  792.             domNode.getAttributes().setNamedItemNS(attribute);
  793.             return attribute;
  794.  
  795.         case Element:
  796.             org.w3c.dom.Element element = domNode.getOwnerDocument().createElementNS(namespaceURI, name);
  797.             if (value != null && value != "")
  798.                 element.appendChild(domNode.getOwnerDocument().createTextNode(value));
  799.             domNode.appendChild(element);
  800.             return element;
  801.  
  802.         default:
  803.             throw new XmlException("Unknown type");
  804.         }
  805.     }
  806.  
  807.     protected boolean domNodeNameEquals(org.w3c.dom.Node node, String namespaceURI, String name) {
  808.         return node.getNamespaceURI() == namespaceURI && node.getNodeName() == name;
  809.     }
  810.  
  811.     protected int getDomChildCount(int type, String namespaceURI, String name) {
  812.         switch (type) {
  813.         case Attribute:
  814.             return ((org.w3c.dom.Element)domNode).hasAttributeNS(namespaceURI, name) ? 1 : 0;
  815.  
  816.         case Element:
  817.             org.w3c.dom.NodeList elements = domNode.getChildNodes();
  818.             int length = elements.getLength();
  819.             int count = 0;
  820.  
  821.             for (int i = 0; i < length; i++) {
  822.                 org.w3c.dom.Node child = elements.item(i);
  823.                 if (domNodeNameEquals(child, namespaceURI, name))
  824.                     count++;
  825.             }
  826.             return count;
  827.  
  828.         default:
  829.             throw new XmlException("Unknown type");
  830.         }
  831.     }
  832.  
  833.     protected org.w3c.dom.Node getDomChildAt(int type, String namespaceURI, String name, int index) {
  834.         int length, count = 0;
  835.  
  836.         switch (type) {
  837.         case Attribute:
  838.             return domNode.getAttributes().getNamedItemNS(namespaceURI, name);
  839.  
  840.         case Element:
  841.             org.w3c.dom.NodeList elements = domNode.getChildNodes();
  842.             length = elements.getLength();
  843.             for (int i = 0; i < length; i++) {
  844.                 org.w3c.dom.Node child = elements.item(i);
  845.                 if (domNodeNameEquals(child, namespaceURI, name) && count++ == index)
  846.                     return child;
  847.             }
  848.             throw new XmlException("Index out of range");
  849.  
  850.         default:
  851.             throw new XmlException("Unknown type");
  852.         }
  853.     }
  854.  
  855.     protected org.w3c.dom.Node getDomChild(int type, String namespaceURI, String name) {
  856.         return getDomChildAt(type, namespaceURI, name, 0);
  857.     }
  858.  
  859.     protected org.w3c.dom.Node setDomChildAt(int type, String namespaceURI, String name, String value, int index) {
  860.         int length, count = 0;
  861.  
  862.         switch (type) {
  863.         case Attribute:
  864.             org.w3c.dom.Attr oldAttr = ((org.w3c.dom.Element)domNode).getAttributeNodeNS(namespaceURI, name);
  865.             ((org.w3c.dom.Element)domNode).setAttributeNS(namespaceURI, name, value);
  866.             return oldAttr;
  867.  
  868.         case Element:
  869.             org.w3c.dom.NodeList elements = domNode.getChildNodes();
  870.             length = elements.getLength();
  871.             for (int i = 0; i < length; i++) {
  872.                 org.w3c.dom.Node child = elements.item(i);
  873.                 if (domNodeNameEquals(child, namespaceURI, name) && count++ == index) {
  874.                     child.setNodeValue(value);
  875.                     return child;
  876.                 }
  877.             }
  878.             throw new XmlException("Index out of range");
  879.  
  880.         default:
  881.             throw new XmlException("Unknown type");
  882.         }
  883.     }
  884.  
  885.     protected org.w3c.dom.Node setDomChild(int type, String namespaceURI, String name, String value) {
  886.         if (type == Attribute || getDomChildCount(type, namespaceURI, name) > 0) {
  887.             return setDomChildAt(type, namespaceURI, name, value, 0);
  888.         } else {
  889.             appendDomChild(type, namespaceURI, name, value);
  890.             return null;
  891.         }
  892.     }
  893.  
  894.     protected org.w3c.dom.Node removeDomChildAt(int type, String namespaceURI, String name, int index) {
  895.         int length, count = 0;
  896.  
  897.         switch (type) {
  898.         case Attribute:
  899.             return domNode.getAttributes().removeNamedItemNS(namespaceURI, name);
  900.  
  901.         case Element:
  902.             org.w3c.dom.NodeList elements = domNode.getChildNodes();
  903.             length = elements.getLength();
  904.             for (int i = 0; i < length; i++) {
  905.                 org.w3c.dom.Node child = elements.item(i);
  906.                 if (domNodeNameEquals(child, namespaceURI, name) && count++ == index)
  907.                     return domNode.removeChild(child);
  908.             }
  909.             throw new XmlException("Index out of range");
  910.  
  911.         default:
  912.             throw new XmlException("Unknown type");
  913.         }
  914.     }
  915.  
  916.     protected void cloneDomElement(String namespaceURI, String name, com.altova.xml.Node srcNode) {
  917.         org.w3c.dom.Element newDomNode = domNode.getOwnerDocument().createElementNS(namespaceURI, name);
  918.         org.w3c.dom.Element srcDomNode = (org.w3c.dom.Element)srcNode.domNode;
  919.  
  920.         while (srcDomNode.getFirstChild() != null) {
  921.             org.w3c.dom.Node n = newDomNode.getOwnerDocument().importNode(srcDomNode.getFirstChild(), true);
  922.             newDomNode.appendChild(n);
  923.             srcDomNode.removeChild(srcDomNode.getFirstChild());
  924.         }
  925.  
  926.         org.w3c.dom.NamedNodeMap srcAttributes = srcNode.domNode.getAttributes();
  927.         org.w3c.dom.NamedNodeMap newAttributes = newDomNode.getAttributes();
  928.  
  929.         while (srcAttributes.getLength() > 0)
  930.             newAttributes.setNamedItem(srcAttributes.removeNamedItem(srcAttributes.item(0).getNodeName()));
  931.  
  932.         srcNode.domNode = newDomNode;
  933.         domNode.appendChild(newDomNode);
  934.     }
  935.  
  936.     protected void cloneInto(org.w3c.dom.Element newDomNode) {
  937.         while (domNode.getFirstChild() != null) {
  938.             org.w3c.dom.Node n = newDomNode.getOwnerDocument().importNode(domNode.getFirstChild(), true);
  939.             newDomNode.appendChild(n);
  940.             domNode.removeChild(domNode.getFirstChild());
  941.         }
  942.  
  943.         org.w3c.dom.NamedNodeMap srcAttributes = ((org.w3c.dom.Element)domNode).getAttributes();
  944.         org.w3c.dom.NamedNodeMap newAttributes = newDomNode.getAttributes();
  945.         while (srcAttributes.getLength() > 0)
  946.             newAttributes.setNamedItem(srcAttributes.removeNamedItem(srcAttributes.item(0).getNodeName()));
  947.  
  948.         domNode = newDomNode;
  949.     }
  950. }[
  951. close
  952. create $outputpath & "/com/altova/xml/XmlException.java"
  953. ]/**
  954.  * XmlException.java
  955.  *
  956.  * Copyright (C) 2002 Altova GmbH - The XML Spy Company
  957.  * All rights reserved.
  958.  *
  959.  * Refer to the XML Spy Documentation for further details.
  960.  * http://www.xmlspy.com
  961.  */
  962.  
  963.  
  964. package com.altova.xml;
  965.  
  966.  
  967. public class XmlException extends RuntimeException {
  968.     protected java.lang.Exception   innerException;
  969.     protected String                message;
  970.  
  971.     public XmlException(String text) {
  972.         innerException = null;
  973.         message = text;
  974.     }
  975.  
  976.     public XmlException(java.lang.Exception other) {
  977.         innerException = other;
  978.         message = other.getMessage();
  979.     }
  980.  
  981.     public String getMessage() {
  982.         return message;
  983.     }
  984.  
  985.     public java.lang.Exception getInnerException() {
  986.         return innerException;
  987.     }
  988. }
  989. [
  990. close
  991. '-----END ALTOVA XML CLASSES-----
  992. create $outputpath & "/Build" & $module & ".xml"
  993. ]<project name="[=$module]" default="test" basedir=".">
  994.     <target name="compile">
  995.         <javac srcdir="com/altova/xml" destdir="."/>
  996.         <javac srcdir="[=$JavaPackageDir]" destdir="."/>
  997.     </target>
  998.     <target name="test" depends="compile">
  999.         <java classname="[=$JavaPackageName].[=$module]Test" fork="true" failonerror="true"/>
  1000.     </target>
  1001.     <target name="clean">
  1002.         <delete>
  1003.             <fileset dir=".">
  1004.                 <include name="**/*.class"/>
  1005.             </fileset>
  1006.         </delete>
  1007.     </target>
  1008. </project>
  1009. [close]