First Commit from Source Code Reply

This commit is contained in:
vincenzofariello
2024-05-09 17:40:24 +02:00
parent 11e3b57c5b
commit 107a016cb9
35225 changed files with 1111346 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
Sample: Any
Author: Steven Traut (straut@bea.com)
Last Updated: June 14, 2005
Versions:
xmlbeans-v1 1.0.3
xmlbeans-v2
-----------------------------------------------------------------------------
This sample illustrates how you can use the XMLBeans API to work with
XML based on schema that features xs:any particles. Unlike other schema
types, xs:any in schema does not result in accessors when you use XMLBeans
to compile schema. Instead, your code must use alternate means to access
and create these parts of the XML. These alternate means include:
- Using XmlCursor instances to "walk" the XML, retrieving and creating
elements.
- Using the selectPath method to retrieve XML via XPath.
- Using the selectChildren method to retrieve elements that are children
by name.
- Using the DOM API to "walk" the node tree, retrieving elements by
name and creating new elements.
When you run this sample, you'll see it print four blocks of information
in the console:
- Results of the Any.buildDocFromScratch method, which builds from scratch the
XML contents of any.xml included with this sample.
- Results of the Any.editExistingDocWithSelectChildren method, which receives
any.xml and replaces one of its elements.
- Results of the Any.editExistingDocWithDOM method, which receives
any.xml and adds an element.
- Results of the Any.editExistingDocWithSelectPath method, which receives
any.xml, promotes one of its elements, and adds a new element.
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. To compile the schemas and sample source, run "ant build"
4. To execute the sample, run "ant run"

View File

@@ -0,0 +1,120 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="Any" default="build">
<property environment="env"/>
<path id="Any.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="*.jar"/>
<pathelement path="build/classes"/>
</path>
<target name="init">
<property name="xmlbeans.home" value="${env.XMLBEANS_HOME}"/>
<echo message="xmlbeans.home: ${xmlbeans.home}"/>
<!-- check for xbean.jar from binary distribution -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/lib"
file="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/build/lib"
file="${xmlbeans.home}/build/lib/xbean.jar" />
<fail message="Set XMLBEANS_HOME in your environment."
unless="xmlbeans.lib"/>
<echo message="xmlbeans.lib: ${xmlbeans.lib}"/>
<path id="xmlbeans.path">
<fileset dir="${xmlbeans.lib}" includes="*.jar"/>
</path>
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpathref="xmlbeans.path"/>
</target>
<!-- ========================== clean ==== -->
<target name="clean">
<delete dir="build"/>
</target>
<!-- ========================== build ==== -->
<target name="build" depends="init,schemas.jar,Any.classes">
</target>
<target name="schemas.check">
<uptodate property="schemas.notRequired"
targetfile="build/lib/schemas.jar">
<srcfiles dir="schemas" includes="**/*.xsd"/>
</uptodate>
</target>
<target name="schemas.jar" depends="init,schemas.check"
unless="schemas.notRequired">
<mkdir dir="build/lib"/>
<xmlbean schema="schemas"
destfile="build/lib/schemas.jar"
srcgendir="src"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="Any.classes" depends="init">
<mkdir dir="build/classes"/>
<javac srcdir="src"
destdir="build/classes"
classpathref="Any.path"
debug="on"
source="1.4"
/>
</target>
<!-- ========================== run ==== -->
<target name="run" depends="init,build">
<echo message="============================== running Any"/>
<java
classname="org.apache.xmlbeans.samples.anytype.Any"
classpathref="Any.path"
fork="true">
<arg line="xml/any.xml"/>
</java>
</target>
<!-- ========================== test ==== -->
<target name="test" depends="init,build">
<echo message="============================== testing Any"/>
<java
classname="org.apache.xmlbeans.samples.anytype.AnyTest"
classpathref="Any.path"
fork="true">
<arg line="xml/any.xml"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://xmlbeans.apache.org/samples/any"
targetNamespace="http://xmlbeans.apache.org/samples/any" elementFormDefault="qualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="stringelement"/>
<xs:any processContents="lax"/>
<xs:element name="arrayofany">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="stringelement" type="xs:string"/>
<xs:complexType name="ListOfStrings">
<xs:sequence>
<xs:element ref="stringelement" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
</xs:schema>

View File

@@ -0,0 +1,195 @@
/*
* XML Type: ListOfStrings
* Namespace: http://xmlbeans.apache.org/samples/any
* Java type: org.apache.xmlbeans.samples.any.ListOfStrings
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.any;
/**
* An XML ListOfStrings(@http://xmlbeans.apache.org/samples/any).
*
* This is a complex type.
*/
public interface ListOfStrings extends org.apache.xmlbeans.XmlObject
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s6EF7A0057B3F4CED74AE6E05BCAAB5DB.TypeSystemHolder.typeSystem.resolveHandle("listofstringse467type");
/**
* Gets array of all "stringelement" elements
*/
java.lang.String[] getStringelementArray();
/**
* Gets ith "stringelement" element
*/
java.lang.String getStringelementArray(int i);
/**
* Gets (as xml) array of all "stringelement" elements
*/
org.apache.xmlbeans.XmlString[] xgetStringelementArray();
/**
* Gets (as xml) ith "stringelement" element
*/
org.apache.xmlbeans.XmlString xgetStringelementArray(int i);
/**
* Returns number of "stringelement" element
*/
int sizeOfStringelementArray();
/**
* Sets array of all "stringelement" element
*/
void setStringelementArray(java.lang.String[] stringelementArray);
/**
* Sets ith "stringelement" element
*/
void setStringelementArray(int i, java.lang.String stringelement);
/**
* Sets (as xml) array of all "stringelement" element
*/
void xsetStringelementArray(org.apache.xmlbeans.XmlString[] stringelementArray);
/**
* Sets (as xml) ith "stringelement" element
*/
void xsetStringelementArray(int i, org.apache.xmlbeans.XmlString stringelement);
/**
* Inserts the value as the ith "stringelement" element
*/
void insertStringelement(int i, java.lang.String stringelement);
/**
* Appends the value as the last "stringelement" element
*/
void addStringelement(java.lang.String stringelement);
/**
* Inserts and returns a new empty value (as xml) as the ith "stringelement" element
*/
org.apache.xmlbeans.XmlString insertNewStringelement(int i);
/**
* Appends and returns a new empty value (as xml) as the last "stringelement" element
*/
org.apache.xmlbeans.XmlString addNewStringelement();
/**
* Removes the ith "stringelement" element
*/
void removeStringelement(int i);
/**
* Gets the "id" attribute
*/
java.lang.String getId();
/**
* Gets (as xml) the "id" attribute
*/
org.apache.xmlbeans.XmlString xgetId();
/**
* True if has "id" attribute
*/
boolean isSetId();
/**
* Sets the "id" attribute
*/
void setId(java.lang.String id);
/**
* Sets (as xml) the "id" attribute
*/
void xsetId(org.apache.xmlbeans.XmlString id);
/**
* Unsets the "id" attribute
*/
void unsetId();
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.any.ListOfStrings newInstance() {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
/** @param xmlAsString the string value to parse */
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.lang.String xmlAsString, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, options ); }
/** @param file the file from which to load an xml document */
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.io.File file) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, null ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.io.File file, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, options ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.net.URL u) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, null ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.net.URL u, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, options ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.io.InputStream is) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.io.InputStream is, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, options ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.io.Reader r) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, null ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(java.io.Reader r, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, options ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(javax.xml.stream.XMLStreamReader sr) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, null ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(javax.xml.stream.XMLStreamReader sr, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, options ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(org.w3c.dom.Node node) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, null ); }
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(org.w3c.dom.Node node, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.any.ListOfStrings parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.any.ListOfStrings) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, options ); }
private Factory() { } // No instance of this class allowed
}
}

View File

@@ -0,0 +1,198 @@
/*
* An XML document type.
* Localname: root
* Namespace: http://xmlbeans.apache.org/samples/any
* Java type: org.apache.xmlbeans.samples.any.RootDocument
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.any;
/**
* A document containing one root(@http://xmlbeans.apache.org/samples/any) element.
*
* This is a complex type.
*/
public interface RootDocument extends org.apache.xmlbeans.XmlObject
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s6EF7A0057B3F4CED74AE6E05BCAAB5DB.TypeSystemHolder.typeSystem.resolveHandle("root9970doctype");
/**
* Gets the "root" element
*/
org.apache.xmlbeans.samples.any.RootDocument.Root getRoot();
/**
* Sets the "root" element
*/
void setRoot(org.apache.xmlbeans.samples.any.RootDocument.Root root);
/**
* Appends and returns a new empty "root" element
*/
org.apache.xmlbeans.samples.any.RootDocument.Root addNewRoot();
/**
* An XML root(@http://xmlbeans.apache.org/samples/any).
*
* This is a complex type.
*/
public interface Root extends org.apache.xmlbeans.XmlObject
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s6EF7A0057B3F4CED74AE6E05BCAAB5DB.TypeSystemHolder.typeSystem.resolveHandle("root2a6eelemtype");
/**
* Gets the "stringelement" element
*/
java.lang.String getStringelement();
/**
* Gets (as xml) the "stringelement" element
*/
org.apache.xmlbeans.XmlString xgetStringelement();
/**
* Sets the "stringelement" element
*/
void setStringelement(java.lang.String stringelement);
/**
* Sets (as xml) the "stringelement" element
*/
void xsetStringelement(org.apache.xmlbeans.XmlString stringelement);
/**
* Gets the "arrayofany" element
*/
org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany getArrayofany();
/**
* Sets the "arrayofany" element
*/
void setArrayofany(org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany arrayofany);
/**
* Appends and returns a new empty "arrayofany" element
*/
org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany addNewArrayofany();
/**
* An XML arrayofany(@http://xmlbeans.apache.org/samples/any).
*
* This is a complex type.
*/
public interface Arrayofany extends org.apache.xmlbeans.XmlObject
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s6EF7A0057B3F4CED74AE6E05BCAAB5DB.TypeSystemHolder.typeSystem.resolveHandle("arrayofany08d6elemtype");
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany newInstance() {
return (org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
private Factory() { } // No instance of this class allowed
}
}
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.any.RootDocument.Root newInstance() {
return (org.apache.xmlbeans.samples.any.RootDocument.Root) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument.Root newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.any.RootDocument.Root) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
private Factory() { } // No instance of this class allowed
}
}
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.any.RootDocument newInstance() {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
/** @param xmlAsString the string value to parse */
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.lang.String xmlAsString, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, options ); }
/** @param file the file from which to load an xml document */
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.io.File file) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.io.File file, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, options ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.net.URL u) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.net.URL u, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, options ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.io.InputStream is) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.io.InputStream is, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, options ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.io.Reader r) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(java.io.Reader r, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, options ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(javax.xml.stream.XMLStreamReader sr) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(javax.xml.stream.XMLStreamReader sr, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, options ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(org.w3c.dom.Node node) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, null ); }
public static org.apache.xmlbeans.samples.any.RootDocument parse(org.w3c.dom.Node node, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.any.RootDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.any.RootDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.any.RootDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, options ); }
private Factory() { } // No instance of this class allowed
}
}

View File

@@ -0,0 +1,116 @@
/*
* An XML document type.
* Localname: stringelement
* Namespace: http://xmlbeans.apache.org/samples/any
* Java type: org.apache.xmlbeans.samples.any.StringelementDocument
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.any;
/**
* A document containing one stringelement(@http://xmlbeans.apache.org/samples/any) element.
*
* This is a complex type.
*/
public interface StringelementDocument extends org.apache.xmlbeans.XmlObject
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s6EF7A0057B3F4CED74AE6E05BCAAB5DB.TypeSystemHolder.typeSystem.resolveHandle("stringelementc479doctype");
/**
* Gets the "stringelement" element
*/
java.lang.String getStringelement();
/**
* Gets (as xml) the "stringelement" element
*/
org.apache.xmlbeans.XmlString xgetStringelement();
/**
* Sets the "stringelement" element
*/
void setStringelement(java.lang.String stringelement);
/**
* Sets (as xml) the "stringelement" element
*/
void xsetStringelement(org.apache.xmlbeans.XmlString stringelement);
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.any.StringelementDocument newInstance() {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
/** @param xmlAsString the string value to parse */
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.lang.String xmlAsString, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, options ); }
/** @param file the file from which to load an xml document */
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.io.File file) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, null ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.io.File file, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, options ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.net.URL u) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, null ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.net.URL u, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, options ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.io.InputStream is) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.io.InputStream is, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, options ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.io.Reader r) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, null ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(java.io.Reader r, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, options ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(javax.xml.stream.XMLStreamReader sr) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, null ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(javax.xml.stream.XMLStreamReader sr, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, options ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(org.w3c.dom.Node node) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, null ); }
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(org.w3c.dom.Node node, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.any.StringelementDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.any.StringelementDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, options ); }
private Factory() { } // No instance of this class allowed
}
}

View File

@@ -0,0 +1,328 @@
/*
* XML Type: ListOfStrings
* Namespace: http://xmlbeans.apache.org/samples/any
* Java type: org.apache.xmlbeans.samples.any.ListOfStrings
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.any.impl;
/**
* An XML ListOfStrings(@http://xmlbeans.apache.org/samples/any).
*
* This is a complex type.
*/
public class ListOfStringsImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.apache.xmlbeans.samples.any.ListOfStrings
{
public ListOfStringsImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName STRINGELEMENT$0 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/any", "stringelement");
private static final javax.xml.namespace.QName ID$2 =
new javax.xml.namespace.QName("", "id");
/**
* Gets array of all "stringelement" elements
*/
public java.lang.String[] getStringelementArray()
{
synchronized (monitor())
{
check_orphaned();
java.util.List targetList = new java.util.ArrayList();
get_store().find_all_element_users(STRINGELEMENT$0, targetList);
java.lang.String[] result = new java.lang.String[targetList.size()];
for (int i = 0, len = targetList.size() ; i < len ; i++)
result[i] = ((org.apache.xmlbeans.SimpleValue)targetList.get(i)).getStringValue();
return result;
}
}
/**
* Gets ith "stringelement" element
*/
public java.lang.String getStringelementArray(int i)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(STRINGELEMENT$0, i);
if (target == null)
{
throw new IndexOutOfBoundsException();
}
return target.getStringValue();
}
}
/**
* Gets (as xml) array of all "stringelement" elements
*/
public org.apache.xmlbeans.XmlString[] xgetStringelementArray()
{
synchronized (monitor())
{
check_orphaned();
java.util.List targetList = new java.util.ArrayList();
get_store().find_all_element_users(STRINGELEMENT$0, targetList);
org.apache.xmlbeans.XmlString[] result = new org.apache.xmlbeans.XmlString[targetList.size()];
targetList.toArray(result);
return result;
}
}
/**
* Gets (as xml) ith "stringelement" element
*/
public org.apache.xmlbeans.XmlString xgetStringelementArray(int i)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(STRINGELEMENT$0, i);
if (target == null)
{
throw new IndexOutOfBoundsException();
}
return (org.apache.xmlbeans.XmlString)target;
}
}
/**
* Returns number of "stringelement" element
*/
public int sizeOfStringelementArray()
{
synchronized (monitor())
{
check_orphaned();
return get_store().count_elements(STRINGELEMENT$0);
}
}
/**
* Sets array of all "stringelement" element
*/
public void setStringelementArray(java.lang.String[] stringelementArray)
{
synchronized (monitor())
{
check_orphaned();
arraySetterHelper(stringelementArray, STRINGELEMENT$0);
}
}
/**
* Sets ith "stringelement" element
*/
public void setStringelementArray(int i, java.lang.String stringelement)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(STRINGELEMENT$0, i);
if (target == null)
{
throw new IndexOutOfBoundsException();
}
target.setStringValue(stringelement);
}
}
/**
* Sets (as xml) array of all "stringelement" element
*/
public void xsetStringelementArray(org.apache.xmlbeans.XmlString[]stringelementArray)
{
synchronized (monitor())
{
check_orphaned();
arraySetterHelper(stringelementArray, STRINGELEMENT$0);
}
}
/**
* Sets (as xml) ith "stringelement" element
*/
public void xsetStringelementArray(int i, org.apache.xmlbeans.XmlString stringelement)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(STRINGELEMENT$0, i);
if (target == null)
{
throw new IndexOutOfBoundsException();
}
target.set(stringelement);
}
}
/**
* Inserts the value as the ith "stringelement" element
*/
public void insertStringelement(int i, java.lang.String stringelement)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target =
(org.apache.xmlbeans.SimpleValue)get_store().insert_element_user(STRINGELEMENT$0, i);
target.setStringValue(stringelement);
}
}
/**
* Appends the value as the last "stringelement" element
*/
public void addStringelement(java.lang.String stringelement)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().add_element_user(STRINGELEMENT$0);
target.setStringValue(stringelement);
}
}
/**
* Inserts and returns a new empty value (as xml) as the ith "stringelement" element
*/
public org.apache.xmlbeans.XmlString insertNewStringelement(int i)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().insert_element_user(STRINGELEMENT$0, i);
return target;
}
}
/**
* Appends and returns a new empty value (as xml) as the last "stringelement" element
*/
public org.apache.xmlbeans.XmlString addNewStringelement()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().add_element_user(STRINGELEMENT$0);
return target;
}
}
/**
* Removes the ith "stringelement" element
*/
public void removeStringelement(int i)
{
synchronized (monitor())
{
check_orphaned();
get_store().remove_element(STRINGELEMENT$0, i);
}
}
/**
* Gets the "id" attribute
*/
public java.lang.String getId()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_attribute_user(ID$2);
if (target == null)
{
return null;
}
return target.getStringValue();
}
}
/**
* Gets (as xml) the "id" attribute
*/
public org.apache.xmlbeans.XmlString xgetId()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_attribute_user(ID$2);
return target;
}
}
/**
* True if has "id" attribute
*/
public boolean isSetId()
{
synchronized (monitor())
{
check_orphaned();
return get_store().find_attribute_user(ID$2) != null;
}
}
/**
* Sets the "id" attribute
*/
public void setId(java.lang.String id)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_attribute_user(ID$2);
if (target == null)
{
target = (org.apache.xmlbeans.SimpleValue)get_store().add_attribute_user(ID$2);
}
target.setStringValue(id);
}
}
/**
* Sets (as xml) the "id" attribute
*/
public void xsetId(org.apache.xmlbeans.XmlString id)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_attribute_user(ID$2);
if (target == null)
{
target = (org.apache.xmlbeans.XmlString)get_store().add_attribute_user(ID$2);
}
target.set(id);
}
}
/**
* Unsets the "id" attribute
*/
public void unsetId()
{
synchronized (monitor())
{
check_orphaned();
get_store().remove_attribute(ID$2);
}
}
}

View File

