home *** CD-ROM | disk | FTP | other *** search
INI File | 2002-09-15 | 29.5 KB | 1,009 lines |
- [
- '-----------------------------------------------------------
- ' Java XML Project Template
- '
- ' Copyright (C) 2002 Altova GmbH - The XML Spy Company
- ' All rights reserved.
- '
- ' XML Spy generates Java classes based on this template.
- ' Refer to the XML Spy Documentation for further details.
- '
- ' http://www.xmlspy.com
- '-----------------------------------------------------------
-
- map type "boolean" to "SchemaBoolean"
-
- map type "byte" to "SchemaInteger"
- map type "unsignedByte" to "SchemaInteger"
- map type "short" to "SchemaInteger"
- map type "unsignedShort" to "SchemaInteger"
- map type "int" to "SchemaInteger"
- map type "unsignedInt" to "SchemaInteger"
- map type "long" to "SchemaInteger"
- map type "unsignedLong" to "SchemaInteger"
-
- map type "integer" to "SchemaInteger"
- map type "nonPositiveInteger" to "SchemaInteger"
- map type "negativeInteger" to "SchemaInteger"
- map type "positiveInteger" to "SchemaInteger"
- map type "nonNegativeInteger" to "SchemaInteger"
- map type "decimal" to "SchemaInteger"
-
- map type "float" to "SchemaDouble"
- map type "double" to "SchemaDouble"
-
- map type "duration" to "SchemaString"
- map type "gYear" to "SchemaInteger"
- map type "gDay" to "SchemaInteger"
- map type "gMonth" to "SchemaInteger"
- map type "gYearMonth" to "SchemaString"
- map type "gMonthDay" to "SchemaString"
- map type "date" to "SchemaString"
- map type "time" to "SchemaString"
- map type "dateTime" to "SchemaString"
-
- map type "string" to "SchemaString"
- map type "hexBinary" to "SchemaString"
- map type "base64Binary" to "SchemaString"
- map type "anyURI" to "SchemaString"
- map type "QName" to "SchemaString"
- map type "NOTATION" to "SchemaString"
- map type "normalizedString" to "SchemaString"
- map type "token" to "SchemaString"
- map type "language" to "SchemaString"
- map type "IDREF" to "SchemaString"
- map type "ENTITY" to "SchemaString"
- map type "NMTOKEN" to "SchemaString"
- map type "Name" to "SchemaString"
- map type "NCName" to "SchemaString"
- map type "ID" to "SchemaString"
- map type "IDREFS" to "SchemaString"
- map type "ENTITIES" to "SchemaString"
- map type "NMTOKENS" to "SchemaString"
-
- default "ValidFirstCharSet" is "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- default "ValidCharSet" is "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789"
- default "InvalidCharReplacement" is "_"
- default "AnonTypePrefix" is ""
- default "AnonTypeSuffix" is "Type"
- default "ClassNamePrefix" is ""
- default "ClassNameSuffix" is ""
-
- reserve "abstract"
- reserve "boolean"
- reserve "break"
- reserve "byte"
- reserve "case"
- reserve "catch"
- reserve "char"
- reserve "class"
- reserve "const"
- reserve "continue"
- reserve "default"
- reserve "do"
- reserve "double"
- reserve "else"
- reserve "extends"
- reserve "false"
- reserve "final"
- reserve "finally"
- reserve "float"
- reserve "for"
- reserve "goto"
- reserve "if"
- reserve "implements"
- reserve "import"
- reserve "instanceof"
- reserve "int"
- reserve "interface"
- reserve "long"
- reserve "native"
- reserve "new"
- reserve "null"
- reserve "package"
- reserve "private"
- reserve "protected"
- reserve "public"
- reserve "return"
- reserve "short"
- reserve "static"
- reserve "strictfp"
- reserve "super"
- reserve "switch"
- reserve "synchronized"
- reserve "this"
- reserve "throw"
- reserve "throws"
- reserve "transient"
- reserve "true"
- reserve "try"
- reserve "void"
- reserve "volatile"
- reserve "while"
-
- $JavaPackageName = "com.schema"
- $JavaPackageDir = "com/schema"
-
- create $outputpath & "/" & $JavaPackageDir & "/" & $module & "Test.java"
- ]/**
- * [=$module]Test.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * This file was generated by XML Spy.
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package [=$JavaPackageName];
-
- import com.altova.xml.types.*;
-
- public class [=$module]Test {
- protected static void sample() {
- // TODO:
- // Place your code here...
- }
-
- public static void main(String args\[\]) {
- try {
- System.out.println("[=$module] Test Application");
- sample();
- System.out.println("OK");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- [
- close
- create $outputpath & "/" & $JavaPackageDir & "/Document.java"
- ]/**
- * Document.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * This file was generated by XML Spy.
- * DO NOT ALTER THIS FILE.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package [=$JavaPackageName];
-
- public class Document extends com.altova.xml.Document {
- public void declareNamespaces(com.altova.xml.Node node) {
- [foreach $namespace in $namespaces
- if $namespace.URI <> ""
- ] declareNamespace(node, "[=$namespace.Prefix]", "[=$namespace.URI]");
- [ endif
- next
- ] }
- }
- [
- close
- 'foreach $namespace in $namespaces
- foreach $class in $classes
- $FullPackageDir = " "
- $FullPackageName = " "
-
- if $class.NamespacePrefix = ""
- $FullPackageDir = $JavaPackageDir
- $FullPackageName = $JavaPackageName
- else
- $FullPackageDir = $JavaPackageDir & "/" & $class.NamespacePrefix
- $FullPackageName = $JavaPackageName & "." & $class.NamespacePrefix
- endif
- if not $class.IsInternal
- create $outputpath & "/" & $FullPackageDir & "/" & $class.Name & ".java"
- ]/**
- * [=$class.Name].java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * This file was generated by XML Spy.
- * DO NOT ALTER THIS FILE.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- [ if $class.IsComplexType
- ]package [=$FullPackageName];
-
- import com.altova.xml.types.*;
-
- public class [=$class.Name] extends com.altova.xml.Node {
- public [=$class.Name]() {
- super();
- }
-
- public [=$class.Name]([=$class.Name] node) {
- super(node);
- }
-
- public [=$class.Name](org.w3c.dom.Node node) {
- super(node);
- }
-
- public [=$class.Name](org.w3c.dom.Document doc) {
- super(doc);
- }
- [ if $class.IsComplexFromSimpleType
- ]
- public [=$class.Base] getValue() {
- return new [=$class.Base](getDomNodeValue(domNode));
- }
-
- public void setValue([=$class.Base] value) {
- setDomNodeValue(domNode, value.asString());
- }
- [ endif
-
- foreach $member in $class.Members
- if $member.HasTypeObject
- if $member.TypeObject.NamespacePrefix <> $class.NamespacePrefix
- if $member.TypeObject.NamespacePrefix <> ""
- $QualifiedType = $JavaPackageName & "." & $member.TypeObject.NamespacePrefix & "." & $member.Type
- else
- $QualifiedType = $JavaPackageName & "." & $member.Type
- endif
- else
- $QualifiedType = $member.Type
- endif
- else
- $QualifiedType = $member.Type
- endif
-
- if $member.NamespaceURI = ""
- $MemberNamespaceURI = "null"
- else
- $MemberNamespaceURI = "\"" & $member.NamespaceURI & "\""
- endif
- ]
- public int get[=$member.Name]MinCount() {
- return [=$member.MinOcc];
- }
-
- public int get[=$member.Name]MaxCount() {
- return [if $member.MaxOcc = -1]Integer.MAX_VALUE[else][=$member.MaxOcc][endif];
- }
-
- public int get[=$member.Name]Count() {
- return getDomChildCount([=$member.NodeType], [=$MemberNamespaceURI], "[=$member.Name]");
- }
-
- boolean has[=$member.Name]() {
- return get[=$member.Name]Count() > 0;
- }
-
- public [=$QualifiedType] get[=$member.Name]At(int index) {
- [ if $member.IsSimpleType
- ] return new [=$QualifiedType](getDomNodeValue(getDomChildAt([=$member.NodeType], [=$MemberNamespaceURI], "[=$member.Name]", index)));
- [ else
- ] return new [=$QualifiedType](getDomChildAt([=$member.NodeType], [=$MemberNamespaceURI], "[=$member.Name]", index));
- [ endif
- ] }
-
- public [=$QualifiedType] get[=$member.Name]() {
- return get[=$member.Name]At(0);
- }
-
- public void remove[=$member.Name]At(int nIndex) {
- [ if $member.MaxOcc > 1
- ] remove[=$member.Name]At(0);
- [ else
- ] while (has[=$member.Name]())
- remove[=$member.Name]At(0);
- [ endif
- ] }
-
- public void remove[=$member.Name]() {
- remove[=$member.Name]At(0);
- }
-
- public void add[=$member.Name]([=$QualifiedType] value) {
- [ if $member.IsSimpleType
- ] setDomChild([=$member.NodeType], [=$MemberNamespaceURI], "[=$member.Name]", value.asString());
- [ else
- ] cloneDomElement([=$MemberNamespaceURI], "[=$member.Name]", value);
- [ endif
- ] }
- [ next
- ]}
- [ else
- if $class.IsSimpleType and not $class.IsInternal
- if $class.Base = $class.BuiltInBase
- $IsDirectChild = true
- else
- $IsDirectChild = false
- endif
- ]package [=$FullPackageName];
-
- import com.altova.xml.types.*;
-
- public class [=$class.Name] extends [=$class.Base] {
- public [=$class.Name](String newValue) {
- super(newValue);
- validate();
- }
-
- public void validate() {
- [
- if not $IsDirectChild
- ] super.validate();
- [
- endif
- foreach $facet in $class.Facets
- if $facet.IsMinLength
- ] if( value.length() < getMinLength() )
- throw new com.altova.xml.XmlException("Too short");
- [ else:if $facet.IsMaxLength
- ] if( value.length() > getMaxLength() )
- throw new com.altova.xml.XmlException("Too long");
- [ else:if $facet.IsLength]
- if( value.length() != getRequiredLength() )
- throw new com.altova.xml.XmlException("Invalid length");
- [ else:if $facet.IsMinInclusive]
- if( value < getMinInclusive() )
- throw new com.altova.xml.XmlException("Out of range");
- [ else:if $facet.IsMinExclusive]
- if( value <= getMinExclusive() )
- throw new com.altova.xml.XmlException("Out of range");
- [ else:if $facet.IsMaxExclusive]
- if( value >= getMaxExclusive() )
- throw new com.altova.xml.XmlException("Out of range");
- [ else:if $facet.IsMaxInclusive]
- if( value > getMaxInclusive() )
- throw new com.altova.xml.XmlException("Out of range");
- [ endif:endif:endif:endif:endif:endif:endif
- next
- ] }
- [
- foreach $facet in $class.Facets
- if $facet.IsMinLength
- ] public int getMinLength() {
- return [=$facet.Constraint];
- }
- [ else:if $facet.IsMaxLength
- ] public int getMaxLength() {
- return [=$facet.Constraint];
- }
- [ else:if $facet.IsLength
- ] public int getRequiredLength() {
- return [=$facet.Constraint];
- }
- [ else:if $facet.IsMinInclusive
- ] public int getMinInclusive() {
- return [=$facet.Constraint];
- }
- [ else:if $facet.IsMinExclusive
- ] public int getMinExclusive() {
- return [=$facet.Constraint];
- }
- [ else:if $facet.IsMaxExclusive
- ] public int getMaxExclusive() {
- return [=$facet.Constraint];
- }
- [ else:if $facet.IsMaxInclusive
- ] public int getMaxInclusive() {
- return [=$facet.Constraint];
- }
- [ endif:endif:endif:endif:endif:endif:endif
- next
- ]}
- [ endif
- endif
- close
- endif
- next
- 'next
- '-----BEGIN ALTOVA XML CLASSES-----
- create $outputpath & "/com/altova/xml/types/SchemaBoolean.java"
- ]/**
- * SchemaBoolean.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package com.altova.xml.types;
-
-
- public class SchemaBoolean extends SchemaType
- {
- protected boolean value;
-
- public SchemaBoolean(boolean newvalue) {
- value = newvalue;
- }
-
- public SchemaBoolean(String newvalue) {
- value = newvalue == "true" || newvalue == "1";
- }
-
- public boolean getValue() {
- return value;
- }
-
- public String asString() {
- return value ? "true" : "false";
- }
- }
- [
- close
- create $outputpath & "/com/altova/xml/types/SchemaDouble.java"
- ]/**
- * SchemaDouble.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package com.altova.xml.types;
-
-
- public class SchemaDouble extends SchemaType
- {
- protected double value;
-
- public SchemaDouble(double newvalue) {
- value = newvalue;
- }
-
- public SchemaDouble(String newvalue) {
- value = Double.parseDouble(newvalue);
- }
-
- public double getValue() {
- return value;
- }
-
- public String asString() {
- return Double.toString(value);
- }
- }
- [
- close
- create $outputpath & "/com/altova/xml/types/SchemaInteger.java"
- ]/**
- * SchemaInteger.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package com.altova.xml.types;
-
-
- public class SchemaInteger extends SchemaType
- {
- protected int value;
-
- public SchemaInteger(int newvalue) {
- value = newvalue;
- }
-
- public SchemaInteger(String newvalue) {
- value = Integer.parseInt(newvalue);
- }
-
- public int getValue() {
- return value;
- }
-
- public String asString() {
- return Integer.toString(value);
- }
- }
- [
- close
- create $outputpath & "/com/altova/xml/types/SchemaString.java"
- ]/**
- * SchemaString.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package com.altova.xml.types;
-
-
- public class SchemaString extends SchemaType
- {
- protected String value;
-
- public SchemaString(String value) {
- this.value = value;
- }
-
- public String asString() {
- return value;
- }
- }
- [
- close
- create $outputpath & "/com/altova/xml/types/SchemaType.java"
- ]/**
- * SchemaType.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package com.altova.xml.types;
-
-
- public abstract class SchemaType implements java.io.Serializable {
- public abstract String asString();
- }
- [
- close
- create $outputpath & "/com/altova/xml/Document.java"
- ]/**
- * Document.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package com.altova.xml;
-
-
- public abstract class Document implements java.io.Serializable {
- protected static javax.xml.parsers.DocumentBuilderFactory factory = null;
- protected static javax.xml.parsers.DocumentBuilder builder = null;
- protected static org.w3c.dom.Document tmpDocument = null;
- protected static org.w3c.dom.DocumentFragment tmpFragment = null;
- protected static int tmpNameCounter = 0;
-
- protected static synchronized javax.xml.parsers.DocumentBuilder getDomBuilder() {
- try {
- if (builder == null) {
- if (factory == null) {
- factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- //factory.setValidating(true);
- }
- builder = factory.newDocumentBuilder();
-
- builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
- public void warning(org.xml.sax.SAXParseException e) {
- }
- public void error(org.xml.sax.SAXParseException e) throws XmlException {
- throw new XmlException(e);
- }
- public void fatalError(org.xml.sax.SAXParseException e) throws XmlException {
- throw new XmlException(e);
- }
- });
- }
- return builder;
- } catch (javax.xml.parsers.ParserConfigurationException e) {
- throw new XmlException(e);
- }
- }
-
- protected static synchronized org.w3c.dom.Document getTemporaryDocument() {
- if (tmpDocument == null)
- tmpDocument = getDomBuilder().newDocument();
- return tmpDocument;
- }
-
- protected static synchronized org.w3c.dom.Node createTemporaryDomNode() {
- String tmpName = "_" + tmpNameCounter++;
- if (tmpFragment == null) {
- tmpFragment = getTemporaryDocument().createDocumentFragment();
- tmpDocument.appendChild(tmpFragment);
- }
- org.w3c.dom.Node node = getTemporaryDocument().createElement(tmpName);
- tmpFragment.appendChild(node);
- return node;
- }
-
- protected String rootElementName = null;
- protected String namespaceURI = null;
- protected String schemaLocation = null;
-
- public Document() {
- }
-
- public void setRootElementName(String namespaceURI, String rootElementName) {
- this.namespaceURI = namespaceURI;
- this.rootElementName = rootElementName;
- }
-
- public void setSchemaLocation(String schemaLocation) {
- this.schemaLocation = schemaLocation;
- }
-
- public org.w3c.dom.Node load(String filename) {
- try {
- return getDomBuilder().parse(new java.io.File(filename)).getDocumentElement();
- } catch (org.xml.sax.SAXException e) {
- throw new XmlException(e);
- } catch (java.io.IOException e) {
- throw new XmlException(e);
- }
- }
-
- public void save(String filename, Node node) {
- try {
- finalizeRootElement(node);
- java.io.FileOutputStream os = new java.io.FileOutputStream(filename);
- java.util.Properties prop = org.apache.xalan.templates.OutputProperties.getDefaultMethodProperties("xml");
- prop.setProperty(javax.xml.transform.OutputKeys.METHOD, "xml");
- org.apache.xalan.serialize.Serializer serializer = org.apache.xalan.serialize.SerializerFactory.getSerializer(prop);
- serializer.setOutputStream(os);
- serializer.asDOMSerializer().serialize(node.domNode.getOwnerDocument());
- } catch (java.io.IOException e) {
- throw new XmlException(e);
- }
- }
-
- protected void finalizeRootElement(Node root) {
- if (root.domNode.getParentNode().getNodeType() != org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE)
- return;
-
- if (rootElementName == null || rootElementName == "")
- throw new XmlException("Call setRootElementName first");
-
- org.w3c.dom.Document doc = getDomBuilder().newDocument();
- org.w3c.dom.Element newRootElement = doc.createElementNS(namespaceURI, rootElementName);
- root.cloneInto(newRootElement);
- doc.appendChild(newRootElement);
-
- newRootElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
- if (namespaceURI == null || namespaceURI == "") {
- if (schemaLocation != null && schemaLocation != "")
- newRootElement.setAttribute("xsi:noNamespaceSchemaLocation", schemaLocation);
- } else {
- if (schemaLocation != null && schemaLocation != "")
- newRootElement.setAttribute("xsi:schemaLocation", namespaceURI + " " + schemaLocation);
- }
-
- root.domNode = newRootElement;
- declareNamespaces(root);
- }
-
- public abstract void declareNamespaces(Node node);
-
- protected void declareNamespace(Node node, String prefix, String URI) {
- node.declareNamespace(prefix, URI);
- }
- }
- [
- close
- create $outputpath & "/com/altova/xml/Node.java"
- ]/**
- * Node.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package com.altova.xml;
-
-
- public abstract class Node implements java.io.Serializable {
- final protected static short Attribute = 0;
- final protected static short Element = 1;
-
- protected static String getDomNodeValue(org.w3c.dom.Node node) {
- if (node == null)
- return null;
- String value = node.getNodeValue();
- if (value != null)
- return value;
- org.w3c.dom.Node child = node.getFirstChild();
- if (child != null && child.getNodeType() == org.w3c.dom.Node.TEXT_NODE)
- return child.getNodeValue();
- else
- return null;
- }
-
- protected static void setDomNodeValue(org.w3c.dom.Node node, String value) {
- if (node == null)
- return;
- if (node.getNodeValue() != null) {
- node.setNodeValue(value);
- return;
- }
- org.w3c.dom.Node child = node.getFirstChild();
- if (child == null || child.getNodeType() != org.w3c.dom.Node.TEXT_NODE) {
- node.appendChild(node.getOwnerDocument().createTextNode(value));
- return;
- }
- }
-
- protected org.w3c.dom.Node domNode = null;
-
- public Node() {
- domNode = Document.createTemporaryDomNode();
- }
-
- public Node(Node node) {
- domNode = node.domNode;
- }
-
- public Node(org.w3c.dom.Node domNode) {
- this.domNode = domNode;
- }
-
- public Node(org.w3c.dom.Document domDocument) {
- this.domNode = domDocument.getDocumentElement();
- }
-
- public org.w3c.dom.Node getDomNode() {
- return domNode;
- }
-
- protected void declareNamespace(String prefix, String URI) {
- if (URI == null || URI == "")
- return;
-
- org.w3c.dom.Element root = domNode.getOwnerDocument().getDocumentElement();
- if (prefix == null || prefix == "")
- root.setAttribute("xmlns", URI);
- else
- root.setAttribute("xmlns:" + prefix, URI);
- }
-
- protected org.w3c.dom.Node appendDomChild(int type, String namespaceURI, String name, String value) {
- switch (type) {
- case Attribute:
- org.w3c.dom.Attr attribute = domNode.getOwnerDocument().createAttributeNS(namespaceURI, name);
- attribute.setNodeValue(value);
- domNode.getAttributes().setNamedItemNS(attribute);
- return attribute;
-
- case Element:
- org.w3c.dom.Element element = domNode.getOwnerDocument().createElementNS(namespaceURI, name);
- if (value != null && value != "")
- element.appendChild(domNode.getOwnerDocument().createTextNode(value));
- domNode.appendChild(element);
- return element;
-
- default:
- throw new XmlException("Unknown type");
- }
- }
-
- protected boolean domNodeNameEquals(org.w3c.dom.Node node, String namespaceURI, String name) {
- return node.getNamespaceURI() == namespaceURI && node.getNodeName() == name;
- }
-
- protected int getDomChildCount(int type, String namespaceURI, String name) {
- switch (type) {
- case Attribute:
- return ((org.w3c.dom.Element)domNode).hasAttributeNS(namespaceURI, name) ? 1 : 0;
-
- case Element:
- org.w3c.dom.NodeList elements = domNode.getChildNodes();
- int length = elements.getLength();
- int count = 0;
-
- for (int i = 0; i < length; i++) {
- org.w3c.dom.Node child = elements.item(i);
- if (domNodeNameEquals(child, namespaceURI, name))
- count++;
- }
- return count;
-
- default:
- throw new XmlException("Unknown type");
- }
- }
-
- protected org.w3c.dom.Node getDomChildAt(int type, String namespaceURI, String name, int index) {
- int length, count = 0;
-
- switch (type) {
- case Attribute:
- return domNode.getAttributes().getNamedItemNS(namespaceURI, name);
-
- case Element:
- org.w3c.dom.NodeList elements = domNode.getChildNodes();
- length = elements.getLength();
- for (int i = 0; i < length; i++) {
- org.w3c.dom.Node child = elements.item(i);
- if (domNodeNameEquals(child, namespaceURI, name) && count++ == index)
- return child;
- }
- throw new XmlException("Index out of range");
-
- default:
- throw new XmlException("Unknown type");
- }
- }
-
- protected org.w3c.dom.Node getDomChild(int type, String namespaceURI, String name) {
- return getDomChildAt(type, namespaceURI, name, 0);
- }
-
- protected org.w3c.dom.Node setDomChildAt(int type, String namespaceURI, String name, String value, int index) {
- int length, count = 0;
-
- switch (type) {
- case Attribute:
- org.w3c.dom.Attr oldAttr = ((org.w3c.dom.Element)domNode).getAttributeNodeNS(namespaceURI, name);
- ((org.w3c.dom.Element)domNode).setAttributeNS(namespaceURI, name, value);
- return oldAttr;
-
- case Element:
- org.w3c.dom.NodeList elements = domNode.getChildNodes();
- length = elements.getLength();
- for (int i = 0; i < length; i++) {
- org.w3c.dom.Node child = elements.item(i);
- if (domNodeNameEquals(child, namespaceURI, name) && count++ == index) {
- child.setNodeValue(value);
- return child;
- }
- }
- throw new XmlException("Index out of range");
-
- default:
- throw new XmlException("Unknown type");
- }
- }
-
- protected org.w3c.dom.Node setDomChild(int type, String namespaceURI, String name, String value) {
- if (type == Attribute || getDomChildCount(type, namespaceURI, name) > 0) {
- return setDomChildAt(type, namespaceURI, name, value, 0);
- } else {
- appendDomChild(type, namespaceURI, name, value);
- return null;
- }
- }
-
- protected org.w3c.dom.Node removeDomChildAt(int type, String namespaceURI, String name, int index) {
- int length, count = 0;
-
- switch (type) {
- case Attribute:
- return domNode.getAttributes().removeNamedItemNS(namespaceURI, name);
-
- case Element:
- org.w3c.dom.NodeList elements = domNode.getChildNodes();
- length = elements.getLength();
- for (int i = 0; i < length; i++) {
- org.w3c.dom.Node child = elements.item(i);
- if (domNodeNameEquals(child, namespaceURI, name) && count++ == index)
- return domNode.removeChild(child);
- }
- throw new XmlException("Index out of range");
-
- default:
- throw new XmlException("Unknown type");
- }
- }
-
- protected void cloneDomElement(String namespaceURI, String name, com.altova.xml.Node srcNode) {
- org.w3c.dom.Element newDomNode = domNode.getOwnerDocument().createElementNS(namespaceURI, name);
- org.w3c.dom.Element srcDomNode = (org.w3c.dom.Element)srcNode.domNode;
-
- while (srcDomNode.getFirstChild() != null) {
- org.w3c.dom.Node n = newDomNode.getOwnerDocument().importNode(srcDomNode.getFirstChild(), true);
- newDomNode.appendChild(n);
- srcDomNode.removeChild(srcDomNode.getFirstChild());
- }
-
- org.w3c.dom.NamedNodeMap srcAttributes = srcNode.domNode.getAttributes();
- org.w3c.dom.NamedNodeMap newAttributes = newDomNode.getAttributes();
-
- while (srcAttributes.getLength() > 0)
- newAttributes.setNamedItem(srcAttributes.removeNamedItem(srcAttributes.item(0).getNodeName()));
-
- srcNode.domNode = newDomNode;
- domNode.appendChild(newDomNode);
- }
-
- protected void cloneInto(org.w3c.dom.Element newDomNode) {
- while (domNode.getFirstChild() != null) {
- org.w3c.dom.Node n = newDomNode.getOwnerDocument().importNode(domNode.getFirstChild(), true);
- newDomNode.appendChild(n);
- domNode.removeChild(domNode.getFirstChild());
- }
-
- org.w3c.dom.NamedNodeMap srcAttributes = ((org.w3c.dom.Element)domNode).getAttributes();
- org.w3c.dom.NamedNodeMap newAttributes = newDomNode.getAttributes();
- while (srcAttributes.getLength() > 0)
- newAttributes.setNamedItem(srcAttributes.removeNamedItem(srcAttributes.item(0).getNodeName()));
-
- domNode = newDomNode;
- }
- }[
- close
- create $outputpath & "/com/altova/xml/XmlException.java"
- ]/**
- * XmlException.java
- *
- * Copyright (C) 2002 Altova GmbH - The XML Spy Company
- * All rights reserved.
- *
- * Refer to the XML Spy Documentation for further details.
- * http://www.xmlspy.com
- */
-
-
- package com.altova.xml;
-
-
- public class XmlException extends RuntimeException {
- protected java.lang.Exception innerException;
- protected String message;
-
- public XmlException(String text) {
- innerException = null;
- message = text;
- }
-
- public XmlException(java.lang.Exception other) {
- innerException = other;
- message = other.getMessage();
- }
-
- public String getMessage() {
- return message;
- }
-
- public java.lang.Exception getInnerException() {
- return innerException;
- }
- }
- [
- close
- '-----END ALTOVA XML CLASSES-----
- create $outputpath & "/Build" & $module & ".xml"
- ]<project name="[=$module]" default="test" basedir=".">
- <target name="compile">
- <javac srcdir="com/altova/xml" destdir="."/>
- <javac srcdir="[=$JavaPackageDir]" destdir="."/>
- </target>
- <target name="test" depends="compile">
- <java classname="[=$JavaPackageName].[=$module]Test" fork="true" failonerror="true"/>
- </target>
- <target name="clean">
- <delete>
- <fileset dir=".">
- <include name="**/*.class"/>
- </fileset>
- </delete>
- </target>
- </project>
- [close]