@@ -0,0 +1,228 @@
/*
* An XML document type.
* Localname: root
* Namespace: http://xmlbeans.apache.org/samples/any
* Java type: org.apache.xmlbeans.samples.any.RootDocument
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.any.impl;
/**
* A document containing one root(@http://xmlbeans.apache.org/samples/any) element.
*
* This is a complex type.
*/
public class RootDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.apache.xmlbeans.samples.any.RootDocument
{
public RootDocumentImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName ROOT$0 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/any", "root");
/**
* Gets the "root" element
*/
public org.apache.xmlbeans.samples.any.RootDocument.Root getRoot()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.any.RootDocument.Root target = null;
target = (org.apache.xmlbeans.samples.any.RootDocument.Root)get_store().find_element_user(ROOT$0, 0);
if (target == null)
{
return null;
}
return target;
}
}
/**
* Sets the "root" element
*/
public void setRoot(org.apache.xmlbeans.samples.any.RootDocument.Root root)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.any.RootDocument.Root target = null;
target = (org.apache.xmlbeans.samples.any.RootDocument.Root)get_store().find_element_user(ROOT$0, 0);
if (target == null)
{
target = (org.apache.xmlbeans.samples.any.RootDocument.Root)get_store().add_element_user(ROOT$0);
}
target.set(root);
}
}
/**
* Appends and returns a new empty "root" element
*/
public org.apache.xmlbeans.samples.any.RootDocument.Root addNewRoot()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.any.RootDocument.Root target = null;
target = (org.apache.xmlbeans.samples.any.RootDocument.Root)get_store().add_element_user(ROOT$0);
return target;
}
}
/**
* An XML root(@http://xmlbeans.apache.org/samples/any).
*
* This is a complex type.
*/
public static class RootImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.apache.xmlbeans.samples.any.RootDocument.Root
{
public RootImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName STRINGELEMENT$0 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/any", "stringelement");
private static final javax.xml.namespace.QName ARRAYOFANY$2 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/any", "arrayofany");
/**
* Gets the "stringelement" element
*/
public java.lang.String getStringelement()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(STRINGELEMENT$0, 0);
if (target == null)
{
return null;
}
return target.getStringValue();
}
}
/**
* Gets (as xml) the "stringelement" element
*/
public org.apache.xmlbeans.XmlString xgetStringelement()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(STRINGELEMENT$0, 0);
return target;
}
}
/**
* Sets the "stringelement" element
*/
public void setStringelement(java.lang.String stringelement)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(STRINGELEMENT$0, 0);
if (target == null)
{
target = (org.apache.xmlbeans.SimpleValue)get_store().add_element_user(STRINGELEMENT$0);
}
target.setStringValue(stringelement);
}
}
/**
* Sets (as xml) the "stringelement" element
*/
public void xsetStringelement(org.apache.xmlbeans.XmlString stringelement)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(STRINGELEMENT$0, 0);
if (target == null)
{
target = (org.apache.xmlbeans.XmlString)get_store().add_element_user(STRINGELEMENT$0);
}
target.set(stringelement);
}
}
/**
* Gets the "arrayofany" element
*/
public org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany getArrayofany()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany target = null;
target = (org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany)get_store().find_element_user(ARRAYOFANY$2, 0);
if (target == null)
{
return null;
}
return target;
}
}
/**
* Sets the "arrayofany" element
*/
public void setArrayofany(org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany arrayofany)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany target = null;
target = (org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany)get_store().find_element_user(ARRAYOFANY$2, 0);
if (target == null)
{
target = (org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany)get_store().add_element_user(ARRAYOFANY$2);
}
target.set(arrayofany);
}
}
/**
* Appends and returns a new empty "arrayofany" element
*/
public org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany addNewArrayofany()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany target = null;
target = (org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany)get_store().add_element_user(ARRAYOFANY$2);
return target;
}
}
/**
* An XML arrayofany(@http://xmlbeans.apache.org/samples/any).
*
* This is a complex type.
*/
public static class ArrayofanyImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany
{
public ArrayofanyImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
}
}
}

View File

@@ -0,0 +1,94 @@
/*
* An XML document type.
* Localname: stringelement
* Namespace: http://xmlbeans.apache.org/samples/any
* Java type: org.apache.xmlbeans.samples.any.StringelementDocument
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.any.impl;
/**
* A document containing one stringelement(@http://xmlbeans.apache.org/samples/any) element.
*
* This is a complex type.
*/
public class StringelementDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.apache.xmlbeans.samples.any.StringelementDocument
{
public StringelementDocumentImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName STRINGELEMENT$0 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/any", "stringelement");
/**
* Gets the "stringelement" element
*/
public java.lang.String getStringelement()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(STRINGELEMENT$0, 0);
if (target == null)
{
return null;
}
return target.getStringValue();
}
}
/**
* Gets (as xml) the "stringelement" element
*/
public org.apache.xmlbeans.XmlString xgetStringelement()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(STRINGELEMENT$0, 0);
return target;
}
}
/**
* Sets the "stringelement" element
*/
public void setStringelement(java.lang.String stringelement)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(STRINGELEMENT$0, 0);
if (target == null)
{
target = (org.apache.xmlbeans.SimpleValue)get_store().add_element_user(STRINGELEMENT$0);
}
target.setStringValue(stringelement);
}
}
/**
* Sets (as xml) the "stringelement" element
*/
public void xsetStringelement(org.apache.xmlbeans.XmlString stringelement)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(STRINGELEMENT$0, 0);
if (target == null)
{
target = (org.apache.xmlbeans.XmlString)get_store().add_element_user(STRINGELEMENT$0);
}
target.set(stringelement);
}
}
}

View File

@@ -0,0 +1,457 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.anytype;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.samples.any.ListOfStrings;
import org.apache.xmlbeans.samples.any.RootDocument;
import org.apache.xmlbeans.samples.any.StringelementDocument;
import org.apache.xmlbeans.samples.any.RootDocument.Root.Arrayofany;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.namespace.QName;
/**
* A sample that illustrates various ways to manipulate XML whose
* schema defines elements as type xs:any. Unlike its treatment of
* other schema types, XMLBeans does not generate accessors for the
* xs:any particle when compiling schema. Instead, your code
* handles instances of this type through any of several alternative
* means, including XPath queries, the selectChildren method,
* XmlCursor instances and the DOM API. This samples illustrates
* these alternative approaches.
*/
public class Any
{
private static final String m_namespaceUri = "http://xmlbeans.apache.org/samples/any";
/**
* Receives <root> XML instance, executing methods that
* edit the received instance or create a new one.
*
* @param args An array in which the first item is a
* path to the XML instance file.
*/
public static void main(String[] args)
{
Any thisSample = new Any();
System.out.println("Running Any.buildDocFromScratch\n");
thisSample.buildDocFromScratch();
RootDocument rootDoc = (RootDocument)thisSample.parseXml(args[0]);
System.out.println("Running Any.editExistingDocWithSelectChildren\n");
thisSample.editExistingDocWithSelectChildren(rootDoc);
System.out.println("Running Any.editExistingDocWithDOM\n");
thisSample.editExistingDocWithDOM(rootDoc);
System.out.println("Running Any.editExistingDocWithSelectPath\n");
thisSample.editExistingDocWithSelectPath(rootDoc);
}
/**
* Creates a new <root> document from scratch.
*
* This method illustrates how you can use XmlCursor instances
* to build XML that is defined in schema as xs:any.
*
* @return <code>true</code> if the new document is valid;
* otherwise, <code>false</code>.
*/
public boolean buildDocFromScratch()
{
// Start by creating a <root> element that will contain
// the children built by this method.
RootDocument rootDoc = RootDocument.Factory.newInstance();
RootDocument.Root root = rootDoc.addNewRoot();
// Add the first element, <stringelement>.
root.setStringelement("some text");
// Create an XmlObject in which to build the second
// element in the sequence, <anyfoo>. Here, the
// XmlObject instance is simply a kind of incubator
// for the XML. Later the XML will be moved into the
// document this code is building.
XmlObject anyFoo = XmlObject.Factory.newInstance();
// Add a cursor to do the work of building the XML.
XmlCursor childCursor = anyFoo.newCursor();
childCursor.toNextToken();
// Add the element in the schema's namespace, then add
// element content.
childCursor.beginElement(new QName(m_namespaceUri, "anyfoo"));
childCursor.insertChars("some text");
// Move the cursor back to the new element's top, where
// it can grab the element's XML.
childCursor.toStartDoc();
childCursor.toNextToken();
// Move the XML into the <root> document by moving it
// from a position at one cursor to a position at
// another.
XmlCursor rootCursor = root.newCursor();
rootCursor.toEndToken();
childCursor.moveXml(rootCursor);
// Add the fourth element, <arrayofany>, by building it
// elsewhere, then moving the new XML into place under
// <root>.
Arrayofany arrayOfAny = root.addNewArrayofany();
if (buildArrayOfAny(arrayOfAny) == null)
{
return false;
}
childCursor.dispose();
rootCursor.dispose();
// Print and validate the result.
System.out.println("Output: The <root> document built from scratch.\n");
System.out.println(rootDoc + "\n");
return validateXml(rootDoc);
}
/**
* Replaces the <anyfoo> element with an <anybar> element in the
* incoming XML.
*
* This method illustrates how you can use the XmlCursor.selectChildren
* method to retrieve child elements whose type is defined as
* xs:any in schema.
*
* @param rootDoc An instance of the <root> XML document.
* @return <code>true</code> if the editing XML is valid;
* otherwise, <code>false</code>.
*/
public boolean editExistingDocWithSelectChildren(RootDocument rootDoc)
{
RootDocument.Root root = rootDoc.getRoot();
// Select the <anyfoo> children of <root>.
XmlObject[] stringElements =
root.selectChildren(new QName(m_namespaceUri, "anyfoo"));
// If the element is there, replace it with another element.
if (stringElements.length > 0)
{
XmlCursor editCursor = stringElements[0].newCursor();
editCursor.removeXml();
editCursor.beginElement(new QName(m_namespaceUri, "anybar"));
editCursor.insertChars("some other text");
editCursor.dispose();
}
System.out.println("Output: The <anyfoo> element has been replaced\n" +
"by an <anybar> element.\n");
System.out.println(rootDoc + "\n");
return validateXml(rootDoc);
}
/**
* Adds a new <bar> element between the first and second
* children of the <arrayofany> element.
*
* This method illustrates how you can use DOM methods to
* retrieve and edit elements whose type is defined as
* xs:any in schema.
*
* @param rootDoc An instance of the <root> XML document.
* @return <code>true</code> if the editing XML is valid;
* otherwise, <code>false</code>.
*/
public boolean editExistingDocWithDOM(RootDocument rootDoc)
{
RootDocument.Root root = rootDoc.getRoot();
// Get the DOM nodes for the <arrayofany> element's children.
Node arrayOfAnyNode = root.getArrayofany().getDomNode();
// You don't have get* accessors for any of the <arrayofany>
// element's children, so use DOM to identify the first
// and second elements while looping through the child list.
NodeList childList = arrayOfAnyNode.getChildNodes();
Element firstElementChild = null;
Element secondElementChild = null;
// Find the first child element and make sure it's
// <stringelement>.
for (int i = 0; i < childList.getLength(); i++)
{
Node node = childList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
if (node.getLocalName().equals("stringelement"))
{
firstElementChild = (Element)node;
break;
}
}
}
if (firstElementChild == null) {return false;}
// Find the second child element and make sure it's
// <someelement>.
Node node = firstElementChild.getNextSibling();
do {
if (node.getNodeType() == Node.ELEMENT_NODE)
{
if (node.getLocalName().equals("someelement"))
{
secondElementChild = (Element)node;
break;
}
}
node = node.getNextSibling();
} while (node != null);
if (secondElementChild == null) {return false;}
// Create and insert a new <bar> element.
Element fooElement =
secondElementChild.getOwnerDocument().createElementNS("http://openuri.org","bar");
Node valueNode =
fooElement.getOwnerDocument().createTextNode("some text");
fooElement.appendChild(valueNode);
arrayOfAnyNode.insertBefore(fooElement, secondElementChild);
System.out.println("Output: <arrayofany> has a new <bar> child element.\n");
System.out.println(rootDoc + "\n");
return validateXml(rootDoc);
}
/**
* Edits incoming <root> XML to make the following changes: replace
* <somelement> with its <stringlist> child; add a new <foo>
* element as the second child of <arrayofany>.
*
* This method illustrates how you can use the selectPath method
* to find an element defined as xs:any in schema, then use
* XmlCursor instances to edit the XML.
*
* @param rootDoc An instance of the <root> XML document.
* @return <code>true</code> if the editing XML is valid;
* otherwise, <code>false</code>.
*/
public boolean editExistingDocWithSelectPath(RootDocument rootDoc)
{
String namespaceDecl = "declare namespace any='" +
m_namespaceUri + "'; ";
XmlCursor selectionCursor = rootDoc.getRoot().getArrayofany().newCursor();
// Save the cursor's position for later, then use XPath
// and cursor movement to position the cursor at
// the <stringlist> element.
selectionCursor.push();
selectionCursor.selectPath(namespaceDecl +
"$this//any:someelement/any:stringlist");
selectionCursor.toNextSelection();
// Create a new cursor and move it to the selection
// cursor's <someelement> parent. Moving the
// <stringlist> element to this position, displacing
// the <someelement> downward, then removing the
// <someelement> XML effectively replaces <someelement>
// with <stringlist>.
XmlCursor editCursor = selectionCursor.newCursor();
editCursor.toParent();
selectionCursor.moveXml(editCursor);
editCursor.removeXml();
editCursor.dispose();
// Return the cursor to the <arrayofany> element so you
// can do more editing. Then move the cursor to the second
// child and insert a new element as second child.
selectionCursor.pop();
selectionCursor.toFirstChild();
selectionCursor.toNextSibling();
selectionCursor.beginElement("foo", "http://openuri.org");
selectionCursor.insertChars("some text");
selectionCursor.dispose();
System.out.println("Output: <stringlist> has been promoted to replace \n" +
"<someelement>, and there's a new <foo> element.\n");
System.out.println(rootDoc + "\n");
return validateXml(rootDoc);
}
/**
* Like the code in the buildDocFromScratch method, this code
* uses the XmlCursor to build XML piece by piece, building
* out the Arrayofany instance it receives.
*
* @return A valid <arrayofany> element bound to an
* Arrrayofany instance.
*/
private Arrayofany buildArrayOfAny(Arrayofany arrayOfAny)
{
// Create a simple <stringelement> and move it into place
// under <arrayofany>.
StringelementDocument stringElementDoc =
StringelementDocument.Factory.newInstance();
stringElementDoc.setStringelement("some text");
XmlCursor childCursor = stringElementDoc.newCursor();
childCursor.toFirstContentToken();
// Add a cursor to mark the position at which the new child
// XML will be moved.
XmlCursor arrayCursor = arrayOfAny.newCursor();
arrayCursor.toNextToken();
childCursor.moveXml(arrayCursor);
childCursor.dispose();
// Create a <someelement> that contains a <stringlist>
// child element, then get the XmlObject representing the new
// <stringlist>. Note that the XmlCursor.beginElement method
// leaves the cursor between START and END tokens -- where
// content can be placed.
arrayCursor.beginElement("someelement", m_namespaceUri);
arrayCursor.beginElement("stringlist", m_namespaceUri);
arrayCursor.toPrevToken();
XmlObject stringList = arrayCursor.getObject();
// The cursor's no longer needed.
arrayCursor.dispose();
// Create the <stringlist> element's value and set it.
ListOfStrings stringListValue = buildListOfStrings();
if (stringListValue == null)
{
return null;
}
stringList.set(stringListValue);
// Validate the new XML.
if (!validateXml(arrayOfAny))
{
return null;
}
return arrayOfAny;
}
/**
* Creates an instance of the ListOfStrings complex type defined
* in the schema. The instance returned by this method can be
* inserted using either a set* operation or a cursor, as in
* {@link #buildArrayOfAny()}.
*
* @return A valid instance of ListOfStrings.
*/
private ListOfStrings buildListOfStrings()
{
// Create an instance of the ListOfStrings complex type.
ListOfStrings stringList = ListOfStrings.Factory.newInstance();
stringList.setId("001");
// Add two children for the instance's root.
XmlString stringElement = stringList.addNewStringelement();
stringElement.setStringValue("string1");
stringElement = stringList.addNewStringelement();
stringElement.setStringValue("string2");
// Validate the new XML.
if (!validateXml(stringList))
{
return null;
}
return stringList;
}
/**
* <p>Validates the XML, printing error messages when the XML is invalid. Note
* that this method will properly validate any instance of a compiled schema
* type because all of these types extend XmlObject.</p>
*
* <p>Note that in actual practice, you'll probably want to use an assertion
* when validating if you want to ensure that your code doesn't pass along
* invalid XML. This sample prints the generated XML whether or not it's
* valid so that you can see the result in both cases.</p>
*
* @param xml The XML to validate.
* @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
*/
public static boolean validateXml(XmlObject xml)
{
boolean isXmlValid = false;
// A collection instance to hold validation error messages.
ArrayList validationMessages = new ArrayList();
// Validate the XML, collecting messages.
isXmlValid = xml.validate(
new XmlOptions().setErrorListener(validationMessages));
// If the XML isn't valid, print the messages.
if (!isXmlValid)
{
printErrors(validationMessages);
}
return isXmlValid;
}
/**
* Receives the collection containing errors found during
* validation and print the errors to the console.
*
* @param validationErrors The validation errors.
*/
public static void printErrors(ArrayList validationErrors)
{
Iterator iter = validationErrors.iterator();
while (iter.hasNext())
{
System.out.println(">> " + iter.next() + "\n");
}
}
/**
* <p>Creates a File from the XML path provided in main arguments, then
* parses the file's contents into a type generated from schema.</p>
* <p/>
* <p>Note that this work might have been done in main. Isolating it here
* makes the code separately available from outside this class.</p>
*
* @param xmlFilePath A path to XML based on the schema in inventory.xsd.
* @return An instance of a generated schema type that contains the parsed
* XML.
*/
public XmlObject parseXml(String xmlFilePath)
{
File xmlFile = new File(xmlFilePath);
XmlObject xml = null;
try
{
xml = XmlObject.Factory.parse(xmlFile);
} catch (XmlException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return xml;
}
}

View File

@@ -0,0 +1,45 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.anytype;
import org.apache.xmlbeans.samples.any.RootDocument;
/**
* A class with which to test the Any sample.
*/
public class AnyTest
{
/**
* Tests the Any sample.
*/
public static void main(String[] args)
{
Any sample = new Any();
boolean newDocIsValid = sample.buildDocFromScratch();
// assert !newDocIsValid;
RootDocument rootDoc = (RootDocument)sample.parseXml(args[0]);
boolean domEditsAreValid = sample.editExistingDocWithDOM(rootDoc);
// assert !domEditsAreValid;
boolean selectPathEditsAreValid = sample.editExistingDocWithSelectPath(rootDoc);
// assert !selectPathEditsAreValid;
boolean selectChildrenEditsAreValid = sample.editExistingDocWithSelectChildren(rootDoc);
// assert !selectChildrenEditsAreValid;
}
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.-->
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlbeans.apache.org/samples/any">
<stringelement>some text</stringelement>
<anyfoo>some text</anyfoo>
<arrayofany>
<stringelement>some text</stringelement>
<someelement>
<stringlist id="001">
<stringelement>string1</stringelement>
<stringelement>string2</stringelement>
</stringlist>
</someelement>
</arrayofany>
</root>

View File

@@ -0,0 +1,47 @@
Sample: DateTime
Author: Rashmi Banthia (rjain29@gmail.com)
Last Updated: Oct. 11, 2004
Versions:
xmlbeans-1.0.3
-----------------------------------------------------------------------------
This sample demonstrates how you can work with XML Schema primitive types date,
dateTime, time, duration, gDay.
This sample illustrates how you can
(1) Convert org.apache.xmlbeans.XmlDate to java.util.Calendar,org.apache.xmlbeans.GDate, java.util.Date
(2) Convert org.apache.xmlbeans.XmlTime to java.util.Calendar,org.apache.xmlbeans.GDate, java.util.Date
(3) Convert org.apache.xmlbeans.XmlDuration to org.apache.xmlbeans.GDuration
(4) Convert org.apache.xmlbeans.XmlGday to java.util.Calendar,org.apache.xmlbeans.GDate, Day - primitive java int
(5) Get/Set XML Schema primitive types date, dateTime, time, duration, and gDay.
XMLBean Types provide mapping between natural Java classes and W3C Schema types.
For eg:
Schema Type Formal Class Natural Java Class
xs:date XmlDate java.util.Calendar (XmlCalendar)
xs:duration XmlDuration org.apache.xmlbeans.GDuration
xs:dateTime XmlDateTime java.util.Calendar (XmlCalendar)
xs:time XmlTime java.util.Calendar (XmlCalendar)
The XmlCalendar is a subclass of GregorianCalendar that modifies several key
details in the behavior of GregorianCalendar to make it more useful when
dealing with XML dates.
When you run this sample:
(1) It will print element values using different formats ie. Calendar, Date, GDate. Please
note it prints only first occurence of element's value for the purpose of simplicity.
(2) It will create a new <important-date> element and saves the same in a XML Document.
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. To compile the schemas and sample source, run "ant build"
4. To execute the sample, run "ant run"

View File

@@ -0,0 +1,121 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="DateTime" default="build">
<property environment="env"/>
<path id="DateTime.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="*.jar"/>
<pathelement path="build/classes"/>
</path>
<target name="init">
<property name="xmlbeans.home" value="${env.XMLBEANS_HOME}"/>
<echo message="xmlbeans.home: ${xmlbeans.home}"/>
<!-- check for xbean.jar from binary distribution -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/lib"
file="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/build/lib"
file="${xmlbeans.home}/build/lib/xbean.jar" />
<fail message="Set XMLBEANS_HOME in your enviornment."
unless="xmlbeans.lib"/>
<echo message="xmlbeans.lib: ${xmlbeans.lib}"/>
<path id="xmlbeans.path">
<fileset dir="${xmlbeans.lib}" includes="*.jar"/>
</path>
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpathref="xmlbeans.path"/>
</target>
<!-- ========================== clean ==== -->
<target name="clean">
<delete dir="build"/>
</target>
<!-- ========================== build ==== -->
<target name="build" depends="init,schemas.jar,DateTime.classes">
</target>
<target name="schemas.check">
<uptodate property="schemas.notRequired"
targetfile="build/lib/schemas.jar">
<srcfiles dir="schemas" includes="**/*.xsd"/>
</uptodate>
</target>
<target name="schemas.jar" depends="init,schemas.check"
unless="schemas.notRequired">
<mkdir dir="build/lib"/>
<xmlbean schema="schemas"
destfile="build/lib/schemas.jar"
srcgendir="build/src"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="DateTime.classes" depends="init">
<mkdir dir="build/classes"/>
<javac srcdir="src"
destdir="build/classes"
classpathref="DateTime.path"
debug="on"
source="1.4"
/>
</target>
<!-- ========================== run ==== -->
<target name="run" depends="init,build">
<echo message="============================== running DateTime"/>
<java
classname="org.apache.xmlbeans.samples.datetime.DateTime"
classpathref="DateTime.path"
fork="true">
<arg line="xml/datetimesample.xml xml/newdatetimesample.xml"/>
</java>
</target>
<!-- ========================== test ==== -->
<target name="test" depends="init,build">
<echo message="============================== testing DateTime"/>
<java
classname="org.apache.xmlbeans.samples.datetime.DateTimeTest"
classpathref="DateTime.path"
fork="true">
<arg line="xml/datetimesample.xml xml/newdatetimesample.xml"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,42 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema targetNamespace="http://xmlbeans.apache.org/samples/datetime"
xmlns:xs = "http://www.w3.org/2001/XMLSchema"
xmlns:dt = "http://xmlbeans.apache.org/samples/datetime"
elementFormDefault="qualified" >
<xs:element name="datetime">
<xs:complexType>
<xs:sequence>
<xs:element name="important-date" type="dt:important-date" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="important-date" >
<xs:sequence>
<xs:element name="holiday" type="xs:date" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="fun-begin-time" type="xs:time" minOccurs="1" maxOccurs="1" />
<xs:element name="fun-end-time" type="xs:time" minOccurs="1" maxOccurs="1" />
<xs:element name="job-duration" type="xs:duration" minOccurs="1" maxOccurs="1" />
<xs:element name="birthdatetime" type="xs:dateTime" minOccurs="1" maxOccurs="1" />
<xs:element name="payday" type="xs:gDay" minOccurs="1" maxOccurs="1" />
<xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>

View File

@@ -0,0 +1,308 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.datetime;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.ArrayList;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
import org.apache.xmlbeans.XmlError;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.GDuration;
import org.apache.xmlbeans.XmlDate;
import org.apache.xmlbeans.XmlCalendar;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.xmlbeans.samples.datetime.ImportantDate;
import org.apache.xmlbeans.samples.datetime.DatetimeDocument;
/**
* The sample illustrates how you can work with XML Schema types date,
* dateTime, time, duration, gDay.
* It parses the XML Document, prints first occurence of <important-date>
* value, creates a new <important-date> element and saves it in a new XML Document.
* This sample illustrates how you can convert XMLBean types to Java types
* (java.util.Date, java.util.Calendar).
* It uses the schema defined in datetime.xsd.
*/
public class DateTime {
/**
* Receives an XML Instance and prints the element values,
* Also creates a new XML Instance.
*
* @param args An array containing
* (a)Path to the XML Instance conforming to the XML schema in datetime.xsd.
* (b)Path for creating a new XML Instance.
*/
public static void main(String args[]){
// Create an instance of this class to work with.
DateTime dt = new DateTime();
// Create an instance of a Datetime type based on the received XML's schema
DatetimeDocument doc = dt.parseXml(args[0]);
// Prints the element values from the XML
dt.printInstance(doc);
// Creates a new XML and saves the file
dt.createDocument(doc,args[1]);
}
/**
* Creates a File from the XML path provided in main arguments, then
* parses the file's contents into a type generated from schema.
*/
public DatetimeDocument parseXml(String file){
// Get the XML instance into a file using the path provided.
File xmlfile = new File(file);
// Create an instance of a type generated from schema to hold the XML.
DatetimeDocument doc = null;
try {
// Parse the instance into the type generated from the schema.
doc = DatetimeDocument.Factory.parse(xmlfile);
}
catch(XmlException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
return doc;
}
/**
* This method prints first occurence of <important-date>
* value. It also prints converted values from XMLBean types to Java types
* (java.util.Date, java.util.Calendar) and org.apache.xmlbeans.GDate.
*/
public void printInstance(DatetimeDocument doc){
// Retrieve the <datetime> element and get an array of
// the <important-date> elements it contains.
DatetimeDocument.Datetime dtelement = doc.getDatetime();
ImportantDate[] impdate = dtelement.getImportantDateArray();
// Loop through the <important-date> elements, printing the
// values for each.
for (int i=0;i<impdate.length;i++){
//For purpose of simplicity in output, only first occurrence is printed.
if (i==0){
//Retrieving all <holiday> elements within <important-date> element
XmlDate[] holiday = impdate[i].xgetHolidayArray();
System.out.println("Holiday(xs:date): ");
for (int j=0;j<holiday.length;j++){
if (j==0){
//XmlDate to java.util.Calendar,org.apache.xmlbeans.GDate, java.util.Date
System.out.println("Calendar:" + holiday[j].getCalendarValue() );
System.out.println("Date:"+holiday[j].getDateValue() );
System.out.println("GDate:"+holiday[j].getGDateValue() +"\n");
}
}
//XmlTime to java.util.Calendar, org.apache.xmlbeans.GDate, java.util.Date
System.out.println("Fun Begin Time(xs:time): ");
System.out.println("Calendar:"+impdate[i].getFunBeginTime());
System.out.println("GDate:"+impdate[i].xgetFunBeginTime().getGDateValue() );
//To convert java.util.Calendar to java.util.Date
SimpleDateFormat sdf = new SimpleDateFormat("H:mm:ss");
Date dt = impdate[i].getFunBeginTime().getTime();
System.out.println("Date:"+ sdf.format(dt) +"\n" );
//XmlDuration to org.apache.xmlbeans.GDuration
System.out.println("Job Duration(xs:duration): ");
System.out.println("GDuration:"+impdate[i].getJobDuration() +"\n" );
//XmlDate to Calendar,GDate, Date
System.out.println("Birth DateTime(xs:dateTime): ");
System.out.println("Calendar:"+impdate[i].getBirthdatetime());
System.out.println("Date:"+impdate[i].xgetBirthdatetime().getDateValue());
System.out.println("GDate:"+impdate[i].xgetBirthdatetime().getGDateValue() +"\n" );
//XmlGday to Calendar,GDate, Day - primitive java int
System.out.println("Pay Day(xs:gDay): ");
System.out.println("Calendar:"+impdate[i].getPayday());
System.out.println("GDate:"+impdate[i].xgetPayday().getGDateValue());
System.out.println("Day:"+ impdate[i].xgetPayday().getGDateValue().getDay() +"\n" );
System.out.println("\n\n");
}
}
}
/**
* This method creates an new <important-date> element and attaches to the existing XML Instance, and saves the
* new Instance to a file(args[1]).
*/
public void createDocument(DatetimeDocument doc , String file){
// Retrieve the <datetime> element and add a new <important-date> element.
DatetimeDocument.Datetime dtelement = doc.getDatetime();
//
// add an important date using XmlCalendar
//
ImportantDate impdate = dtelement.addNewImportantDate();
//Creating value for <holiday> element
Calendar holiday = new XmlCalendar("2004-07-04");
//Creating value for <fun-begin-time> element
Calendar funbegintime = new XmlCalendar("10:30:33");
//Creating value for <fun-end-time> element
Calendar funendtime = new XmlCalendar("12:40:12");
//Creating value for <birthdatetime> element
Calendar birthdatetime = new XmlCalendar("1977-11-29T10:10:12");
//Creating value for <job-duration> element
GDuration jobduration = new GDuration(1,2,4,5,10,12,15,null);
//Creating value for <payday> element
Calendar payday = new XmlCalendar("---12");
//Setting all the elements
impdate.addHoliday(holiday);
impdate.setFunBeginTime(funbegintime);
impdate.setFunEndTime(funendtime);
impdate.setJobDuration(jobduration);
impdate.setBirthdatetime(birthdatetime);
impdate.setPayday(payday);
impdate.setDescription("Using XmlCalendar");
//
// add another important date using Calendar
//
impdate = dtelement.addNewImportantDate();
//Creating value for <holiday> element using XmlCalendar
holiday = new XmlCalendar("2004-07-04");
//Creating value for <fun-begin-time> element using GregorianCalendar
funbegintime = Calendar.getInstance();
funbegintime.clear();
funbegintime.set(Calendar.AM_PM , Calendar.AM);
funbegintime.set(Calendar.HOUR, 10);
funbegintime.set(Calendar.MINUTE, 30 );
funbegintime.set(Calendar.SECOND, 35 );
//Creating value for <fun-end-time> element
funendtime = Calendar.getInstance();
funendtime.clear();
funendtime.set(Calendar.AM_PM , Calendar.AM);
funendtime.set(Calendar.HOUR, 12);
funendtime.set(Calendar.MINUTE, 40 );
funendtime.set(Calendar.SECOND, 12 );
//Creating value for <birthdatetime> element
birthdatetime = Calendar.getInstance();
birthdatetime.clear();
birthdatetime.set(1977,10,29,10,10,12);
//Creating value for <job-duration> element
jobduration = new GDuration(1,2,4,5,10,12,15,null);
//Creating value for <payday> element
payday = Calendar.getInstance();
payday.clear();
payday.set(Calendar.DAY_OF_MONTH,12);
//Setting all the elements
impdate.addHoliday(holiday);
impdate.setFunBeginTime(funbegintime);
impdate.setFunEndTime(funendtime);
impdate.setJobDuration(jobduration);
impdate.setBirthdatetime(birthdatetime);
impdate.setPayday(payday);
impdate.setDescription("Using Calendar");
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
// Validate the new XML
boolean isXmlValid = validateXml(doc);
if (isXmlValid) {
File f = new File(file);
try{
//Writing the XML Instance to a file.
doc.save(f,xmlOptions);
}
catch(IOException e){
e.printStackTrace();
}
System.out.println("\nXML Instance Document saved at : " + f.getPath());
}
}
/**
* <p>Validates the XML, printing error messages when the XML is invalid. Note
* that this method will properly validate any instance of a compiled schema
* type because all of these types extend XmlObject.</p>
*
* <p>Note that in actual practice, you'll probably want to use an assertion
* when validating if you want to ensure that your code doesn't pass along
* invalid XML. This sample prints the generated XML whether or not it's
* valid so that you can see the result in both cases.</p>
*
* @param xml The XML to validate.
* @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
*/
public boolean validateXml(XmlObject xml)
{
boolean isXmlValid = false;
// A collection instance to hold validation error messages.
ArrayList validationMessages = new ArrayList();
// Validate the XML, collecting messages.
isXmlValid = xml.validate(new XmlOptions().setErrorListener(validationMessages));
if (!isXmlValid)
{
System.out.println("Invalid XML: ");
for (int i = 0; i < validationMessages.size(); i++)
{
XmlError error = (XmlError) validationMessages.get(i);
System.out.println(error.getMessage());
System.out.println(error.getObjectLocation());
}
}
return isXmlValid;
}
}

View File

@@ -0,0 +1,49 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.datetime;
import org.apache.xmlbeans.samples.datetime.DatetimeDocument ;
/**
* A class with which to test the DateTime sample.
*/
public class DateTimeTest
{
/**
* Tests the DateTime sample.
*
* @param args An array in which the first item is a path to an XML file
* based on the schema in datetime.xsd.
*/
public static void main(String[] args)
{
// Create an instance of this sample to work with.
DateTime sample = new DateTime();
// Create an schema type instance from the XML indicated by the path.
DatetimeDocument doc = sample.parseXml(args[0]);
sample.printInstance(doc);
// Validate the XML.
boolean exampleIsValid = sample.validateXml(doc);
assert exampleIsValid;
//Creating a new XML document
sample.createDocument(doc,args[1]);
}
}

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<datetime xmlns="http://xmlbeans.apache.org/samples/datetime">
<important-date>
<holiday>2004-11-02</holiday>
<fun-begin-time>18:00:00</fun-begin-time>
<fun-end-time>23:00:00</fun-end-time>
<job-duration>P1Y1DT20H25M30S</job-duration>
<birthdatetime>2001-04-16T15:23:15</birthdatetime>
<payday>---15</payday>
<description>2nd-Nov-2004, 6:00PM, 11:00PM, 1Yr and a day - 20hours, 16th Apr 2001 3:23 and 15 seconds</description>
</important-date>
<important-date>
<holiday>2004-07-04</holiday>
<fun-begin-time>10:30:35</fun-begin-time>
<fun-end-time>12:40:12</fun-end-time>
<job-duration>P2Y4M5DT10H12M15S</job-duration>
<birthdatetime>1977-11-29T10:10:12</birthdatetime>
<payday>---30</payday>
<description>Description</description>
</important-date>
</datetime>
<!-- Professional XML pgno.201 = duration = 11Y0M1DT20:25:30 -->

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.-->
<datetime xmlns="http://xmlbeans.apache.org/samples/datetime">
<important-date>
<holiday>2004-11-02</holiday>
<fun-begin-time>18:00:00</fun-begin-time>
<fun-end-time>23:00:00</fun-end-time>
<job-duration>P1Y1DT20H25M30S</job-duration>
<birthdatetime>2001-04-16T15:23:15</birthdatetime>
<payday>---15</payday>
<description>2nd-Nov-2004, 6:00PM, 11:00PM, 1Yr and a day - 20hours, 16th Apr 2001 3:23 and 15 seconds</description>
</important-date>
<important-date>
<holiday>2004-07-04</holiday>
<fun-begin-time>10:30:35</fun-begin-time>
<fun-end-time>12:40:12</fun-end-time>
<job-duration>P2Y4M5DT10H12M15S</job-duration>
<birthdatetime>1977-11-29T10:10:12</birthdatetime>
<payday>---30</payday>
<description>Description</description>
</important-date>
<important-date>
<holiday>2004-07-04</holiday>
<fun-begin-time>10:30:33</fun-begin-time>
<fun-end-time>12:40:12</fun-end-time>
<job-duration>P2Y4M5DT10H12M15S</job-duration>
<birthdatetime>1977-11-29T10:10:12</birthdatetime>
<payday>---12</payday>
<description>Using XmlCalendar</description>
</important-date>
<important-date>
<holiday>2004-07-04</holiday>
<fun-begin-time>10:30:35</fun-begin-time>
<fun-end-time>12:40:12</fun-end-time>
<job-duration>P2Y4M5DT10H12M15S</job-duration>
<birthdatetime>1977-11-29T10:10:12</birthdatetime>
<payday>---12</payday>
<description>Using Calendar</description>
</important-date>
</datetime>
<!--Professional XML pgno.201 = duration = 11Y0M1DT20:25:30-->

View File

@@ -0,0 +1,34 @@
Sample: MixedContent
Author: Steven Traut (straut@bea.com)
Last Updated: Sept. 6, 2004
Versions:
xmlbeans-1.0.3
xmlbeans-v2
-----------------------------------------------------------------------------
This sample illustrates how you can work with mixed content XML by combining
strong types generated from schema with an XmlCursor instance. The XmlCursor
interface is provided with XMLBeans for just this kind of use. With strong types
you can only get or set the full value of an element; by using a cursor you can
"dive into" the contents of an element, manipulating child elements that are
embedded in the content and surrounded by other text.
The sample's XML is a pseudo-inventory of nonsensical items, each with a unique
ID and a description. Where the name of one item is mentioned in the description
of another, the sample code wraps the name with a <link> element whose id
attribute is the ID of the named item.
When you run this sample, you'll see it print potentially three blocks of
information:
- The XML it got from the inventoryitems.xml file.
- The XML it generated by associating cross-mentioned items.
- The results from validating the resulting XML, if the XML is invalid.
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. To compile the schemas and sample source, run "ant build"
4. To execute the sample, run "ant run"

View File

@@ -0,0 +1,120 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="MixedContent" default="build">
<property environment="env"/>
<path id="MixedContent.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="*.jar"/>
<pathelement path="build/classes"/>
</path>
<target name="init">
<property name="xmlbeans.home" value="${env.XMLBEANS_HOME}"/>
<echo message="xmlbeans.home: ${xmlbeans.home}"/>
<!-- check for xbean.jar from binary distribution -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/lib"
file="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/build/lib"
file="${xmlbeans.home}/build/lib/xbean.jar" />
<fail message="Set XMLBEANS_HOME in your enviornment."
unless="xmlbeans.lib"/>
<echo message="xmlbeans.lib: ${xmlbeans.lib}"/>
<path id="xmlbeans.path">
<fileset dir="${xmlbeans.lib}" includes="*.jar"/>
</path>
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpathref="xmlbeans.path"/>
</target>
<!-- ========================== clean ==== -->
<target name="clean">
<delete dir="build"/>
</target>
<!-- ========================== build ==== -->
<target name="build" depends="init,schemas.jar,MixedContent.classes">
</target>
<target name="schemas.check">
<uptodate property="schemas.notRequired"
targetfile="build/lib/schemas.jar">
<srcfiles dir="schemas" includes="**/*.xsd"/>
</uptodate>
</target>
<target name="schemas.jar" depends="init,schemas.check"
unless="schemas.notRequired">
<mkdir dir="build/lib"/>
<xmlbean schema="schemas"
destfile="build/lib/schemas.jar"
srcgendir="build/src"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="MixedContent.classes" depends="init">
<mkdir dir="build/classes"/>
<javac srcdir="src"
destdir="build/classes"
classpathref="MixedContent.path"
debug="on"
source="1.4"
/>
</target>
<!-- ========================== run ==== -->
<target name="run" depends="init,build">
<echo message="============================== running MixedContent"/>
<java
classname="org.apache.xmlbeans.samples.cursor.MixedContent"
classpathref="MixedContent.path"
fork="true">
<arg line="xml/inventoryitems.xml"/>
</java>
</target>
<!-- ========================== test ==== -->
<target name="test" depends="init,build">
<echo message="============================== testing MixedContent"/>
<java
classname="org.apache.xmlbeans.samples.cursor.MixedContentTest"
classpathref="MixedContent.path"
fork="true">
<arg line="xml/inventoryitems.xml"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema targetNamespace="http://xmlbeans.apache.org/samples/cursor/mixedcontent"
xmlns:mc="http://xmlbeans.apache.org/samples/cursor/mixedcontent"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:complexType name="descriptionType" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="link" type="mc:linkType"/>
</xs:choice>
</xs:complexType>
<xs:element name="inventory">
<xs:complexType>
<xs:sequence>
<xs:element name="item" type="mc:itemType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="itemType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="description" type="mc:descriptionType"/>
<xs:element name="price" type="xs:double"/>
<xs:element name="quantity" type="xs:int"/>
</xs:sequence>
<xs:attribute name="id" type="xs:int" use="required"/>
</xs:complexType>
<xs:complexType name="linkType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:int" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>

View File

@@ -0,0 +1,263 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Unless required by applicable law or agreed to in writing, software
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.cursor;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.samples.cursor.mixedcontent.DescriptionType;
import org.apache.xmlbeans.samples.cursor.mixedcontent.InventoryDocument;
import org.apache.xmlbeans.samples.cursor.mixedcontent.ItemType;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
/**
* <p>This sample illustrates how you can use an XML cursor
* to manipulate the content of an element. Even though
* working with strongly-typed XML (in which you are accessing
* the XML through an API generated from schema) provides easy
* access for getting and setting the entire value of an
* element or attribute, it does not easily provide finer
* grained access to an element's content. This sample
* shows how you can use an XML cursor to "dive into" an
* element's content, manipulating it on a character-by-
* character level.</p>
* <p/>
* <p>The code in this sample is designed to look at the
* description of each item in an inventory list, creating
* a link wherever the description contains a reference
* to another item in the inventory list. This alters the
* &lt;description&gt; element so that it contains a mix of text and
* link elements. Such an element is said to have "mixed
* content."</p>
* <p/>
* This sample uses the schema defined in inventory.xsd.
*/
public class MixedContent
{
/**
* Receives an inventory XML instance and rewrites it so that items listed
* in the inventory point to one another via &lt;link&gt; elements.
*
* @param args An array containing one argument: the path to an XML instance
* conforming to the schema in inventory.xsd.
*/
public static void main(String[] args)
{
// Create an instance of this sample to work with.
MixedContent thisSample = new MixedContent();
// Create an schema type instance from the XML indicated by the path.
InventoryDocument inventoryDoc = thisSample.parseXml(args[0]);
// Print what was received.
System.out.println("Received XML: \n\n" + inventoryDoc.toString());
// Edit the XML, adding <link> elements to associate related items.
InventoryDocument linkedResultDoc = thisSample.linkItems(inventoryDoc);
// Print the updated XML.
System.out.println("XML with linked items: \n\n" + linkedResultDoc.toString());
// Validate the result.
System.out.println("New XML is valid: " +
thisSample.validateXml(linkedResultDoc));
}
/**
* <p>Creates "links" between items in an inventory list by inserting
* a &lt;link&gt; element for each linked item. An XmlCursor
* instance passes through each &lt;description&gt; element, looking
* for text matching the name of an item.</p>
*
* @param inventoryDoc An XML document conforming to the schema in
* inventory.xsd.
*/
public InventoryDocument linkItems(InventoryDocument inventoryDoc)
{
// Retrieve the &lt;inventory&gt; element and get an array of
// the &lt;item&gt; elements it contains.
InventoryDocument.Inventory inventory = inventoryDoc.getInventory();
ItemType[] items = inventory.getItemArray();
// Loop through the &lt;item&gt; elements, examining the
// description for each to see if another inventory item
// is mentioned.
for (int i = 0; i < items.length; i++)
{
// Get details about the current item, including
// its length. This will be used to measure text
// while exploring the description.
String itemName = items[i].getName();
String itemId = new Integer(items[i].getId()).toString();
int itemCharCount = itemName.length();
// Loop through the item descriptions, looking at each
// for the name of the current item.
for (int j = 0; j < items.length; j++)
{
DescriptionType description = items[j].getDescription();
// Insert an XmlCursor instance and set it at
// the beginning of the <&lt;description&gt; element's text,
// just after the start tag.
XmlCursor cursor = description.newCursor();
cursor.toLastAttribute();
cursor.toNextToken();
// Get a String containing the characters to the
// immediate right of the cursor, up to the next
// token (in this case, the next element after
// the description element). Get the number of
// characters to the right of the cursor; this will
// be used to mark the distance the cursor should move
// before trying another item's description. Also,
// create a charCount variable to mark the cursor's
// current position.
String cursorChars = cursor.getChars();
int descCharCount = cursorChars.length();
int charCount = 0;
// As long at the cursor hasn't reached the end of the
// description text, check to see if the text to the
// cursor's immediate right matches the item name sought.
// If it does match, remove the text and create a link
// element to replace it.
while (charCount < descCharCount)
{
// A char array to hold the characters currently being
// checked.
char[] chars = new char[itemCharCount];
// Pass the char array with the getChars method. This
// method will find the chars from the cursor's
// immediate right to the char at itemCharCount (the
// length of the item name currently sought). The
// method's second argument indicates where in the char
// array the found text should begin -- in this case, at the
// beginning.
int charsReturned = cursor.getChars(chars, 0, itemCharCount);
// If the characters in chars match the item name, then
// make a link from the text.
if (new String(chars).equals(itemName))
{
// Remove the found item name.
cursor.removeChars(itemCharCount);
// Begin a new link element whose namespace is the
// same as the rest of the inventory document. The
// beginElement method creates a new element with the
// name specified around the current cursor.
cursor.beginElement("link",
"http://xmlbeans.apache.org/samples/cursor/mixedcontent");
// Insert an id attribute and make its value the id of
// the item sought.
cursor.insertAttributeWithValue("id", itemId);
// Insert the item name as the element's value.
cursor.insertChars(itemName);
}
// Move on to the next character in the description.
cursor.toNextChar(1);
// Increment the counter tracking the cursor's position.
charCount++;
}
// Be sure to dispose of a cursor that's no longer needed.
// This allows it to be garbage collected.
cursor.dispose();
}
}
// Return the edited document.
return inventoryDoc;
}
/**
* <p>Validates the XML, printing error messages when the XML is invalid. Note
* that this method will properly validate any instance of a compiled schema
* type because all of these types extend XmlObject.</p>
*
* <p>Note that in actual practice, you'll probably want to use an assertion
* when validating if you want to ensure that your code doesn't pass along
* invalid XML. This sample prints the generated XML whether or not it's
* valid so that you can see the result in both cases.</p>
*
* @param xml The XML to validate.
* @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
*/
public boolean validateXml(XmlObject xml)
{
boolean isXmlValid = false;
// A collection instance to hold validation error messages.
ArrayList validationMessages = new ArrayList();
// Validate the XML, collecting messages.
isXmlValid = xml.validate(
new XmlOptions().setErrorListener(validationMessages));
// If the XML isn't valid, print the messages.
if (!isXmlValid)
{
System.out.println("Invalid XML: ");
for (int i = 0; i < validationMessages.size(); i++)
{
XmlError error = (XmlError) validationMessages.get(i);
System.out.println(error.getMessage());
System.out.println(error.getObjectLocation());
}
}
return isXmlValid;
}
/**
* <p>Creates a File from the XML path provided in main arguments, then
* parses the file's contents into a type generated from schema.</p>
*
* <p>Note that this work might have been done in main. Isolating it here
* makes the code separately available from outside this class.</p>
*
* @param xmlFilePath A path to XML based on the schema in inventory.xsd.
* @return An instance of a generated schema type that contains the parsed
* XML.
*/
public InventoryDocument parseXml(String xmlFilePath)
{
// Get the XML instance into a file using the path provided.
File inventoryFile = new File(xmlFilePath);
// Create an instance of a type generated from schema to hold the XML.
InventoryDocument inventoryDoc = null;
try
{
// Parse the instance into the type generated from the schema.
inventoryDoc = InventoryDocument.Factory.parse(inventoryFile);
} catch (XmlException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return inventoryDoc;
}
}

View File

@@ -0,0 +1,50 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.cursor;
import org.apache.xmlbeans.samples.cursor.mixedcontent.InventoryDocument;
/**
* A class with which to test the MixedContent sample.
*/
public class MixedContentTest
{
/**
* Tests the MixedContent sample.
*
* @param args An array in which the first item is a path to an XML file
* based on the schema in inventory.xsd.
*/
public static void main(String[] args)
{
// Create an instance of this sample to work with.
MixedContent sample = new MixedContent();
// Create an schema type instance from the XML indicated by the path.
InventoryDocument inventoryDoc = sample.parseXml(args[0]);
// Validate the XML.
boolean exampleIsValid = sample.validateXml(inventoryDoc);
assert exampleIsValid;
// Edit the XML, adding <link> elements to associate related items.
InventoryDocument linkedResultDoc = sample.linkItems(inventoryDoc);
// Validate the XML.
boolean newXmlIsValid = sample.validateXml(linkedResultDoc);
assert newXmlIsValid;
}
}

View File

@@ -0,0 +1,36 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<inventory xmlns="http://xmlbeans.apache.org/samples/cursor/mixedcontent">
<item id="897946">
<name>locking flange harbinger</name>
<description>Completely myopic gyrating mill-flange.</description>
<price>21.79</price>
<quantity>4594</quantity>
</item>
<item id="745621">
<name>protaic calliphange</name>
<description>Asymmetrical flared-gill spongimass. Complements the locking flange harbinger
with perfect precision.</description>
<price>19.95</price>
<quantity>2</quantity>
</item>
<item id="784269">
<name>gyrating mill-flange</name>
<description>Polymorphic atrophical mylobium. Not compatible with any other device ever made.</description>
<price>.99</price>
<quantity>1205987</quantity>
</item>
</inventory>

View File

@@ -0,0 +1,29 @@
Sample: MixedContent
Author: Eric Vasilik (ericvas@bea.com)
Last Updated: Oct. 28, 2004
Versions:
xmlbeans-1.0.3
xmlbeans-v2
-----------------------------------------------------------------------------
This samples gives an quick overview of how to use XmlBeans with both the
strongly typed XmlObjects (StatementDocument, Transaction) and with the
XmlCursor.
In the sample, a instance of a statement is iterated over twice --
once using the strongly typed array approach and once with an XmlCursor. When
walking over the array the programmer naivly adds up deposit amounts before
the withdrawal amounts. The end result is a positive balance. When walking
over the array using XmlCursor, the transaction amounts are processed in order
and the end result is a negative balance.
In this situation, the order of the xml elements matters!
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. To compile the schemas and sample source, run "ant build"
4. To execute the sample, run "ant run"

View File

@@ -0,0 +1,120 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="OrderMatters" default="build">
<property environment="env"/>
<path id="OrderMatters.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="*.jar"/>
<pathelement path="build/classes"/>
</path>
<target name="init">
<property name="xmlbeans.home" value="${env.XMLBEANS_HOME}"/>
<echo message="xmlbeans.home: ${xmlbeans.home}"/>
<!-- check for xbean.jar from binary distribution -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/lib"
file="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/build/lib"
file="${xmlbeans.home}/build/lib/xbean.jar" />
<fail message="Set XMLBEANS_HOME in your enviornment."
unless="xmlbeans.lib"/>
<echo message="xmlbeans.lib: ${xmlbeans.lib}"/>
<path id="xmlbeans.path">
<fileset dir="${xmlbeans.lib}" includes="*.jar"/>
</path>
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpathref="xmlbeans.path"/>
</target>
<!-- ========================== clean ==== -->
<target name="clean">
<delete dir="build"/>
</target>
<!-- ========================== build ==== -->
<target name="build" depends="init,schemas.jar,OrderMatters.classes">
</target>
<target name="schemas.check">
<uptodate property="schemas.notRequired"
targetfile="build/lib/schemas.jar">
<srcfiles dir="schemas" includes="**/*.xsd"/>
</uptodate>
</target>
<target name="schemas.jar" depends="init,schemas.check"
unless="schemas.notRequired">
<mkdir dir="build/lib"/>
<xmlbean schema="schemas"
destfile="build/lib/schemas.jar"
srcgendir="build/src"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="OrderMatters.classes" depends="init">
<mkdir dir="build/classes"/>
<javac srcdir="src"
destdir="build/classes"
classpathref="OrderMatters.path"
debug="on"
source="1.4"
/>
</target>
<!-- ========================== run ==== -->
<target name="run" depends="init,build">
<echo message="============================== running OrderMatters"/>
<java
classname="org.apache.xmlbeans.samples.cursor.OrderMatters"
classpathref="OrderMatters.path"
fork="true">
<arg line="xml/stmt.xml"/>
</java>
</target>
<!-- ========================== test ==== -->
<target name="test" depends="init,build">
<echo message="============================== testing OrderMatters"/>
<java
classname="org.apache.xmlbeans.samples.cursor.OrderMattersTest"
classpathref="OrderMatters.path"
fork="true">
<arg line="xml/stmt.xml"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,38 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema
targetNamespace="http://statement"
elementFormDefault="qualified"
xmlns:tns="http://statement"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="statement">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="deposit" type="tns:transaction"/>
<xs:element name="withdrawal" type="tns:transaction"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="transaction">
<xs:sequence>
<xs:element name="description" type="xs:string"/>
<xs:element name="amount" type="xs:float"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

View File

@@ -0,0 +1,102 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.cursor;
import statement.StatementDocument;
import statement.StatementDocument.Statement;
import statement.Transaction;
import java.io.File;
import org.apache.xmlbeans.XmlCursor;
import javax.xml.namespace.QName;
public class OrderMatters
{
private static QName deposit = new QName( "http://statement", "deposit" );
public static void main ( String[] args ) throws Exception
{
// load the xml instance into the store and return a
// strongly typed instance of StatementDocument
StatementDocument stmtDoc = StatementDocument.Factory.parse( new File( args[ 0 ] ) );
System.out.println( "Valid statement instance? " + stmtDoc.validate() );
float balance = balanceOutOfOrder(stmtDoc);
System.out.println( "Ending balance: $" + balance );
balance = balanceInOrder(stmtDoc);
System.out.println( "Ending balance: $" + balance );
}
/**
* Out of order balance: the ease of stronly-typed XmlObjects!
*/
public static float balanceOutOfOrder(StatementDocument stmtDoc)
{
Statement stmt = stmtDoc.getStatement();
float balance = 0;
Transaction[] deposits = stmt.getDepositArray();
Transaction[] withdrawals = stmt.getWithdrawalArray();
for ( int i = 0 ; i < deposits.length ; i++ )
balance += deposits[ i ].getAmount();
for ( int i = 0 ; i < withdrawals.length ; i++ )
balance -= withdrawals[ i ].getAmount();
return balance;
}
/**
* In order balance: the power of XmlCursor!
*/
public static float balanceInOrder(StatementDocument stmtDoc)
{
float balance = 0;
XmlCursor cursor = stmtDoc.newCursor();
// use xpath to select elements
cursor.selectPath( "*/*" );
// iterate over the selection
while ( cursor.toNextSelection() )
{
// two views of the same data:
// move back and forth between XmlObject <-> XmlCursor
Transaction trans = (Transaction) cursor.getObject();
float amount = trans.getAmount();
if (cursor.getName().equals( deposit ))
balance += amount;
else if ((balance -= amount) < 0)
{
// doh!
System.out.println( "Negative balance: $" + balance );
balance -= 50;
}
}
return balance;
}
}

View File

@@ -0,0 +1,46 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.cursor;
import statement.StatementDocument;
import statement.StatementDocument.Statement;
import statement.Transaction;
import java.io.File;
import org.apache.xmlbeans.XmlCursor;
import javax.xml.namespace.QName;
public class OrderMattersTest
{
private static QName deposit = new QName( "http://statement", "deposit" );
public static void main ( String[] args ) throws Exception
{
StatementDocument stmtDoc = StatementDocument.Factory.parse( new File( args[ 0 ] ) );
if (!stmtDoc.validate())
throw new RuntimeException("expected valid instance: " + args[0]);
float balance = OrderMatters.balanceOutOfOrder(stmtDoc);
if (1010F != balance)
throw new RuntimeException("expected out of order to return $1010.0: " + balance);
balance = OrderMatters.balanceInOrder(stmtDoc);
if (960F != balance)
throw new RuntimeException("expected in order to return $960.0: " + balance);
}
}

View File

@@ -0,0 +1,33 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<statement xmlns="http://statement">
<deposit>
<description>Vegas winnings!</description>
<amount>3000.00</amount>
</deposit>
<withdrawal>
<description>OSCON Registration</description>
<amount>1890.00</amount>
</withdrawal>
<withdrawal>
<description>Four Seasons Hotel</description>
<amount>1200.00</amount>
</withdrawal>
<deposit>
<description>Paycheck</description>
<amount>1100.00</amount>
</deposit>
</statement>

View File

@@ -0,0 +1,28 @@
Sample: SchemaEnum
Author: Steven Traut (straut@bea.com)
Last Updated: Aug. 11th, 2004
Versions:
xmlbeans-1.0.3
xmlbeans-v2
-----------------------------------------------------------------------------
This sample illustrates how you can access XML values that are
defined in schema as enumerations. When a schema containing
enumerations is compiled, the generated Java types represent the
schema enumerations with Java enumerations. You can access these through
their constants and corresponding int values.
When you run this sample, you'll see it print three blocks of information:
- The XML it got from the PurchaseOrder.xml file.
- The XML it generated by taking data from the PurchaseOrder.xml file and
copying it into a new XML document created from another schema.
- A few lines of data extracted from the newly generated XML file.
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. To compile the schemas and sample source, run "ant build"
4. To execute the sample, run "ant run"

View File

@@ -0,0 +1,120 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="SchemaEnum" default="build">
<property environment="env"/>
<path id="SchemaEnum.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="*.jar"/>
<pathelement path="build/classes"/>
</path>
<target name="init">
<property name="xmlbeans.home" value="${env.XMLBEANS_HOME}"/>
<echo message="xmlbeans.home: ${xmlbeans.home}"/>
<!-- check for xbean.jar from binary distribution -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/lib"
file="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/build/lib"
file="${xmlbeans.home}/build/lib/xbean.jar" />
<fail message="Set XMLBEANS_HOME in your enviornment."
unless="xmlbeans.lib"/>
<echo message="xmlbeans.lib: ${xmlbeans.lib}"/>
<path id="xmlbeans.path">
<fileset dir="${xmlbeans.lib}" includes="*.jar"/>
</path>
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpathref="xmlbeans.path"/>
</target>
<!-- ========================== clean ==== -->
<target name="clean">
<delete dir="build"/>
</target>
<!-- ========================== build ==== -->
<target name="build" depends="init,schemas.jar,SchemaEnum.classes">
</target>
<target name="schemas.check">
<uptodate property="schemas.notRequired"
targetfile="build/lib/schemas.jar">
<srcfiles dir="schemas" includes="**/*.xsd"/>
</uptodate>
</target>
<target name="schemas.jar" depends="init,schemas.check"
unless="schemas.notRequired">
<mkdir dir="build/lib"/>
<xmlbean schema="schemas"
destfile="build/lib/schemas.jar"
srcgendir="build/src"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="SchemaEnum.classes" depends="init">
<mkdir dir="build/classes"/>
<javac srcdir="src"
destdir="build/classes"
classpathref="SchemaEnum.path"
debug="on"
source="1.4"
/>
</target>
<!-- ========================== run ==== -->
<target name="run" depends="init,build">
<echo message="============================== running SchemaEnum"/>
<java
classname="org.apache.xmlbeans.samples.enumeration.SchemaEnum"
classpathref="SchemaEnum.path"
fork="true">
<arg line="xml/PurchaseOrder.xml"/>
</java>
</target>
<!-- ========================== test ==== -->
<target name="test" depends="init,build">
<echo message="============================== testing SchemaEnum"/>
<java
classname="org.apache.xmlbeans.samples.enumeration.SchemaEnumTest"
classpathref="SchemaEnum.path"
fork="true">
<arg line="xml/PurchaseOrder.xml"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,50 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema targetNamespace="http://xmlbeans.apache.org/samples/enumeration/schemaenum/easypo"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:po="http://xmlbeans.apache.org/samples/enumeration/schemaenum/easypo"
elementFormDefault="qualified">
<xs:element name="purchase-order">
<xs:complexType>
<xs:sequence>
<xs:element name="customer" type="po:customer"/>
<xs:element name="date" type="xs:dateTime" />
<xs:element name="line-item" type="po:line-item" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="shipper" type="po:shipper" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="customer">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="line-item">
<xs:sequence>
<xs:element name="description" type="xs:string"/>
<xs:element name="per-unit-ounces" type="xs:decimal"/>
<xs:element name="price" type="xs:double"/>
<xs:element name="quantity" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="shipper">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="per-ounce-rate" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

View File

@@ -0,0 +1,63 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema targetNamespace="http://xmlbeans.apache.org/samples/enumeration/schemaenum/pricesummary"
xmlns:ps="http://xmlbeans.apache.org/samples/enumeration/schemaenum/pricesummary"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<!-- Define an item type that specifies information about an item.
item elements are children of the price element. -->
<xs:complexType name="itemType">
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="amount" type="xs:double"/>
<xs:element name="quantity" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
<!-- Define a price type that specifies price information. A price may
contain multiple item elements (of type "itemType"), and has a single
threshold attribute whose value may be "Below10Dollars", "Between10And20Dollars",
or "Above20Dollars". These values are enumerated, and may be accessed as
enumerations through XMLBeans. -->
<xs:complexType name="priceType">
<xs:sequence>
<xs:element name="item" type="ps:itemType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="threshold">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Below10Dollars"/>
<xs:enumeration value="Between10And20Dollars"/>
<xs:enumeration value="Above20Dollars"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<!-- Define a price type that specifies price information. A price may
contain multiple item elements (of type "itemType"), and has a single
threshold attribute whose value may be "Below10Dollars", "Between10And20Dollars",
or "Above20Dollars". These values are enumerated, and may be accessed as
enumerations through XMLBeans. -->
<xs:element name="price-summary">
<xs:complexType>
<xs:sequence>
<xs:element name="price" type="ps:priceType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@@ -0,0 +1,279 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.enumeration;
import org.apache.xmlbeans.XmlError;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.apache.xmlbeans.samples.enumeration.schemaenum.easypo.LineItem;
import org.apache.xmlbeans.samples.enumeration.schemaenum.easypo.PurchaseOrderDocument;
import org.apache.xmlbeans.samples.enumeration.schemaenum.pricesummary.ItemType;
import org.apache.xmlbeans.samples.enumeration.schemaenum.pricesummary.PriceSummaryDocument;
import org.apache.xmlbeans.samples.enumeration.schemaenum.pricesummary.PriceType;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
/**
* This sample illustrates how you can access XML values that are
* defined in schema as enumerations. When a schema containing
* enumerations is compiled, the generated Java types represent the
* schema enumerations with Java enumerations. You can access these through
* their constants and corresponding int values.
* <p/>
* The schemas used by this sample are defined in PriceSummary.xsd and
* EasyPO.xsd.
*/
public class SchemaEnum
{
/**
* Receives an PO XML instance and uses its data to create an XML
* document based another schema, and which summarizes the items
* in the PO by price.
*
* @param args An array containing one argument: the path to an XML instance
* conforming to the schema in EasyPO.xsd.
*/
public static void main(String[] args)
{
// Create an instance of this class to work with.
SchemaEnum thisSample = new SchemaEnum();
// Create an instance of a type based on the received XML's schema
// and use it to print what the sample received.
PurchaseOrderDocument poDoc = thisSample.parseXml(args[0]);
System.out.println("Received XML: \n\n" + poDoc.toString());
// Print the summarized items in XML based on a different schema.
PriceSummaryDocument summaryDoc = thisSample.summarizeItems(poDoc);
System.out.println("Summarized items: \n\n" + summaryDoc.toString());
// Print a simple non-XML list of items by threshold.
String sortedItems = thisSample.sortByThreshold(summaryDoc);
System.out.println("Sorted items: \n" + sortedItems);
// Validate the result.
System.out.println("New XML is valid: " +
thisSample.validateXml(summaryDoc));
}
/**
* <p>This method uses values in the incoming XML to construct
* a new XML document of a different schema. PriceSummary.xsd, the schema
* for the new document, defines XML enumerations for a price
* threshold attribute. Items whose price is between $10 and $20 receive
* a threshold value of "Between10And20Dollars"; items above 20 get a threshold
* value of "Above20Dollars".</p>
* <p/>
* <p>This method loops through the purchase order items, creating a summary
* document that specifies their threshold value.</p>
* <p/>
* <p>You can verify this method's work by comparing the resulting XML with
* the XML in PriceSummary.xml. You can also use this method's return value
* to test the sortByThreshold method.</p>
*/
public PriceSummaryDocument summarizeItems(PurchaseOrderDocument poDoc)
{
PurchaseOrderDocument.PurchaseOrder po = poDoc.getPurchaseOrder();
// Create a new instance of the PriceSummary schema. This is the document
// the code creates, extracting values from the purchase order.
PriceSummaryDocument summaryDoc = PriceSummaryDocument.Factory.newInstance();
PriceSummaryDocument.PriceSummary summary = summaryDoc.addNewPriceSummary();
// Create <price> elements to hold <item> elements according to their
// price threshold.
PriceType priceZero = summary.addNewPrice();
PriceType priceTen = summary.addNewPrice();
PriceType priceTwenty = summary.addNewPrice();
// Set the threshold attribute value for the two new elements.
priceZero.setThreshold(PriceType.Threshold.BELOW_10_DOLLARS);
priceTen.setThreshold(PriceType.Threshold.BETWEEN_10_AND_20_DOLLARS);
priceTwenty.setThreshold(PriceType.Threshold.ABOVE_20_DOLLARS);
// Loop through the purchase order <line-item> elements. If their
// <price> child element is between 10.00 and 20.00, add the <line-item>
// to the <price> element whose threshold is 10.00. For those over 20.00,
// add them to the <price> element whose threshold is 20.00.
// There don't happen to be any under 10.00, but handle this case anyway.
LineItem[] items = po.getLineItemArray();
for (int i = 0; i < items.length; i++)
{
LineItem item = items[i];
if (item.getPrice() < 10.00)
{
ItemType newItem = priceZero.addNewItem();
newItem.setTitle(item.getDescription());
newItem.xsetQuantity(item.xgetQuantity());
newItem.setAmount(item.getPrice());
} else if (item.getPrice() >= 10.00 && item.getPrice() < 20.00)
{
ItemType newItem = priceTen.addNewItem();
newItem.setTitle(item.getDescription());
newItem.xsetQuantity(item.xgetQuantity());
newItem.setAmount(item.getPrice());
} else if (item.getPrice() >= 20.00)
{
ItemType newItem = priceTwenty.addNewItem();
newItem.setTitle(item.getDescription());
newItem.xsetQuantity(item.xgetQuantity());
newItem.setAmount(item.getPrice());
}
}
return summaryDoc;
}
/**
* <p>This method loops through a price summary XML document to
* create a string that lists the items grouped by threshold.
* Unlike the summarizeItems method, which creates a new XML
* document that contains an attribute whose value is enumerated,
* this method retrieves values from an enumeration.</p>
* <p/>
* <p>This method illustrates how you can use the int value corresponding
* to enumerations to specify them in Java switch statements.</p>
*/
public String sortByThreshold(PriceSummaryDocument summaryDoc)
{
// Extract the summary element from the incoming XML, then use it
// to extract an array of the price elements.
PriceSummaryDocument.PriceSummary summary = summaryDoc.getPriceSummary();
PriceType[] priceElements = summary.getPriceArray();
StringBuffer responseBuffer = new StringBuffer();
// Create string buffers to hold the sorted results of the values
// retrieved.
StringBuffer zeroBuffer = new StringBuffer("\nItems under 10 dollars: \n");
StringBuffer tenBuffer = new StringBuffer("\nItems between 10 and 20 dollars: \n");
StringBuffer twentyBuffer = new StringBuffer("\nItems more than 20 dollars: \n");
// Loop through the price elements, extracting the array of <item> child
// elements in each.
for (int i = 0; i < priceElements.length; i++)
{
ItemType[] itemElements = priceElements[i].getItemArray();
// Loop through the <item> elements, discovering which threshold
// the item belongs to, then using the element's <title> value
// in in a sorted list.
for (int j = 0; j < itemElements.length; j++)
{
ItemType item = itemElements[j];
// For each <item> element, find out the int value of its <price>
// parent element's threshold attribute value. Append the item's
// title to the appropriate string buffer.
switch (priceElements[i].getThreshold().intValue())
{
case PriceType.Threshold.INT_BELOW_10_DOLLARS:
zeroBuffer.append(" " + item.getTitle() + "\n");
break;
case PriceType.Threshold.INT_BETWEEN_10_AND_20_DOLLARS:
tenBuffer.append(" " + item.getTitle() + "\n");
break;
case PriceType.Threshold.INT_ABOVE_20_DOLLARS:
twentyBuffer.append(" " + item.getTitle() + "\n");
break;
default:
System.out.println("Yo! Something unexpected happened!");
break;
}
}
}
responseBuffer.append(tenBuffer);
responseBuffer.append(twentyBuffer);
return responseBuffer.toString();
}
/**
* <p>Validates the XML, printing error messages when the XML is invalid. Note
* that this method will properly validate any instance of a compiled schema
* type because all of these types extend XmlObject.</p>
* <p/>
* <p>Note that in actual practice, you'll probably want to use an assertion
* when validating if you want to ensure that your code doesn't pass along
* invalid XML. This sample prints the generated XML whether or not it's
* valid so that you can see the result in both cases.</p>
*
* @param xml The XML to validate.
* @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
*/
public boolean validateXml(XmlObject xml)
{
boolean isXmlValid = false;
// A collection instance to hold validation error messages.
ArrayList validationMessages = new ArrayList();
// Validate the XML, collecting messages.
isXmlValid = xml.validate(new XmlOptions().setErrorListener(validationMessages));
if (!isXmlValid)
{
System.out.println("Invalid XML: ");
for (int i = 0; i < validationMessages.size(); i++)
{
XmlError error = (XmlError) validationMessages.get(i);
System.out.println(error.getMessage());
System.out.println(error.getObjectLocation());
}
}
return isXmlValid;
}
/**
* <p>Creates a File from the XML path provided in main arguments, then
* parses the file's contents into a type generated from schema.</p>
* <p/>
* <p>Note that this work might have been done in main. Isolating it here
* makes the code separately available from outside this class.</p>
*
* @param xmlFilePath A path to XML based on the schema in inventory.xsd.
* @return An instance of a generated schema type that contains the parsed
* XML.
*/
public PurchaseOrderDocument parseXml(String xmlFilePath)
{
File poFile = new File(xmlFilePath);
PurchaseOrderDocument poDoc = null;
try
{
poDoc = PurchaseOrderDocument.Factory.parse(poFile);
} catch (XmlException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return poDoc;
}
}

View File

@@ -0,0 +1,52 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.enumeration;
import org.apache.xmlbeans.samples.enumeration.schemaenum.easypo.PurchaseOrderDocument;
import org.apache.xmlbeans.samples.enumeration.schemaenum.pricesummary.PriceSummaryDocument;
/**
* A class to test the SchemaEnum sample.
*/
public class SchemaEnumTest
{
/**
* Tests the SchemaEnum sample.
*
* @param args An array in which the first item is a path to an XML file
* based on the schema in inventory.xsd.
*/
public static void main(String[] args)
{
SchemaEnum sample = new SchemaEnum();
PurchaseOrderDocument poDoc = sample.parseXml(args[0]);
boolean exampleIsValid = sample.validateXml(poDoc);
assert exampleIsValid;
// Create a new document that summarizes the PO doc.
PriceSummaryDocument summaryDoc = sample.summarizeItems(poDoc);
boolean summaryIsValid = sample.validateXml(summaryDoc);
assert summaryIsValid;
// Create a summary of the items based on price.
String sortedItems = sample.sortByThreshold(summaryDoc);
boolean stringExists = (sortedItems != null);
assert stringExists;
}
}

View File

@@ -0,0 +1,36 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<price-summary xmlns="http://xmlbeans.apache.org/samples/enumeration/schemaenum/pricesummary">
<price threshold="Above20Dollars">
<item>
<title>Burnham's Celestial Handbook, Vol 1</title>
<amount>21.79</amount>
<quantity>1</quantity>
</item>
</price>
<price threshold="Between10And20Dollars">
<item>
<title>Burnham's Celestial Handbook, Vol 2</title>
<amount>19.89</amount>
<quantity>2</quantity>
</item>
<item>
<title>Burnham's Celestial Handbook, Vol 3</title>
<amount>19.89</amount>
<quantity>1</quantity>
</item>
</price>
</price-summary>

View File

@@ -0,0 +1,44 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<purchase-order xmlns="http://xmlbeans.apache.org/samples/enumeration/schemaenum/easypo">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2001-12-17T09:30:47-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 1</description>
<per-unit-ounces>5</per-unit-ounces>
<price>21.79</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 3</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>1</quantity>
</line-item>
<shipper>
<name>UPS</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</purchase-order>

View File

@@ -0,0 +1,38 @@
Sample: Validation
Author: Steven Traut (straut@bea.com)
Last Updated: May 25, 2005
Versions:
xmlbeans-v1 1.0.3
xmlbeans-v2
-----------------------------------------------------------------------------
This sample illustrates how you can use the XMLBeans API to validate
XML instances against schema. The API provides two validation features:
- A validate method (available from XmlOjbect and types generated from schema)
with which you can validate the bound instance and collect error messages that
result.
- An option through which you can specify that simple schema types should
be validated by XMLBeans when your code sets their value. This feature
will simply throw an exception if setting the value renders the instance
invalid.
Because it uses invalid XML for illustration, this sample is designed to "fail"
when it runs. When you run this sample, you'll see it print two blocks of information
in the console:
- A message containing errors resulting from calling the validate method
on invalid XML.
- The stack trace of an exception resulting from setting an invalid value
when the XmlOptions.VALIDATE_ON_SET option has been specified.
Note that you can also validate at the command line using tools provided
in the bin directory of the XMLBeans distribution.
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. To compile the schemas and sample source, run "ant build"
4. To execute the sample, run "ant run"

View File

@@ -0,0 +1,120 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="Validation" default="build">
<property environment="env"/>
<path id="Validation.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="*.jar"/>
<pathelement path="build/classes"/>
</path>
<target name="init">
<property name="xmlbeans.home" value="${env.XMLBEANS_HOME}"/>
<echo message="xmlbeans.home: ${xmlbeans.home}"/>
<!-- check for xbean.jar from binary distribution -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/lib"
file="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/build/lib"
file="${xmlbeans.home}/build/lib/xbean.jar" />
<fail message="Set XMLBEANS_HOME in your environment."
unless="xmlbeans.lib"/>
<echo message="xmlbeans.lib: ${xmlbeans.lib}"/>
<path id="xmlbeans.path">
<fileset dir="${xmlbeans.lib}" includes="*.jar"/>
</path>
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpathref="xmlbeans.path"/>
</target>
<!-- ========================== clean ==== -->
<target name="clean">
<delete dir="build"/>
</target>
<!-- ========================== build ==== -->
<target name="build" depends="init,schemas.jar,Validation.classes">
</target>
<target name="schemas.check">
<uptodate property="schemas.notRequired"
targetfile="build/lib/schemas.jar">
<srcfiles dir="schemas" includes="**/*.xsd"/>
</uptodate>
</target>
<target name="schemas.jar" depends="init,schemas.check"
unless="schemas.notRequired">
<mkdir dir="build/lib"/>
<xmlbean schema="schemas"
destfile="build/lib/schemas.jar"
srcgendir="src"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="Validation.classes" depends="init">
<mkdir dir="build/classes"/>
<javac srcdir="src"
destdir="build/classes"
classpathref="Validation.path"
debug="on"
source="1.4"
/>
</target>
<!-- ========================== run ==== -->
<target name="run" depends="init,build">
<echo message="============================== running Validation"/>
<java
classname="org.apache.xmlbeans.samples.validation.Validation"
classpathref="Validation.path"
fork="true">
<arg line="xml/todolist.xml"/>
</java>
</target>
<!-- ========================== test ==== -->
<target name="test" depends="init,build">
<echo message="============================== testing Validation"/>
<java
classname="org.apache.xmlbeans.samples.validation.ValidationTest"
classpathref="Validation.path"
fork="true">
<arg line="xml/todolist.xml"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema targetNamespace="http://xmlbeans.apache.org/samples/validation/todolist" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://xmlbeans.apache.org/samples/validation/todolist" elementFormDefault="qualified">
<xs:element name="todolist">
<xs:complexType>
<xs:sequence>
<xs:element name="item" type="itemType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="itemType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="due_by" type="xs:dateTime" minOccurs="0"/>
<xs:element name="action" type="actionType"/>
</xs:sequence>
<xs:attribute name="id" type="idType"/>
</xs:complexType>
<xs:simpleType name="nameType">
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="idType">
<xs:restriction base="xs:int">
<xs:maxExclusive value="100"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="actionType">
<xs:restriction base="xs:string">
<xs:enumeration value="do"/>
<xs:enumeration value="delegate"/>
<xs:enumeration value="someday_maybe_defer"/>
<xs:enumeration value="toss"/>
<xs:enumeration value="incubate"/>
<xs:enumeration value="file"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@@ -0,0 +1,188 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.validation;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.samples.validation.todolist.*;
import org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
/**
* A sample to illustrate two means for validating XML against schema
* using features of the XMLBeans API. The features illustrated are:
*
* - Validating after changes by using the XmlObject.validate method.
* This method is exposed by types generated by compiling schema. The
* validate method validates instances against all aspects of schema.
* Also, with this method you can specify a Collection instance to
* capture errors that occur during validation.
*
* - Validating "on the fly" using the XmlOptions.VALIDATE_ON_SET constant.
* This option prompts XMLBeans to validate XML against simple schema types
* <em>as you set them</em>, rather than by expressly calling for validation.
* You can set this option by calling XmlOptions.setValidateOnSet, then
* specifying the XmlOptions instance as a parameter when creating
* a new instance from schema or parsing an existing one.
*
* Note that it is also possible to validate instances from the
* command line by using tools you'll find in the bin directory of the
* XMLBeans distribution.
*/
public class Validation
{
private static XmlOptions m_validationOptions;
/**
* Receives a todo list XML instance, twice rendering it invalid
* and validating it using the XMLBeans API.
*
* @param args An array in which the first item is a
* path to the XML instance file.
*/
public static void main(String[] args)
{
Validation thisSample = new Validation();
// Use the validate method to validate an instance after
// updates.
boolean isValidAfterChanges = thisSample.isValidAfterChanges(args[0]);
// Use the VALIDATE_ON_SET option to validate an instance
// as updates are made.
boolean isValidOnTheFly = thisSample.isValidOnTheFly(args[0]);
}
/**
* Illustrates use of the validate method by making changes to incoming
* XML that invalidate the XML, then validating the instance and
* printing resulting error messages.
*
* Because this code is designed to generate invalid XML, it
* returns false when successful.
*
* @param xmlPath A path to the XML instance file.
* @return <code>true if the XML is valid after changes;
* otherwise, <code>false</code>.
*/
public boolean isValidAfterChanges(String xmlPath)
{
System.out.println("Validating after changes: \n");
// Set up the validation error listener.
ArrayList validationErrors = new ArrayList();
m_validationOptions = new XmlOptions();
m_validationOptions.setErrorListener(validationErrors);
TodolistDocument todoList = (TodolistDocument)parseXml(xmlPath, null);
// Schema defines the <name> element as required (minOccurs = '1').
// So this statement renders the XML invalid because it sets the
// <name> element to nil.
todoList.getTodolist().getItemArray(0).setName(null);
// During validation, errors are added to the ArrayList for
// retrieval and printing by the printErrors method.
boolean isValid = todoList.validate(m_validationOptions);
if (!isValid)
{
printErrors(validationErrors);
}
return isValid;
}
/**
* Illustrates the "validate on set" feature, which validates XML
* for simple types on the fly. As XML for those types is "set" through
* accessors generated by compiling schema, XMLBeans checks the XML's
* validity. The code here uses generated types to retrieve the first
* <item> in a <todolist>, then update the <item>'s id attribute. The code
* throws an exception when it tries to set an id attribute value that
* is too high.
*
* Because this code is designed to generate invalid XML, it
* returns false when successful.
*
* @param xmlPath A path to the XML instance file.
* @return <code>true</code> if valid XML is successfully created;
* otherwise, <code>false</code>.
*/
public boolean isValidOnTheFly(String xmlPath)
{
System.out.println("Validating on-the-fly: \n");
m_validationOptions = new XmlOptions();
m_validationOptions.setValidateOnSet();
TodolistDocument todoList = (TodolistDocument)parseXml(xmlPath, m_validationOptions);
Todolist list = todoList.getTodolist();
ItemType firstItem = list.getItemArray(0);
// Schema defines the <id> element as allowing values up to 100. So
// this line throws an exception because it invalidates the XML the
// code is updating.
firstItem.setId(8587);
// This line will not be reached.
return todoList.validate();
}
/**
* Receives the collection containing errors found during
* validation and print the errors to the console.
*
* @param validationErrors The validation errors.
*/
public void printErrors(ArrayList validationErrors)
{
System.out.println("Errors discovered during validation: \n");
Iterator iter = validationErrors.iterator();
while (iter.hasNext())
{
System.out.println(">> " + iter.next() + "\n");
}
}
/**
* <p>Creates a File from the XML path provided in main arguments, then
* parses the file's contents into a type generated from schema.</p>
* <p/>
* <p>Note that this work might have been done in main. Isolating it here
* makes the code separately available from outside this class.</p>
*
* @param xmlFilePath A path to XML based on the schema in inventory.xsd.
* @return An instance of a generated schema type that contains the parsed
* XML.
*/
public XmlObject parseXml(String xmlFilePath, XmlOptions validationOptions)
{
File xmlFile = new File(xmlFilePath);
XmlObject xml = null;
try
{
xml = XmlObject.Factory.parse(xmlFile, validationOptions);
} catch (XmlException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return xml;
}
}

View File

@@ -0,0 +1,43 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.validation;
import org.apache.xmlbeans.samples.validation.Validation;
/**
* A class with which to test the Validation sample.
*/
public class ValidationTest
{
/**
* Tests the Validation sample.
*/
public static void main(String[] args)
{
// all we're checking for is that the sample doesn't throw anything.
// a real sample test might assert something more interesting.
Validation sample = new Validation();
// Use the validate method to validate an instance after
// updates.
boolean isValidAfterChanges = sample.isValidAfterChanges(args[0]);
assert !isValidAfterChanges;
// Use the VALIDATE_ON_SET option to validate an instance
// as updates are made.
boolean isValidOnTheFly = sample.isValidOnTheFly(args[0]);
assert !isValidOnTheFly;
}
}

View File

@@ -0,0 +1,170 @@
/*
* XML Type: actionType
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.ActionType
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist;
/**
* An XML actionType(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is an atomic type that is a restriction of org.apache.xmlbeans.XmlString.
*/
public interface ActionType extends org.apache.xmlbeans.XmlString
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s59A663BF38731BA9F8026B121E40FDD3.TypeSystemHolder.typeSystem.resolveHandle("actiontype5fa0type");
org.apache.xmlbeans.StringEnumAbstractBase enumValue();
void set(org.apache.xmlbeans.StringEnumAbstractBase e);
static final Enum DO = Enum.forString("do");
static final Enum DELEGATE = Enum.forString("delegate");
static final Enum SOMEDAY_MAYBE_DEFER = Enum.forString("someday_maybe_defer");
static final Enum TOSS = Enum.forString("toss");
static final Enum INCUBATE = Enum.forString("incubate");
static final Enum FILE = Enum.forString("file");
static final int INT_DO = Enum.INT_DO;
static final int INT_DELEGATE = Enum.INT_DELEGATE;
static final int INT_SOMEDAY_MAYBE_DEFER = Enum.INT_SOMEDAY_MAYBE_DEFER;
static final int INT_TOSS = Enum.INT_TOSS;
static final int INT_INCUBATE = Enum.INT_INCUBATE;
static final int INT_FILE = Enum.INT_FILE;
/**
* Enumeration value class for org.apache.xmlbeans.samples.validation.todolist.ActionType.
* These enum values can be used as follows:
* <pre>
* enum.toString(); // returns the string value of the enum
* enum.intValue(); // returns an int value, useful for switches
* // e.g., case Enum.INT_DO
* Enum.forString(s); // returns the enum value for a string
* Enum.forInt(i); // returns the enum value for an int
* </pre>
* Enumeration objects are immutable singleton objects that
* can be compared using == object equality. They have no
* public constructor. See the constants defined within this
* class for all the valid values.
*/
static final class Enum extends org.apache.xmlbeans.StringEnumAbstractBase
{
/**
* Returns the enum value for a string, or null if none.
*/
public static Enum forString(java.lang.String s)
{ return (Enum)table.forString(s); }
/**
* Returns the enum value corresponding to an int, or null if none.
*/
public static Enum forInt(int i)
{ return (Enum)table.forInt(i); }
private Enum(java.lang.String s, int i)
{ super(s, i); }
static final int INT_DO = 1;
static final int INT_DELEGATE = 2;
static final int INT_SOMEDAY_MAYBE_DEFER = 3;
static final int INT_TOSS = 4;
static final int INT_INCUBATE = 5;
static final int INT_FILE = 6;
public static final org.apache.xmlbeans.StringEnumAbstractBase.Table table =
new org.apache.xmlbeans.StringEnumAbstractBase.Table
(
new Enum[]
{
new Enum("do", INT_DO),
new Enum("delegate", INT_DELEGATE),
new Enum("someday_maybe_defer", INT_SOMEDAY_MAYBE_DEFER),
new Enum("toss", INT_TOSS),
new Enum("incubate", INT_INCUBATE),
new Enum("file", INT_FILE),
}
);
private static final long serialVersionUID = 1L;
private java.lang.Object readResolve() { return forInt(intValue()); }
}
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.validation.todolist.ActionType newValue(java.lang.Object obj) {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) type.newValue( obj ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType newInstance() {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
/** @param xmlAsString the string value to parse */
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.lang.String xmlAsString, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, options ); }
/** @param file the file from which to load an xml document */
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.io.File file) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.io.File file, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.net.URL u) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.net.URL u, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.io.InputStream is) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.io.InputStream is, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.io.Reader r) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(java.io.Reader r, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(javax.xml.stream.XMLStreamReader sr) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(javax.xml.stream.XMLStreamReader sr, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(org.w3c.dom.Node node) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(org.w3c.dom.Node node, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.ActionType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.ActionType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, options ); }
private Factory() { } // No instance of this class allowed
}
}

View File

@@ -0,0 +1,98 @@
/*
* XML Type: idType
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.IdType
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist;
/**
* An XML idType(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is an atomic type that is a restriction of org.apache.xmlbeans.XmlInt.
*/
public interface IdType extends org.apache.xmlbeans.XmlInt
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s59A663BF38731BA9F8026B121E40FDD3.TypeSystemHolder.typeSystem.resolveHandle("idtypef11btype");
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.validation.todolist.IdType newValue(java.lang.Object obj) {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) type.newValue( obj ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType newInstance() {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
/** @param xmlAsString the string value to parse */
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.lang.String xmlAsString, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, options ); }
/** @param file the file from which to load an xml document */
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.io.File file) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.io.File file, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.net.URL u) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.net.URL u, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.io.InputStream is) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.io.InputStream is, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.io.Reader r) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(java.io.Reader r, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(javax.xml.stream.XMLStreamReader sr) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(javax.xml.stream.XMLStreamReader sr, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(org.w3c.dom.Node node) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(org.w3c.dom.Node node, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.IdType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.IdType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, options ); }
private Factory() { } // No instance of this class allowed
}
}

View File

@@ -0,0 +1,225 @@
/*
* XML Type: itemType
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.ItemType
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist;
/**
* An XML itemType(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is a complex type.
*/
public interface ItemType extends org.apache.xmlbeans.XmlObject
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s59A663BF38731BA9F8026B121E40FDD3.TypeSystemHolder.typeSystem.resolveHandle("itemtypeb663type");
/**
* Gets the "name" element
*/
java.lang.String getName();
/**
* Gets (as xml) the "name" element
*/
org.apache.xmlbeans.XmlString xgetName();
/**
* Sets the "name" element
*/
void setName(java.lang.String name);
/**
* Sets (as xml) the "name" element
*/
void xsetName(org.apache.xmlbeans.XmlString name);
/**
* Gets the "description" element
*/
java.lang.String getDescription();
/**
* Gets (as xml) the "description" element
*/
org.apache.xmlbeans.XmlString xgetDescription();
/**
* True if has "description" element
*/
boolean isSetDescription();
/**
* Sets the "description" element
*/
void setDescription(java.lang.String description);
/**
* Sets (as xml) the "description" element
*/
void xsetDescription(org.apache.xmlbeans.XmlString description);
/**
* Unsets the "description" element
*/
void unsetDescription();
/**
* Gets the "due_by" element
*/
java.util.Calendar getDueBy();
/**
* Gets (as xml) the "due_by" element
*/
org.apache.xmlbeans.XmlDateTime xgetDueBy();
/**
* True if has "due_by" element
*/
boolean isSetDueBy();
/**
* Sets the "due_by" element
*/
void setDueBy(java.util.Calendar dueBy);
/**
* Sets (as xml) the "due_by" element
*/
void xsetDueBy(org.apache.xmlbeans.XmlDateTime dueBy);
/**
* Unsets the "due_by" element
*/
void unsetDueBy();
/**
* Gets the "action" element
*/
org.apache.xmlbeans.samples.validation.todolist.ActionType.Enum getAction();
/**
* Gets (as xml) the "action" element
*/
org.apache.xmlbeans.samples.validation.todolist.ActionType xgetAction();
/**
* Sets the "action" element
*/
void setAction(org.apache.xmlbeans.samples.validation.todolist.ActionType.Enum action);
/**
* Sets (as xml) the "action" element
*/
void xsetAction(org.apache.xmlbeans.samples.validation.todolist.ActionType action);
/**
* Gets the "id" attribute
*/
int getId();
/**
* Gets (as xml) the "id" attribute
*/
org.apache.xmlbeans.samples.validation.todolist.IdType xgetId();
/**
* True if has "id" attribute
*/
boolean isSetId();
/**
* Sets the "id" attribute
*/
void setId(int id);
/**
* Sets (as xml) the "id" attribute
*/
void xsetId(org.apache.xmlbeans.samples.validation.todolist.IdType id);
/**
* Unsets the "id" attribute
*/
void unsetId();
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.validation.todolist.ItemType newInstance() {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
/** @param xmlAsString the string value to parse */
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.lang.String xmlAsString, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, options ); }
/** @param file the file from which to load an xml document */
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.io.File file) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.io.File file, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.net.URL u) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.net.URL u, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.io.InputStream is) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.io.InputStream is, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.io.Reader r) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(java.io.Reader r, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(javax.xml.stream.XMLStreamReader sr) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(javax.xml.stream.XMLStreamReader sr, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(org.w3c.dom.Node node) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(org.w3c.dom.Node node, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.ItemType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.ItemType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, options ); }
private Factory() { } // No instance of this class allowed
}
}

View File

@@ -0,0 +1,98 @@
/*
* XML Type: nameType
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.NameType
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist;
/**
* An XML nameType(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is an atomic type that is a restriction of org.apache.xmlbeans.XmlString.
*/
public interface NameType extends org.apache.xmlbeans.XmlString
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s59A663BF38731BA9F8026B121E40FDD3.TypeSystemHolder.typeSystem.resolveHandle("nametypeabebtype");
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.validation.todolist.NameType newValue(java.lang.Object obj) {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) type.newValue( obj ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType newInstance() {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
/** @param xmlAsString the string value to parse */
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.lang.String xmlAsString, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, options ); }
/** @param file the file from which to load an xml document */
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.io.File file) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.io.File file, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.net.URL u) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.net.URL u, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.io.InputStream is) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.io.InputStream is, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.io.Reader r) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(java.io.Reader r, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(javax.xml.stream.XMLStreamReader sr) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(javax.xml.stream.XMLStreamReader sr, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(org.w3c.dom.Node node) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(org.w3c.dom.Node node, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.NameType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.NameType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, options ); }
private Factory() { } // No instance of this class allowed
}
}

View File

@@ -0,0 +1,177 @@
/*
* An XML document type.
* Localname: todolist
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.TodolistDocument
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist;
/**
* A document containing one todolist(@http://xmlbeans.apache.org/samples/validation/todolist) element.
*
* This is a complex type.
*/
public interface TodolistDocument extends org.apache.xmlbeans.XmlObject
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s59A663BF38731BA9F8026B121E40FDD3.TypeSystemHolder.typeSystem.resolveHandle("todolist637cdoctype");
/**
* Gets the "todolist" element
*/
org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist getTodolist();
/**
* Sets the "todolist" element
*/
void setTodolist(org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist todolist);
/**
* Appends and returns a new empty "todolist" element
*/
org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist addNewTodolist();
/**
* An XML todolist(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is a complex type.
*/
public interface Todolist extends org.apache.xmlbeans.XmlObject
{
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)schema.system.s59A663BF38731BA9F8026B121E40FDD3.TypeSystemHolder.typeSystem.resolveHandle("todolist39fcelemtype");
/**
* Gets array of all "item" elements
*/
org.apache.xmlbeans.samples.validation.todolist.ItemType[] getItemArray();
/**
* Gets ith "item" element
*/
org.apache.xmlbeans.samples.validation.todolist.ItemType getItemArray(int i);
/**
* Returns number of "item" element
*/
int sizeOfItemArray();
/**
* Sets array of all "item" element
*/
void setItemArray(org.apache.xmlbeans.samples.validation.todolist.ItemType[] itemArray);
/**
* Sets ith "item" element
*/
void setItemArray(int i, org.apache.xmlbeans.samples.validation.todolist.ItemType item);
/**
* Inserts and returns a new empty value (as xml) as the ith "item" element
*/
org.apache.xmlbeans.samples.validation.todolist.ItemType insertNewItem(int i);
/**
* Appends and returns a new empty value (as xml) as the last "item" element
*/
org.apache.xmlbeans.samples.validation.todolist.ItemType addNewItem();
/**
* Removes the ith "item" element
*/
void removeItem(int i);
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist newInstance() {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
private Factory() { } // No instance of this class allowed
}
}
/**
* A factory class with static methods for creating instances
* of this type.
*/
public static final class Factory
{
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument newInstance() {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, options ); }
/** @param xmlAsString the string value to parse */
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.lang.String xmlAsString, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, options ); }
/** @param file the file from which to load an xml document */
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.io.File file) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.io.File file, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( file, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.net.URL u) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.net.URL u, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( u, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.io.InputStream is) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.io.InputStream is, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.io.Reader r) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(java.io.Reader r, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( r, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(javax.xml.stream.XMLStreamReader sr) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(javax.xml.stream.XMLStreamReader sr, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( sr, type, options ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(org.w3c.dom.Node node) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, null ); }
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(org.w3c.dom.Node node, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( node, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.samples.validation.todolist.TodolistDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xis, type, options ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, null ); }
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis, org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream( xis, type, options ); }
private Factory() { } // No instance of this class allowed
}
}

View File

@@ -0,0 +1,26 @@
/*
* XML Type: actionType
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.ActionType
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist.impl;
/**
* An XML actionType(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is an atomic type that is a restriction of org.apache.xmlbeans.XmlString.
*/
public class ActionTypeImpl extends org.apache.xmlbeans.impl.values.JavaStringEnumerationHolderEx implements org.apache.xmlbeans.samples.validation.todolist.ActionType
{
public ActionTypeImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType, false);
}
protected ActionTypeImpl(org.apache.xmlbeans.SchemaType sType, boolean b)
{
super(sType, b);
}
}

View File

@@ -0,0 +1,26 @@
/*
* XML Type: idType
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.IdType
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist.impl;
/**
* An XML idType(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is an atomic type that is a restriction of org.apache.xmlbeans.XmlInt.
*/
public class IdTypeImpl extends org.apache.xmlbeans.impl.values.JavaIntHolderEx implements org.apache.xmlbeans.samples.validation.todolist.IdType
{
public IdTypeImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType, false);
}
protected IdTypeImpl(org.apache.xmlbeans.SchemaType sType, boolean b)
{
super(sType, b);
}
}

View File

@@ -0,0 +1,445 @@
/*
* XML Type: itemType
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.ItemType
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist.impl;
/**
* An XML itemType(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is a complex type.
*/
public class ItemTypeImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.apache.xmlbeans.samples.validation.todolist.ItemType
{
public ItemTypeImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName NAME$0 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/validation/todolist", "name");
private static final javax.xml.namespace.QName DESCRIPTION$2 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/validation/todolist", "description");
private static final javax.xml.namespace.QName DUEBY$4 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/validation/todolist", "due_by");
private static final javax.xml.namespace.QName ACTION$6 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/validation/todolist", "action");
private static final javax.xml.namespace.QName ID$8 =
new javax.xml.namespace.QName("", "id");
/**
* Gets the "name" element
*/
public java.lang.String getName()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(NAME$0, 0);
if (target == null)
{
return null;
}
return target.getStringValue();
}
}
/**
* Gets (as xml) the "name" element
*/
public org.apache.xmlbeans.XmlString xgetName()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(NAME$0, 0);
return target;
}
}
/**
* Sets the "name" element
*/
public void setName(java.lang.String name)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(NAME$0, 0);
if (target == null)
{
target = (org.apache.xmlbeans.SimpleValue)get_store().add_element_user(NAME$0);
}
target.setStringValue(name);
}
}
/**
* Sets (as xml) the "name" element
*/
public void xsetName(org.apache.xmlbeans.XmlString name)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(NAME$0, 0);
if (target == null)
{
target = (org.apache.xmlbeans.XmlString)get_store().add_element_user(NAME$0);
}
target.set(name);
}
}
/**
* Gets the "description" element
*/
public java.lang.String getDescription()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(DESCRIPTION$2, 0);
if (target == null)
{
return null;
}
return target.getStringValue();
}
}
/**
* Gets (as xml) the "description" element
*/
public org.apache.xmlbeans.XmlString xgetDescription()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(DESCRIPTION$2, 0);
return target;
}
}
/**
* True if has "description" element
*/
public boolean isSetDescription()
{
synchronized (monitor())
{
check_orphaned();
return get_store().count_elements(DESCRIPTION$2) != 0;
}
}
/**
* Sets the "description" element
*/
public void setDescription(java.lang.String description)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(DESCRIPTION$2, 0);
if (target == null)
{
target = (org.apache.xmlbeans.SimpleValue)get_store().add_element_user(DESCRIPTION$2);
}
target.setStringValue(description);
}
}
/**
* Sets (as xml) the "description" element
*/
public void xsetDescription(org.apache.xmlbeans.XmlString description)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlString target = null;
target = (org.apache.xmlbeans.XmlString)get_store().find_element_user(DESCRIPTION$2, 0);
if (target == null)
{
target = (org.apache.xmlbeans.XmlString)get_store().add_element_user(DESCRIPTION$2);
}
target.set(description);
}
}
/**
* Unsets the "description" element
*/
public void unsetDescription()
{
synchronized (monitor())
{
check_orphaned();
get_store().remove_element(DESCRIPTION$2, 0);
}
}
/**
* Gets the "due_by" element
*/
public java.util.Calendar getDueBy()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(DUEBY$4, 0);
if (target == null)
{
return null;
}
return target.getCalendarValue();
}
}
/**
* Gets (as xml) the "due_by" element
*/
public org.apache.xmlbeans.XmlDateTime xgetDueBy()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlDateTime target = null;
target = (org.apache.xmlbeans.XmlDateTime)get_store().find_element_user(DUEBY$4, 0);
return target;
}
}
/**
* True if has "due_by" element
*/
public boolean isSetDueBy()
{
synchronized (monitor())
{
check_orphaned();
return get_store().count_elements(DUEBY$4) != 0;
}
}
/**
* Sets the "due_by" element
*/
public void setDueBy(java.util.Calendar dueBy)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(DUEBY$4, 0);
if (target == null)
{
target = (org.apache.xmlbeans.SimpleValue)get_store().add_element_user(DUEBY$4);
}
target.setCalendarValue(dueBy);
}
}
/**
* Sets (as xml) the "due_by" element
*/
public void xsetDueBy(org.apache.xmlbeans.XmlDateTime dueBy)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.XmlDateTime target = null;
target = (org.apache.xmlbeans.XmlDateTime)get_store().find_element_user(DUEBY$4, 0);
if (target == null)
{
target = (org.apache.xmlbeans.XmlDateTime)get_store().add_element_user(DUEBY$4);
}
target.set(dueBy);
}
}
/**
* Unsets the "due_by" element
*/
public void unsetDueBy()
{
synchronized (monitor())
{
check_orphaned();
get_store().remove_element(DUEBY$4, 0);
}
}
/**
* Gets the "action" element
*/
public org.apache.xmlbeans.samples.validation.todolist.ActionType.Enum getAction()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(ACTION$6, 0);
if (target == null)
{
return null;
}
return (org.apache.xmlbeans.samples.validation.todolist.ActionType.Enum)target.getEnumValue();
}
}
/**
* Gets (as xml) the "action" element
*/
public org.apache.xmlbeans.samples.validation.todolist.ActionType xgetAction()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.ActionType target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.ActionType)get_store().find_element_user(ACTION$6, 0);
return target;
}
}
/**
* Sets the "action" element
*/
public void setAction(org.apache.xmlbeans.samples.validation.todolist.ActionType.Enum action)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(ACTION$6, 0);
if (target == null)
{
target = (org.apache.xmlbeans.SimpleValue)get_store().add_element_user(ACTION$6);
}
target.setEnumValue(action);
}
}
/**
* Sets (as xml) the "action" element
*/
public void xsetAction(org.apache.xmlbeans.samples.validation.todolist.ActionType action)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.ActionType target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.ActionType)get_store().find_element_user(ACTION$6, 0);
if (target == null)
{
target = (org.apache.xmlbeans.samples.validation.todolist.ActionType)get_store().add_element_user(ACTION$6);
}
target.set(action);
}
}
/**
* Gets the "id" attribute
*/
public int getId()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_attribute_user(ID$8);
if (target == null)
{
return 0;
}
return target.getIntValue();
}
}
/**
* Gets (as xml) the "id" attribute
*/
public org.apache.xmlbeans.samples.validation.todolist.IdType xgetId()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.IdType target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.IdType)get_store().find_attribute_user(ID$8);
return target;
}
}
/**
* True if has "id" attribute
*/
public boolean isSetId()
{
synchronized (monitor())
{
check_orphaned();
return get_store().find_attribute_user(ID$8) != null;
}
}
/**
* Sets the "id" attribute
*/
public void setId(int id)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue)get_store().find_attribute_user(ID$8);
if (target == null)
{
target = (org.apache.xmlbeans.SimpleValue)get_store().add_attribute_user(ID$8);
}
target.setIntValue(id);
}
}
/**
* Sets (as xml) the "id" attribute
*/
public void xsetId(org.apache.xmlbeans.samples.validation.todolist.IdType id)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.IdType target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.IdType)get_store().find_attribute_user(ID$8);
if (target == null)
{
target = (org.apache.xmlbeans.samples.validation.todolist.IdType)get_store().add_attribute_user(ID$8);
}
target.set(id);
}
}
/**
* Unsets the "id" attribute
*/
public void unsetId()
{
synchronized (monitor())
{
check_orphaned();
get_store().remove_attribute(ID$8);
}
}
}

View File

@@ -0,0 +1,26 @@
/*
* XML Type: nameType
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.NameType
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist.impl;
/**
* An XML nameType(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is an atomic type that is a restriction of org.apache.xmlbeans.XmlString.
*/
public class NameTypeImpl extends org.apache.xmlbeans.impl.values.JavaStringHolderEx implements org.apache.xmlbeans.samples.validation.todolist.NameType
{
public NameTypeImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType, false);
}
protected NameTypeImpl(org.apache.xmlbeans.SchemaType sType, boolean b)
{
super(sType, b);
}
}

View File

@@ -0,0 +1,209 @@
/*
* An XML document type.
* Localname: todolist
* Namespace: http://xmlbeans.apache.org/samples/validation/todolist
* Java type: org.apache.xmlbeans.samples.validation.todolist.TodolistDocument
*
* Automatically generated - do not modify.
*/
package org.apache.xmlbeans.samples.validation.todolist.impl;
/**
* A document containing one todolist(@http://xmlbeans.apache.org/samples/validation/todolist) element.
*
* This is a complex type.
*/
public class TodolistDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.apache.xmlbeans.samples.validation.todolist.TodolistDocument
{
public TodolistDocumentImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName TODOLIST$0 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/validation/todolist", "todolist");
/**
* Gets the "todolist" element
*/
public org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist getTodolist()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist)get_store().find_element_user(TODOLIST$0, 0);
if (target == null)
{
return null;
}
return target;
}
}
/**
* Sets the "todolist" element
*/
public void setTodolist(org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist todolist)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist)get_store().find_element_user(TODOLIST$0, 0);
if (target == null)
{
target = (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist)get_store().add_element_user(TODOLIST$0);
}
target.set(todolist);
}
}
/**
* Appends and returns a new empty "todolist" element
*/
public org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist addNewTodolist()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist)get_store().add_element_user(TODOLIST$0);
return target;
}
}
/**
* An XML todolist(@http://xmlbeans.apache.org/samples/validation/todolist).
*
* This is a complex type.
*/
public static class TodolistImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.apache.xmlbeans.samples.validation.todolist.TodolistDocument.Todolist
{
public TodolistImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName ITEM$0 =
new javax.xml.namespace.QName("http://xmlbeans.apache.org/samples/validation/todolist", "item");
/**
* Gets array of all "item" elements
*/
public org.apache.xmlbeans.samples.validation.todolist.ItemType[] getItemArray()
{
synchronized (monitor())
{
check_orphaned();
java.util.List targetList = new java.util.ArrayList();
get_store().find_all_element_users(ITEM$0, targetList);
org.apache.xmlbeans.samples.validation.todolist.ItemType[] result = new org.apache.xmlbeans.samples.validation.todolist.ItemType[targetList.size()];
targetList.toArray(result);
return result;
}
}
/**
* Gets ith "item" element
*/
public org.apache.xmlbeans.samples.validation.todolist.ItemType getItemArray(int i)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.ItemType target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.ItemType)get_store().find_element_user(ITEM$0, i);
if (target == null)
{
throw new IndexOutOfBoundsException();
}
return target;
}
}
/**
* Returns number of "item" element
*/
public int sizeOfItemArray()
{
synchronized (monitor())
{
check_orphaned();
return get_store().count_elements(ITEM$0);
}
}
/**
* Sets array of all "item" element
*/
public void setItemArray(org.apache.xmlbeans.samples.validation.todolist.ItemType[] itemArray)
{
synchronized (monitor())
{
check_orphaned();
arraySetterHelper(itemArray, ITEM$0);
}
}
/**
* Sets ith "item" element
*/
public void setItemArray(int i, org.apache.xmlbeans.samples.validation.todolist.ItemType item)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.ItemType target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.ItemType)get_store().find_element_user(ITEM$0, i);
if (target == null)
{
throw new IndexOutOfBoundsException();
}
target.set(item);
}
}
/**
* Inserts and returns a new empty value (as xml) as the ith "item" element
*/
public org.apache.xmlbeans.samples.validation.todolist.ItemType insertNewItem(int i)
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.ItemType target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.ItemType)get_store().insert_element_user(ITEM$0, i);
return target;
}
}
/**
* Appends and returns a new empty value (as xml) as the last "item" element
*/
public org.apache.xmlbeans.samples.validation.todolist.ItemType addNewItem()
{
synchronized (monitor())
{
check_orphaned();
org.apache.xmlbeans.samples.validation.todolist.ItemType target = null;
target = (org.apache.xmlbeans.samples.validation.todolist.ItemType)get_store().add_element_user(ITEM$0);
return target;
}
}
/**
* Removes the ith "item" element
*/
public void removeItem(int i)
{
synchronized (monitor())
{
check_orphaned();
get_store().remove_element(ITEM$0, i);
}
}
}
}

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<todolist xmlns="http://xmlbeans.apache.org/samples/validation/todolist">
<item id="001">
<name>Buy a south Pacific island.</name>
<description>Contingent on inheriting lots of money.</description>
<due_by>2005-05-01T23:36:28</due_by>
<action>someday_maybe_defer</action>
</item>
<item id="002">
<name>Get that new PowerBook I've been eyeing.</name>
<description>Resulting productivity increase will be exponential!</description>
<due_by>2005-05-01T23:36:28</due_by>
<action>do</action>
</item>
<item id="003">
<name>Clean the garage.</name>
<description>Remove at least enough junk so that my bicycle fits.</description>
<due_by>2005-05-30T23:36:28</due_by>
<action>delegate</action>
</item>
</todolist>

View File

@@ -0,0 +1,48 @@
Sample: XQueryXPath
Author: Steven Traut (straut@bea.com)
Last Updated: May 14, 2008
Versions:
xmlbeans-v1 1.0.3
xmlbeans-v2 2.4.0
-----------------------------------------------------------------------------
This sample illustrates how you can use the XMLBeans API to execute
XPath and XQuery expressions. The sample illustrates these features:
- Using the XmlObject.selectPath and XmlCursor.selectPath methods
to execute XPath expressions. The selectPath method's results (if
any) are always chunks of the instance queried against. In other
words, changes to query results change the original instance.
However, you work with results differently depending on whether
selectPath was called from an XmlObject or XmlCursor instance. See
the SelectPath class for more information.
- Using the XmlObject.execQuery and XmlCursor.execQuery methods
to execute XQuery expressions. Results of these queries are copied
into new XML, meaning that changes to results do not change the
original instance. Here again, you work with results differently
depending how which method you used to query. See the ExecQuery
class for more information.
A note about dependencies. Very simple XPath expressions -- e.g.,
expressions without predicates or function calls -- require only
the xbean.jar on your class path. More complex XPath expressions
and XQuery expressions require an XPath/XQuery engine, such as
Saxon. XMLBeans 2.4.0 supports the use of Saxon 9. Two Saxon jars,
saxon9.jar and saxon9-dom.jar, as well as xbean_xpath.jar, are
required on the classpath for code in this sample to run.
These jars are created in the build/lib directory if you build
XMLBeans from Apache source.
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. xbean_xpath.jar, saxon9.jar, and saxon9-dom.jar must be on your
classpath.
These files are created in the build/lib directory when you
build XMLBeans from source.
4. To compile the schemas and sample source, run "ant build"
5. To execute the sample, run "ant run"

View File

@@ -0,0 +1,120 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="XQueryXPath" default="build">
<property environment="env"/>
<path id="XQueryXPath.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="*.jar"/>
<pathelement path="build/classes"/>
<pathelement path="${env.CLASSPATH}"/>
</path>
<target name="init">
<property name="xmlbeans.home" value="${env.XMLBEANS_HOME}"/>
<echo message="xmlbeans.home: ${xmlbeans.home}"/>
<!-- check for xbean.jar from binary distribution -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/lib"
file="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/build/lib"
file="${xmlbeans.home}/build/lib/xbean.jar" />
<fail message="Set XMLBEANS_HOME in your environment."
unless="xmlbeans.lib"/>
<echo message="xmlbeans.lib: ${xmlbeans.lib}"/>
<path id="xmlbeans.path">
<fileset dir="${xmlbeans.lib}" includes="*.jar"/>
</path>
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpathref="xmlbeans.path"/>
</target>
<!-- ========================== clean ==== -->
<target name="clean">
<delete dir="build"/>
</target>
<!-- ========================== build ==== -->
<target name="build" depends="init,schemas.jar,XQueryXPath.classes">
</target>
<target name="schemas.check">
<uptodate property="schemas.notRequired"
targetfile="build/lib/schemas.jar">
<srcfiles dir="schemas" includes="**/*.xsd"/>
</uptodate>
</target>
<target name="schemas.jar" depends="init,schemas.check"
unless="schemas.notRequired">
<mkdir dir="build/lib"/>
<xmlbean schema="schemas"
destfile="build/lib/schemas.jar"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="XQueryXPath.classes" depends="init">
<mkdir dir="build/classes"/>
<javac srcdir="src"
destdir="build/classes"
classpathref="XQueryXPath.path"
debug="on"
source="1.4"
/>
</target>
<!-- ========================== run ==== -->
<target name="run" depends="init,build">
<echo message="============================== running XQueryXPath"/>
<java
classname="org.apache.xmlbeans.samples.xquery.XQueryXPath"
classpathref="XQueryXPath.path"
fork="true">
<arg line="xml/employees.xml"/>
</java>
</target>
<!-- ========================== test ==== -->
<target name="test" depends="init,build">
<echo message="============================== testing XQueryXPath"/>
<java
classname="org.apache.xmlbeans.samples.xquery.XQueryXPathTest"
classpathref="XQueryXPath.path"
fork="true">
<arg line="xml/employees.xml"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://xmlbeans.apache.org/samples/xquery/employees"
xmlns="http://xmlbeans.apache.org/samples/xquery/employees">
<xs:element name="employees">
<xs:complexType>
<xs:sequence>
<xs:element name="employee" type="employeeType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="employeeType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="addressType" maxOccurs="unbounded"/>
<xs:element name="phone" type="phoneType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addressType">
<xs:sequence>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:NCName"/>
<xs:element name="state" type="xs:NCName"/>
<xs:element name="zip" type="xs:integer"/>
</xs:sequence>
<xs:attribute name="location" type="xs:NCName" use="required"/>
</xs:complexType>
<xs:complexType name="phoneType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="location" type="xs:NCName" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>

View File

@@ -0,0 +1,154 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.xquery;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
/**
* This class demonstrates how to use the execQuery method to execute XQuery
* expressions. Compare the code here with the code in the SelectPath class.
* That class uses the selectPath method to execute XPath expressions.
* <p/>
* You can call the execQuery method from either an XmlObject or XmlCursor
* instance. Calling from XmlObject returns an XmlObject array. Calling
* from XmlCursor returns a new XmlCursor instance positioned at the root
* of a fragment containing copies of the XML queried against. Results of the
* query (if any) are sibling children of the fragment's root.
*/
public class ExecQuery
{
final static String m_namespaceDeclaration =
"declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees';";
/**
* Uses XQuery to retrieve work <phone> elements from the incoming XML, then
* changes the number in the results.
*
* This method demonstrates the following characteristics of the execQuery method:
*
* - it supports XQuery.
* - the XML it returns is a copy of the XML queried against; contrast this with
* the selectPath method, which returns a portion of the original document.
* Changes to returned XML do not impact the XML queried against.
* - execQuery called from an XmlCursor returns a cursor positioned at
* the STARTDOC token of a new XML fragment. Contrast this with the
* XmlCursor.selectPath method, which stores results as "selections" in
* the cursor used to execute the query.
*
* @param empDoc The incoming XML.
* @return <code>true</code> if the XPath expression returned results;
* otherwise, <code>false</code>.
*/
public boolean updateWorkPhone(XmlObject empDoc)
{
boolean hasResults = false;
// A cursor instance to query with.
XmlCursor empCursor = empDoc.newCursor();
// The expression: Get the <employee> elements with <state> elements whose
// value is "WA".
String queryExpression =
"for $e in $this/xq:employees/xq:employee " +
"let $s := $e/xq:address/xq:state " +
"where $s = 'WA' " +
"return $e//xq:phone[@location='work']";
// Execute the query. Results, if any, will be available at
// the position of the resultCursor in a new XML document.
XmlCursor resultCursor =
empCursor.execQuery(m_namespaceDeclaration + queryExpression);
System.out.println("The query results, <phone> element copies made " +
"from the received document: \n");
System.out.println(resultCursor.getObject().toString() + "\n");
// If there are results, the results will be children of the fragment root
// where the new cursor is positioned. This statement tests for children
// and moves the cursor if to the first if it exists.
if (resultCursor.toFirstChild())
{
hasResults = true;
// Use the cursor to loop through the results, printing each sibling
// <employee> element returned by the query.
int i = 0;
do
{
// Change the phone numbers.
XmlCursor editCursor = resultCursor.newCursor();
editCursor.toLastAttribute();
editCursor.toNextToken();
editCursor.removeXml();
editCursor.insertChars("(206)555-1234");
} while (resultCursor.toNextSibling());
resultCursor.toStartDoc();
System.out.println("The query results after changes: \n");
System.out.println(resultCursor.getObject().toString() + "\n");
System.out.println("The received document -- note that it is unchanged. " +
"Changes were made to the copy created by the execQuery method. \n");
System.out.println(empDoc + "\n");
}
return hasResults;
}
/**
* Uses XQuery to retrieve work <zip> elements from the incoming XML, adding the
* elements as children to a <zip-list> element.
*
* This method demonstrates the following characteristics of the execQuery method:
*
* - it supports XQuery.
* - execQuery called from an XmlObject returns an array of XmlObject instances.
* These are bound to copies of the received XML.
*
* @param empDoc The incoming XML.
* @return <code>true</code> if the XPath expression returned results;
* otherwise, <code>false</code>.
*/
public boolean collectZips(XmlObject empDoc)
{
// The query is designed to return results, so return
// true if it does.
boolean hasResults = false;
// The expression: Get the <zip> elements and return them as children
// of a new <zip-list> element.
String queryExpression =
"let $e := $this/xq:employees " +
"return " +
"<zip-list> " +
"{for $z in $e/xq:employee/xq:address/xq:zip " +
"return $z} " +
"</zip-list>";
// Execute the query. Results will be copies of the XML queried against,
// stored as members of an XmlObject array.
XmlObject[] results =
empDoc.execQuery(m_namespaceDeclaration + queryExpression);
// Print the results.
if (results.length > 0)
{
hasResults = true;
System.out.println("The query results: \n");
System.out.println(results[0].toString() + "\n");
}
return hasResults;
}
}

View File

@@ -0,0 +1,172 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.xquery;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.samples.xquery.employees.PhoneType;
/**
* This class demonstrates how to use the selectPath method to execute XPath
* expressions. Compare the code here with the code in the ExecQuery class.
* That class uses the execQuery method to execute XQuery expressions.
* <p/>
* You can call the selectPath method from either an XmlObject or XmlCursor
* instance. Calling from XmlObject returns an XmlObject array. Calling
* from XmlCursor returns void, and you use methods of the cursor to
* navigate among returned "selections".
*/
public class SelectPath
{
// Declare a namespace corresponding to the namespace declared in the XML
// instance. The string here will be used as part of the XPath expression to
// ensure that the query finds namespace-qualified elements in the XML.
final static String m_namespaceDeclaration =
"declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees';";
/**
* Prints the XML bound to <em>empDoc</em>, uses XPath to
* retrieve elements containing work phone numbers, changes the numbers
* to another number, then prints the XML again to display the changes.
*
* This method demonstrates the following characteristics of the selectPath method:
*
* - it supports expressions that include predicates
* - the XML it returns is the XML queried against -- not a copy, as with results
* returned via execQuery methods and XQuery. Changes to this XML update
* the XML queried against.
* - selectPath called from an XMLBean type (instead of a cursor) returns an
* array of results (if any). These results can be cast to a matching type
* generated from schema.
*
* @param empDoc The incoming XML.
* @return <code>true</code> if the XPath expression returned results;
* otherwise, <code>false</code>.
*/
public boolean updateWorkPhone(XmlObject empDoc)
{
boolean hasResults = false;
// Print the XML received.
System.out.println("XML as received by updateWorkPhone method: \n\n"
+ empDoc.toString());
// Create a variable with the query expression.
String pathExpression =
"$this/xq:employees/xq:employee/xq:phone[@location='work']";
// Execute the query.
XmlObject[] results = empDoc.selectPath(m_namespaceDeclaration
+ pathExpression);
if (results.length > 0)
{
hasResults = true;
// <phone> elements returned from the expression will conform to the
// schema, so bind them to the appropriate XMLBeans type generated
// from the schema.
PhoneType[] phones = (PhoneType[]) results;
// Change all the work phone numbers to the same number.
for (int i = 0; i < phones.length; i++)
{
phones[i].setStringValue("(206)555-1234");
}
// Print the XML with updates.
System.out.println("\nXML as updated by updateWorkPhone method (each work \n" +
"phone number has been changed to the same number): \n\n"
+ empDoc.toString() + "\n");
}
return hasResults;
}
/**
* Uses the XPath text() function to get values from <name>
* elements in received XML, then collects those values as the value of a
* <names> element created here.
* <p/>
* Demonstrates the following characteristics of the selectPath method:
* <p/>
* - It supports expressions that include XPath function calls.
* - selectPath called from an XmlCursor instance (instead of an XMLBeans
* type) places results (if any) into the cursor's selection set.
*
* @param empDoc The incoming XML.
* @return <code>true</code> if the XPath expression returned results;
* otherwise, <code>false</code>.
*/
public boolean collectNames(XmlObject empDoc)
{
boolean hasResults = false;
// Create a cursor with which to execute query expressions. The cursor
// is inserted at the very beginning of the incoming XML, then moved to
// the first element's START token.
XmlCursor pathCursor = empDoc.newCursor();
pathCursor.toFirstChild();
// Execute the path expression, qualifying it with the namespace
// declaration.
pathCursor.selectPath(m_namespaceDeclaration
+ "$this//xq:employee/xq:name/text()");
// If there are results, then go ahead and do stuff.
if (pathCursor.getSelectionCount() > 0)
{
hasResults = true;
// Create a new <names> element into which names from the XML
// will be copied. Note that this element is in the default
// namespace; it's not part of the schema.
XmlObject namesElement = null;
try
{
namesElement = XmlObject.Factory.parse("<names/>");
} catch (XmlException e)
{
e.printStackTrace();
}
// Add a cursor the new element and put it between its START and END
// tokens, where new values can be inserted.
XmlCursor namesCursor = namesElement.newCursor();
namesCursor.toFirstContentToken();
namesCursor.toEndToken();
// Loop through the selections, appending the incoming <name> element's
// value to the new <name> element's value. (Of course, this could have
// been done with a StringBuffer, but that wouldn't show the cursor in
// use.)
while (pathCursor.toNextSelection())
{
namesCursor.insertChars(pathCursor.getTextValue());
if (pathCursor.hasNextSelection())
{
namesCursor.insertChars(", ");
}
}
// Dispose of the cursors now that they're not needed.
pathCursor.dispose();
namesCursor.dispose();
// Print the new element.
System.out.println("\nNames collected by collectNames method: \n\n"
+ namesElement + "\n");
}
return hasResults;
}
}

View File

@@ -0,0 +1,117 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.xquery;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import java.io.File;
import java.io.IOException;
/**
* A sample to XMLBeans API features for executing XPath and XQuery
* expressions. The sample illustrates these features:
*
* - Using the XmlObject.selectPath and XmlCursor.selectPath methods
* to execute XPath expressions. The selectPath method's results (if
* any) are always chunks of the instance queried against. In other
* words, changes to query results change the original instance.
* However, you work with results differently depending on whether
* selectPath was called from an XmlObject or XmlCursor instance. See
* the SelectPath class for more information.
* - Using the XmlObject.execQuery and XmlCursor.execQuery methods
* to execute XQuery expressions. Results of these queries are copied
* into new XML, meaning that changes to results do not change the
* original instance. Here again, you work with results differently
* depending how which method you used to query. See the ExecQuery
* class for more information.
*/
public class XQueryXPath
{
/**
* Receives an employees list XML instance, passing the instance to
* methods that execute queries against it.
*
* @param args An array in which the first item is a
* path to the XML instance file.
*/
public static void main(String[] args)
throws org.apache.xmlbeans.XmlException, java.io.IOException
{
XQueryXPath sample = new XQueryXPath();
sample.executeQueries(args);
}
/**
* Returns <code>true</code> if all of the sample methods returned true
* (i.e., their query expressions returned results).
*
* @param args An array in which the first item is a
* path to the XML instance file.
* @return <code>true</code> if all of the sample methods returned true
* (i.e., their query expressions returned results); otherwise,
* <code>false</code>.
*/
public boolean executeQueries(String[] args)
{
XmlObject xml = this.parseXml(args[0]);
// Execute the XQuery samples.
ExecQuery xquerySample = new ExecQuery();
System.out.println("Running ExecQuery.selectEmpsByStateCursor\n");
boolean xqWorkPhoneSuccessful = xquerySample.updateWorkPhone(xml);
System.out.println("Running ExecQuery.selectZipsNewDocCursor\n");
boolean xqCollectZips = xquerySample.collectZips(xml);
// Execute the XPath samples.
SelectPath xpathSample = new SelectPath();
System.out.println("Running SelectPath.updateWorkPhone \n");
boolean xpWorkPhoneSuccessful = xpathSample.updateWorkPhone(xml);
System.out.println("Running SelectPath.collectNames \n");
boolean xpCollectNames = xpathSample.collectNames(xml);
return (xqWorkPhoneSuccessful && xqCollectZips
&& xpWorkPhoneSuccessful && xpCollectNames) ? true : false;
}
/**
* <p>Creates a File from the XML path provided in main arguments, then
* parses the file's contents into a type generated from schema.</p>
* @param xmlFilePath A path to XML based on the schema in inventory.xsd.
* @return An instance of a generated schema type that contains the parsed
* XML.
*/
public XmlObject parseXml(String xmlFilePath)
{
File xmlFile = new File(xmlFilePath);
XmlObject xml = null;
try
{
xml = XmlObject.Factory.parse(xmlFile);
} catch (XmlException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return xml;
}
}

View File

@@ -0,0 +1,32 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.xquery;
/**
* A class with which to test the XQueryXPath sample.
*/
public class XQueryXPathTest
{
/**
* Tests the XQueryXPath sample.
*/
public static void main(String[] args)
throws org.apache.xmlbeans.XmlException, java.io.IOException
{
XQueryXPath sample = new XQueryXPath();
boolean queriesSuccessful = sample.executeQueries(args);
assert queriesSuccessful;
}
}

View File

@@ -0,0 +1,71 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<employees xmlns="http://xmlbeans.apache.org/samples/xquery/employees">
<employee>
<name>Fred Jones</name>
<address location="home">
<street>900 Aurora Ave.</street>
<city>Seattle</city>
<state>WA</state>
<zip>98115</zip>
</address>
<address location="work">
<street>2011 152nd Avenue NE</street>
<city>Redmond</city>
<state>WA</state>
<zip>98052</zip>
</address>
<phone location="work">(425)555-5665</phone>
<phone location="home">(206)555-5555</phone>
<phone location="mobile">(206)555-4321</phone>
</employee>
<employee>
<name>Sally Smith</name>
<address location="home">
<street>1430 Oak Place</street>
<city>Salem</city>
<state>OR</state>
<zip>97125</zip>
</address>
<address location="work">
<street>765 Main St.</street>
<city>Keizer</city>
<state>OR</state>
<zip>97303</zip>
</address>
<phone location="work">(503)555-3856</phone>
<phone location="home">(503)555-6951</phone>
<phone location="mobile">(503)555-5152</phone>
</employee>
<employee>
<name>Gladys Kravitz</name>
<address location="home">
<street>1313 Mockingbird Lane</street>
<city>Seattle</city>
<state>WA</state>
<zip>98115</zip>
</address>
<address location="work">
<street>2011 152nd Avenue NE</street>
<city>Redmond</city>
<state>WA</state>
<zip>98052</zip>
</address>
<phone location="work">(425)555-6897</phone>
<phone location="home">(206)555-6594</phone>
<phone location="mobile">(206)555-7894</phone>
</employee>
</employees>

View File

@@ -0,0 +1,41 @@
Sample: XSDConfig
Author: Rashmi Banthia (rjain29@gmail.com)
Last Updated: Oct. 18th, 2004
Versions:
xmlbeans-1.0.3
-----------------------------------------------------------------------------
This sample illustrates how you can specify package names to be used for xml
namespaces. You can also specify class names to be used for individual qualified names.
To customize the package names and the class names, you'll need to create .xsdconfig file.
For eg: "filename.xsdconfig"
Schema for xsdconfig can be obtained from XMLBeans source.
For this sample:
(1) The java class names generated without the XsdConfig are:
* org.apache.xmlbeans.samples.catalog.ArticleDocument
* org.apache.xmlbeans.samples.catalog.AVeryLongDescriptionElementDocument
* org.apache.xmlbeans.samples.catalog.CatalogDocument
* org.apache.xmlbeans.samples.catalog.JournalDocument
(CatalogXsd.java uses above mentioned classes)
(2) The java class names generated with XsdConfig are:
* com.catalog.XmlArticleDocumentBean
* com.catalog.XmlShortItemBean
* com.catalog.XmlCatalogDocumentBean
* com.catalog.XmlJournalDocumentBean
(CatalogXsdConfig.java uses above mentioned classes)
When you run this sample, you will see it print all the element values from XML document
instance (with and without XsdConfig file).
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. To compile the schemas and sample source, run "ant build"

View File

@@ -0,0 +1,175 @@
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="xsdconfig" default="build">
<property environment="env"/>
<path id="XsdConfig.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="schemas_xsdconfig.jar"/>
<pathelement path="build/classes"/>
</path>
<path id="Xsd.path">
<path refid="xmlbeans.path"/>
<fileset dir="build/lib" includes="schemas_xsd.jar"/>
<pathelement path="build/classes"/>
</path>
<target name="init">
<property name="xmlbeans.home" value="${env.XMLBEANS_HOME}"/>
<echo message="xmlbeans.home: ${xmlbeans.home}"/>
<!-- check for xbean.jar from binary distribution -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/lib"
file="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
<available
property="xmlbeans.lib"
value="${xmlbeans.home}/build/lib"
file="${xmlbeans.home}/build/lib/xbean.jar" />
<fail message="Set XMLBEANS_HOME in your enviornment."
unless="xmlbeans.lib"/>
<echo message="xmlbeans.lib: ${xmlbeans.lib}"/>
<path id="xmlbeans.path">
<fileset dir="${xmlbeans.lib}" includes="*.jar"/>
</path>
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpathref="xmlbeans.path"/>
</target>
<!-- ========================== clean ==== -->
<target name="clean">
<delete dir="build"/>
</target>
<!-- ========================== build ==== -->
<target name="build" depends="init,schemas_xsd.jar, schemas_xsdconfig.jar,XsdConfig.classes">
</target>
<target name="schemas_xsd.check">
<uptodate property="schemas_xsd.notRequired"
targetfile="build/lib/schemas_xsd.jar">
<srcfiles dir="schemas" includes="**/*.xsd"/>
</uptodate>
</target>
<target name="schemas_xsdconfig.check">
<uptodate property="schemas_xsdconfig.notRequired"
targetfile="build/lib/schemas_xsdconfig.jar">
<srcfiles dir="schemas" includes="**/*.xsd **/*.xsdconfig"/>
</uptodate>
</target>
<target name="schemas_xsdconfig.jar" depends="init,schemas_xsdconfig.check"
unless="schemas_xsdconfig.notRequired">
<mkdir dir="build/lib"/>
<!-- Generating with XSD and XsdConfig file -->
<xmlbean schema="schemas"
destfile="build/lib/schemas_xsdconfig.jar"
srcgendir="build/src/xsdconfig"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="schemas_xsd.jar" depends="init,schemas_xsd.check"
unless="schemas_xsd.notRequired">
<mkdir dir="build/lib"/>
<!-- Generating with XSD only (no config file) -->
<xmlbean schema="schemas/catalog.xsd"
destfile="build/lib/schemas_xsd.jar"
srcgendir="build/src/xsd"
classpathref="xmlbeans.path"
debug="on"
/>
</target>
<target name="XsdConfig.classes" depends="init">
<mkdir dir="build/classes"/>
<javac srcdir="src" includes="org/apache/xmlbeans/samples/xsdconfig/CatalogXsdConfig.java org/apache/xmlbeans/samples/xsdconfig/XsdConfigTest.java"
destdir="build/classes"
classpathref="XsdConfig.path"
debug="on"
source="1.4"
/>
<javac srcdir="src" includes="org/apache/xmlbeans/samples/xsdconfig/CatalogXsd.java org/apache/xmlbeans/samples/xsdconfig/XsdTest.java "
destdir="build/classes"
classpathref="Xsd.path"
debug="on"
source="1.4"
/>
</target>
<!-- ========================== run ==== -->
<target name="run" depends="init,build">
<echo message="============================== running Xsd Sample (With XSD only - no Config)"/>
<java
classname="org.apache.xmlbeans.samples.xsdconfig.CatalogXsd"
classpathref="Xsd.path"
fork="true">
<arg line="xml/catalog.xml"/>
</java>
<echo message="============================== running Xsd Sample (With XSD and XsdConfig)"/>
<java
classname="org.apache.xmlbeans.samples.xsdconfig.CatalogXsdConfig"
classpathref="XsdConfig.path"
fork="true">
<arg line="xml/catalog.xml"/>
</java>
</target>
<!-- ========================== test ==== -->
<target name="test" depends="init,build">
<echo message="============================== testing XsdTest"/>
<java
classname="org.apache.xmlbeans.samples.xsdconfig.XsdTest"
classpathref="Xsd.path"
fork="true">
<arg line="xml/catalog.xml"/>
</java>
<echo message="============================== testing XsdConfigTest"/>
<java
classname="org.apache.xmlbeans.samples.xsdconfig.XsdConfigTest"
classpathref="XsdConfig.path"
fork="true">
<arg line="xml/catalog.xml"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,57 @@
<!-- Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ct="http://xmlbeans.apache.org/samples/catalog"
targetNamespace="http://xmlbeans.apache.org/samples/catalog"
elementFormDefault="qualified"
>
<xs:element name="catalog">
<xs:complexType>
<xs:sequence>
<xs:element ref="ct:journal" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="journal">
<xs:complexType>
<xs:sequence>
<xs:element ref="ct:article" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="article">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="author" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="ct:a-very-long-description-element" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="a-very-long-description-element">
<xs:complexType>
<xs:sequence>
<xs:element name ="forsample" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@@ -0,0 +1,49 @@
<!-- Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config"
xmlns:ct="http://xmlbeans.apache.org/samples/catalog">
<!--
<namespace> element specifies configuration for namespace.
Attribute uri contains namespace list. <package> element specifies package name
to be used for types generated in this namespace.
-->
<xb:namespace uri="http://xmlbeans.apache.org/samples/catalog http://anotherurihere.org">
<xb:package>com.catalog</xb:package>
</xb:namespace>
<!-- ##any indicates all URIs.
A <prefix> is used to prepend to top-level Java type names generated in this namespace.
A <suffix> is used to append to top-level Java types names generated in this namespace.
The <prefix> and <suffix> are not used for inner Java type definitions.
-->
<xb:namespace uri="##any">
<xb:prefix>Xml</xb:prefix>
<xb:suffix>Bean</xb:suffix>
</xb:namespace>
<!--<qname> specifies a Java class name for a Qualified name -->
<xb:qname name="ct:forsample" javaname="GoodName" />
<xb:qname name="ct:a-very-long-description-element" javaname="XmlShortItemBean" />
</xb:config>

View File

@@ -0,0 +1,155 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.xsdconfig;
/*
*This class uses the auto generated package names and class names. It doesn't consider XsdConfig file.
*Note the difference between the imports in two files (CatalogXsdConfig.java and CatalogXsd.java)
*/
import org.apache.xmlbeans.samples.catalog.CatalogDocument;
import org.apache.xmlbeans.samples.catalog.JournalDocument;
import org.apache.xmlbeans.samples.catalog.ArticleDocument;
import org.apache.xmlbeans.samples.catalog.AVeryLongDescriptionElementDocument;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlError;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import java.util.ArrayList;
import java.io.IOException;
import java.io.File;
public class CatalogXsd
{
public static void main(String[] args)
{
// Create an instance of this class to work with.
CatalogXsd catalogxsd = new CatalogXsd();
// Create an instance of a type based on the received XML's schema
CatalogDocument catdoc = catalogxsd.parseXml(args[0]);
//Prints the element values from the XML.
catalogxsd.printElements(catdoc);
}
/**
* Creates a File from the XML path provided in main arguments, then
* parses the file's contents into a type (CatalogDocument) generated from schema.
*
* @param xmlFilePath A path to XML based on the schema in EasyPo.xsd
* @return An instance of a generated schema type (CatalogDocument) that contains the
* parsed XML.
*/
public CatalogDocument parseXml(String xmlFilePath)
{
File xmlfile = new File(xmlFilePath);
CatalogDocument catdoc = null;
try
{
catdoc = CatalogDocument.Factory.parse(xmlfile);
}
catch (XmlException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return catdoc;
}
/**
* This method prints all the element values in the given XML document based on Catalog.xsd
*/
public void printElements(CatalogDocument catdoc)
{
// Get object reference of root element.
CatalogDocument.Catalog catalogelement = catdoc.getCatalog();
//Get all <journal> element from the root element.
JournalDocument.Journal[] journalarray = catalogelement.getJournalArray();
//Loop through <journal> element array.
for (int i = 0; i < journalarray.length; i++)
{
//Retrieve all <article> elements within each <journal> element
ArticleDocument.Article[] articlearray = journalarray[i].getArticleArray();
//Loop through <article> array retrieved above
for (int j = 0; j < articlearray.length; j++)
{
System.out.println(articlearray[j].getTitle());
String[] str = articlearray[j].getAuthorArray();
for (int k = 0; k < str.length; k++)
System.out.println(str[k]);
//Note the method for retrieving <forsample> element.
System.out.println(articlearray[j].getAVeryLongDescriptionElement()
.getForsample());
}
}
System.out.println("\n\n\n");
}
/**
* <p>Validates the XML, printing error messages when the XML is invalid. Note
* that this method will properly validate any instance of a compiled schema
* type because all of these types extend XmlObject.</p>
* <p/>
* <p>Note that in actual practice, you'll probably want to use an assertion
* when validating if you want to ensure that your code doesn't pass along
* invalid XML. This sample prints the generated XML whether or not it's
* valid so that you can see the result in both cases.</p>
*
* @param xml The XML to validate.
* @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
*/
public static boolean validateXml(XmlObject xml)
{
boolean isXmlValid = false;
// A collection instance to hold validation error messages.
ArrayList validationMessages = new ArrayList();
// Validate the XML, collecting messages.
isXmlValid = xml.validate(
new XmlOptions().setErrorListener(validationMessages));
// If the XML isn't valid, print the messages.
if (!isXmlValid)
{
System.out.println("\nInvalid XML: ");
for (int i = 0; i < validationMessages.size(); i++)
{
XmlError error = (XmlError) validationMessages.get(i);
System.out.println(error.getMessage());
System.out.println(error.getObjectLocation());
}
}
return isXmlValid;
}
}

View File

@@ -0,0 +1,155 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.xsdconfig;
/**
*This class uses the package names and class names mentioned in XsdConfig.
*Note the difference between the imports in two files (CatalogXsdConfig.java and CatalogXsd.java)
*/
import com.catalog.XmlCatalogDocumentBean;
import com.catalog.XmlJournalDocumentBean;
import com.catalog.XmlArticleDocumentBean;
import com.catalog.XmlShortItemBean;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlError;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import java.util.ArrayList;
import java.io.IOException;
import java.io.File;
public class CatalogXsdConfig
{
public static void main(String[] args)
{
// Create an instance of this class to work with.
CatalogXsdConfig catxsdconfig = new CatalogXsdConfig();
// Create an instance of a type based on the received XML's schema
XmlCatalogDocumentBean catdoc = catxsdconfig.parseXml(args[0]);
//Prints the element values from the XML.
catxsdconfig.printElements(catdoc);
}
/**
* Creates a File from the XML path provided in main arguments, then
* parses the file's contents into a type (CatalogDocument) generated from schema.
*
* @param xmlFilePath A path to XML based on the schema in EasyPo.xsd
* @return An instance of a generated schema type (CatalogDocument) that contains the
* parsed XML.
*/
public XmlCatalogDocumentBean parseXml(String xmlFilePath)
{
File xmlfile = new File(xmlFilePath);
XmlCatalogDocumentBean catdoc = null;
try
{
catdoc = XmlCatalogDocumentBean.Factory.parse(xmlfile);
}
catch (XmlException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return catdoc;
}
/*
* This method prints all the element values in the given XML document based on Catalog.xsd
*/
public void printElements(XmlCatalogDocumentBean catdoc)
{
// Get object reference of root element.
XmlCatalogDocumentBean.Catalog catalogelement = catdoc.getCatalog();
//Get all <journal> element from the root element.
XmlJournalDocumentBean.Journal[] journalarray = catalogelement.getJournalArray();
//Loop through <journal> element array.
for (int i = 0; i < journalarray.length; i++)
{
//Retrieve all <article> elements within each <journal> element
XmlArticleDocumentBean.Article[] articlearray = journalarray[i].getArticleArray();
//Loop through <article> array retrieved above
for (int j = 0; j < articlearray.length; j++)
{
System.out.println(articlearray[j].getTitle());
String[] str = articlearray[j].getAuthorArray();
for (int k = 0; k < str.length; k++)
System.out.println(str[k]);
//Note the method for retrieving <forsample> element.
System.out.println(
articlearray[j].getXmlShortItemBean().getGoodName());
}
}
System.out.println("\n\n\n");
}
/**
* <p>Validates the XML, printing error messages when the XML is invalid. Note
* that this method will properly validate any instance of a compiled schema
* type because all of these types extend XmlObject.</p>
* <p/>
* <p>Note that in actual practice, you'll probably want to use an assertion
* when validating if you want to ensure that your code doesn't pass along
* invalid XML. This sample prints the generated XML whether or not it's
* valid so that you can see the result in both cases.</p>
*
* @param xml The XML to validate.
* @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
*/
public static boolean validateXml(XmlObject xml)
{
boolean isXmlValid = false;
// A collection instance to hold validation error messages.
ArrayList validationMessages = new ArrayList();
// Validate the XML, collecting messages.
isXmlValid = xml.validate(
new XmlOptions().setErrorListener(validationMessages));
// If the XML isn't valid, print the messages.
if (!isXmlValid)
{
System.out.println("\nInvalid XML: ");
for (int i = 0; i < validationMessages.size(); i++)
{
XmlError error = (XmlError) validationMessages.get(i);
System.out.println(error.getMessage());
System.out.println(error.getObjectLocation());
}
}
return isXmlValid;
}
}

View File

@@ -0,0 +1,41 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.xsdconfig;
import com.catalog.XmlCatalogDocumentBean;
public class XsdConfigTest
{
/**
* Tests the CatalogXsdConfig.java class. This does consider XsdConfig file.
*/
public static void main(String[] args)
{
// Create an instance of the sample to test.
CatalogXsdConfig sample = new CatalogXsdConfig();
XmlCatalogDocumentBean catdoc = sample.parseXml(args[0]);
//Prints the element values from the XML.
sample.printElements(catdoc);
// Validate the XML.
assert sample.validateXml(catdoc);
}
}

View File

@@ -0,0 +1,40 @@
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.samples.xsdconfig;
import org.apache.xmlbeans.samples.catalog.CatalogDocument;
public class XsdTest
{
/**
* Tests the CatalogXsd.java class. This does not consider XsdConfig file.
*/
public static void main(String[] args)
{
// Create an instance of the sample to test.
CatalogXsd sample = new CatalogXsd();
CatalogDocument catdoc = sample.parseXml(args[0]);
//Prints the element values from the XML.
sample.printElements(catdoc);
// Validate the XML.
assert sample.validateXml(catdoc);
}
}

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<catalog xmlns="http://xmlbeans.apache.org/samples/catalog">
<journal>
<article>
<title>Java programming for high-performance numerical computing</title>
<author>J. E. Moreira et.al.</author>
<a-very-long-description-element>
<forsample>This is a sample element for journal-1</forsample>
</a-very-long-description-element>
</article>
</journal>
<journal>
<article>
<title>Dynamically Binding EJBs Using the Java Reflection API</title>
<author>Douglas A. Clark</author>
<a-very-long-description-element>
<forsample>This document can be found at http://www.cuj.com/documents/s=8467/cujjsup2010clark/clark.htm </forsample>
</a-very-long-description-element>
</article>
</journal>
</catalog>