libjibx-java-1.1.6a/ 0000755 0001750 0001750 00000000000 11023302622 014071 5 ustar moeller moeller libjibx-java-1.1.6a/build/ 0000755 0001750 0001750 00000000000 11023035622 015173 5 ustar moeller moeller libjibx-java-1.1.6a/build/extras/ 0000755 0001750 0001750 00000000000 11021525446 016507 5 ustar moeller moeller libjibx-java-1.1.6a/build/extras/org/ 0000755 0001750 0001750 00000000000 11021525446 017276 5 ustar moeller moeller libjibx-java-1.1.6a/build/extras/org/jibx/ 0000755 0001750 0001750 00000000000 11021525446 020232 5 ustar moeller moeller libjibx-java-1.1.6a/build/extras/org/jibx/extras/ 0000755 0001750 0001750 00000000000 11023035622 021532 5 ustar moeller moeller libjibx-java-1.1.6a/build/extras/org/jibx/extras/BindingSelector.java 0000644 0001750 0001750 00000020144 10071714102 025450 0 ustar moeller moeller /*
Copyright (c) 2003-2004, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.extras;
import java.io.OutputStream;
import java.io.Writer;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallable;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.impl.MarshallingContext;
import org.jibx.runtime.impl.UnmarshallingContext;
/**
* Binding selector that supports versioned XML documents. This looks for a
* version attribute on the root element of the document, and selects the
* mapping to be used for unmarshalling based on the value. It also supports
* selecting the version for marshalling based on a supplied version argument
* value.
*
* @author Dennis M. Sosnoski
* @version 1.0
*/
public class BindingSelector
{
/** URI of version selection attribute. */
private final String m_attributeUri;
/** Name of version selection attribute. */
private final String m_attributeName;
/** Array of version names. */
private final String[] m_versionTexts;
/** Array of bindings corresponding to versions. */
private final String[] m_versionBindings;
/** Basic unmarshalling context used to determine document version. */
private final UnmarshallingContext m_context;
/** Stream for marshalling output. */
private OutputStream m_outputStream;
/** Encoding for output stream. */
private String m_outputEncoding;
/** Output writer for marshalling. */
private Writer m_outputWriter;
/** Indentation for marshalling. */
private int m_outputIndent;
/**
* Constructor.
*
* @param uri version selection attribute URI (null
if none)
* @param name version selection attribute name
* @param versions array of version texts (first is default)
* @param bindings array of binding names corresponding to versions
*/
public BindingSelector(String uri, String name, String[] versions,
String[] bindings) {
m_attributeUri = uri;
m_attributeName = name;
m_versionTexts = versions;
m_versionBindings = bindings;
m_context = new UnmarshallingContext();
m_outputIndent = -1;
}
/**
* Get initial unmarshalling context. This gives access to the unmarshalling
* context used before the specific version is determined. The document
* information must be set for this context before calling {@link
* #unmarshalVersioned}.
*
* @return initial unmarshalling context
*/
public IUnmarshallingContext getContext() {
return m_context;
}
/**
* Set output stream and encoding.
*
* @param outs stream for document data output
* @param enc document output encoding, or null
for default
*/
public void setOutput(OutputStream outs, String enc) {
m_outputStream = outs;
m_outputEncoding = enc;
}
/**
* Set output writer.
*
* @param outw writer for document data output
*/
public void setOutput(Writer outw) {
m_outputWriter = outw;
}
/**
* Set nesting indent spaces.
*
* @param indent number of spaces to indent per level, or disable
* indentation if negative
*/
public void setIndent(int indent) {
m_outputIndent = indent;
}
/**
* Marshal according to supplied version.
*
* @param obj root object to be marshalled
* @param version identifier for version to be used in marshalling
* @throws JiBXException if error in marshalling
*/
public void marshalVersioned(Object obj, String version)
throws JiBXException {
// look up version in defined list
String match = (version == null) ? m_versionTexts[0] : version;
for (int i = 0; i < m_versionTexts.length; i++) {
if (match.equals(m_versionTexts[i])) {
// version found, create marshaller for the associated binding
IBindingFactory fact = BindingDirectory.
getFactory(m_versionBindings[i], obj.getClass());
MarshallingContext context =
(MarshallingContext)fact.createMarshallingContext();
// configure marshaller for writing document
context.setIndent(m_outputIndent);
if (m_outputWriter == null) {
if (m_outputStream == null) {
throw new JiBXException("Output not configured");
} else {
context.setOutput(m_outputStream, m_outputEncoding);
}
} else {
context.setOutput(m_outputWriter);
}
// output object as document
context.startDocument(m_outputEncoding, null);
((IMarshallable)obj).marshal(context);
context.endDocument();
return;
}
}
// error if unknown version in document
throw new JiBXException("Unrecognized document version " + version);
}
/**
* Unmarshal according to document version.
*
* @param clas expected class mapped to root element of document (used only
* to look up the binding)
* @return root object unmarshalled from document
* @throws JiBXException if error in unmarshalling
*/
public Object unmarshalVersioned(Class clas) throws JiBXException {
// get the version attribute value (using first value as default)
m_context.toStart();
String version = m_context.attributeText(m_attributeUri,
m_attributeName, m_versionTexts[0]);
// look up version in defined list
for (int i = 0; i < m_versionTexts.length; i++) {
if (version.equals(m_versionTexts[i])) {
// version found, create unmarshaller for the associated binding
IBindingFactory fact = BindingDirectory.
getFactory(m_versionBindings[i], clas);
UnmarshallingContext context =
(UnmarshallingContext)fact.createUnmarshallingContext();
// return object unmarshalled using binding for document version
context.setFromContext(m_context);
return context.unmarshalElement();
}
}
// error if unknown version in document
throw new JiBXException("Unrecognized document version " + version);
}
} libjibx-java-1.1.6a/build/extras/org/jibx/extras/DiscardElementMapper.java 0000644 0001750 0001750 00000006026 10221060356 026432 0 ustar moeller moeller /*
Copyright (c) 2004-2005, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.extras;
import org.jibx.runtime.IMarshaller;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshaller;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.impl.UnmarshallingContext;
/**
*
Custom marshaller/unmarshaller for arbitrary ignored element. This ignores * an element when unmarshalling, if one is present, and does nothing when * marshalling.
* * @author Dennis M. Sosnoski * @version 1.0 */ public class DiscardElementMapper implements IMarshaller, IUnmarshaller { /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#isExtension(int) */ public boolean isExtension(int index) { return false; } /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#marshal(java.lang.Object, * org.jibx.runtime.IMarshallingContext) */ public void marshal(Object obj, IMarshallingContext ictx) {} /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext) */ public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException { return !ctx.isEnd(); } /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#unmarshal(java.lang.Object, * org.jibx.runtime.IUnmarshallingContext) */ public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // just discard and return null ((UnmarshallingContext)ictx).skipElement(); return null; } } libjibx-java-1.1.6a/build/extras/org/jibx/extras/DiscardListMapper.java 0000644 0001750 0001750 00000006162 10221060356 025755 0 ustar moeller moeller /* Copyright (c) 2004-2005, Dennis M. Sosnoski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jibx.extras; import org.jibx.runtime.IMarshaller; import org.jibx.runtime.IMarshallingContext; import org.jibx.runtime.IUnmarshaller; import org.jibx.runtime.IUnmarshallingContext; import org.jibx.runtime.JiBXException; import org.jibx.runtime.impl.UnmarshallingContext; /** *Custom marshaller/unmarshaller for arbitrary ignored content to end of * element. This ignores all content to the end of the enclosing element when * unmarshalling, and does nothing with marshalling.
* * @author Dennis M. Sosnoski * @version 1.0 */ public class DiscardListMapper implements IMarshaller, IUnmarshaller { /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#isExtension(int) */ public boolean isExtension(int index) { return false; } /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#marshal(java.lang.Object, * org.jibx.runtime.IMarshallingContext) */ public void marshal(Object obj, IMarshallingContext ictx) {} /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext) */ public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException { return !ctx.isEnd(); } /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#unmarshal(java.lang.Object, * org.jibx.runtime.IUnmarshallingContext) */ public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // just discard all elements and return null while (!ictx.isEnd()) { ((UnmarshallingContext)ictx).skipElement(); } return null; } } libjibx-java-1.1.6a/build/extras/org/jibx/extras/DocumentComparator.java 0000644 0001750 0001750 00000026264 10767277422 026241 0 ustar moeller moeller /* Copyright (c) 2003-2007, Dennis M. Sosnoski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jibx.extras; import java.io.IOException; import java.io.PrintStream; import java.io.Reader; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; /** * XML document comparator. This uses XMLPull parsers to read a pair of * documents in parallel, comparing the streams of components seen from the two * documents. The comparison ignores differences in whitespace separating * elements, but treats whitespace as significant within elements with only * character data content. * * @author Dennis M. Sosnoski */ public class DocumentComparator { /** Parser for first document. */ protected XmlPullParser m_parserA; /** Parser for second document. */ protected XmlPullParser m_parserB; /** Print stream for reporting differences. */ protected PrintStream m_differencePrint; /** * Constructor. Builds the actual parser. * * @param print print stream for reporting differences * @throws XmlPullParserException on error creating parsers */ public DocumentComparator(PrintStream print) throws XmlPullParserException { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); m_parserA = factory.newPullParser(); m_parserB = factory.newPullParser(); m_differencePrint = print; } /** * Build parse input position description. * * @param parser for which to build description * @return text description of current parse position */ protected String buildPositionString(XmlPullParser parser) { return " line " + parser.getLineNumber() + ", col " + parser.getColumnNumber(); } /** * Build name string. * * @param ns namespace URI * @param name local name * @return printable names string */ protected String buildName(String ns, String name) { if ("".equals(ns)) { return name; } else { return "{" + ns + '}' + name; } } /** * Prints error description text. The generated text include position * information from both documents. * * @param msg error message text */ protected void printError(String msg) { if (m_differencePrint != null) { m_differencePrint.println(msg + " - from " + buildPositionString(m_parserA) + " to " + buildPositionString(m_parserB)); } } /** * Verifies that the attributes on the current start tags match. Any * mismatches are printed immediately. * * @returntrue
if the attributes match, false
if
* not
*/
protected boolean matchAttributes() {
int counta = m_parserA.getAttributeCount();
int countb = m_parserB.getAttributeCount();
boolean[] flags = new boolean[countb];
boolean match = true;
for (int i = 0; i < counta; i++) {
String name = m_parserA.getAttributeName(i);
String ns = m_parserA.getAttributeNamespace(i);
String value = m_parserA.getAttributeValue(i);
boolean found = false;
for (int j = 0; j < countb; j++) {
if (name.equals(m_parserB.getAttributeName(j)) &&
ns.equals(m_parserB.getAttributeNamespace(j))) {
flags[j] = true;
if (!value.equals(m_parserB.getAttributeValue(j))) {
if (match) {
printError("Attribute mismatch");
match = false;
}
m_differencePrint.println(" attribute " +
buildName(ns, name) + " value '" + value +
"' != '" + m_parserB.getAttributeValue(j) + '\'');
}
found = true;
break;
}
}
if (!found) {
if (match) {
printError("Attribute mismatch");
match = false;
}
m_differencePrint.println(" attribute " +
buildName(ns, name) + "=\"" + value +
"\" is missing from second document");
}
}
for (int i = 0; i < countb; i++) {
if (!flags[i]) {
if (match) {
printError("Attribute mismatch");
match = false;
}
m_differencePrint.println(" attribute " +
buildName(m_parserB.getAttributeNamespace(i),
m_parserB.getAttributeName(i)) +
" is missing from first document");
}
}
return match;
}
/**
* Check if two text strings match, ignoring leading and trailing spaces.
* Any mismatch is printed immediately, with the supplied lead text.
*
* @param texta
* @param textb
* @param lead error text lead
* @return true
if the texts match, false
if
* not
*/
protected boolean matchText(String texta, String textb, String lead) {
if (texta.trim().equals(textb.trim())) {
return true;
} else {
printError(lead);
if (m_differencePrint != null) {
m_differencePrint.println(" \"" + texta +
"\" (length " + texta.length() + " vs. \"" +
textb + "\" (length " + textb.length() + ')');
}
return false;
}
}
/**
* Verifies that the current start or end tag names match.
*
* @return true
if the names match, false
if not
*/
protected boolean matchNames() {
return m_parserA.getName().equals(m_parserB.getName()) &&
m_parserA.getNamespace().equals(m_parserB.getNamespace());
}
/**
* Compares a pair of documents by reading them in parallel from a pair of
* parsers. The comparison ignores differences in whitespace separating
* elements, but treats whitespace as significant within elements with only
* character data content.
*
* @param rdra reader for first document to be compared
* @param rdrb reader for second document to be compared
* @return true
if the documents are the same,
* false
if they're different
*/
public boolean compare(Reader rdra, Reader rdrb) {
try {
// set the documents and initialize
m_parserA.setInput(rdra);
m_parserB.setInput(rdrb);
boolean content = false;
String texta = "";
String textb = "";
boolean same = true;
while (true) {
// start by collecting and moving past text content
if (m_parserA.getEventType() == XmlPullParser.TEXT) {
texta = m_parserA.getText();
m_parserA.next();
}
if (m_parserB.getEventType() == XmlPullParser.TEXT) {
textb = m_parserB.getText();
m_parserB.next();
}
// now check actual tag state
int typea = m_parserA.getEventType();
int typeb = m_parserB.getEventType();
if (typea != typeb) {
printError("Different document structure");
return false;
} else if (typea == XmlPullParser.START_TAG) {
// compare start tags, attributes, and prior text
content = true;
if (!matchNames()) {
printError("Different start tags");
return false;
} else {
if (!matchAttributes()) {
same = false;
}
if (!matchText(texta, textb,
"Different text content between elements")) {
same = false;
}
}
texta = textb = "";
} else if (typea == XmlPullParser.END_TAG) {
// compare end tags and prior text
if (!matchNames()) {
printError("Different end tags");
return false;
}
if (content) {
if (!matchText(texta, textb, "Different text content")) {
same = false;
}
content = false;
} else {
if (!matchText(texta, textb,
"Different text content between elements")) {
same = false;
}
}
texta = textb = "";
} else if (typea == XmlPullParser.END_DOCUMENT) {
return same;
}
// advance both parsers to next component
m_parserA.next();
m_parserB.next();
}
} catch (IOException ex) {
if (m_differencePrint != null) {
ex.printStackTrace(m_differencePrint);
}
return false;
} catch (XmlPullParserException ex) {
if (m_differencePrint != null) {
ex.printStackTrace(m_differencePrint);
}
return false;
}
}
} libjibx-java-1.1.6a/build/extras/org/jibx/extras/DocumentModelMapperBase.java 0000644 0001750 0001750 00000011775 10434260002 027104 0 ustar moeller moeller /*
Copyright (c) 2004, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.extras;
import org.jibx.runtime.IXMLReader;
import org.jibx.runtime.IXMLWriter;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.impl.UnmarshallingContext;
/**
* Base implementation for custom marshaller/unmarshallers to any document * model representation. This class just provides a few basic operations that * are used by the representation-specific subclasses.
* * @author Dennis M. Sosnoski * @version 1.0 */ public class DocumentModelMapperBase { /** Fixed XML namespace. */ public static final String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"; /** Fixed XML namespace namespace. */ public static final String XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/"; /** Writer for direct output as XML. */ protected IXMLWriter m_xmlWriter; /** Context being used for unmarshalling. */ protected UnmarshallingContext m_unmarshalContext; /** * Get namespace URI for index. * * @param index namespace index to look up * @return uri namespace URI at index position */ protected String getNamespaceUri(int index) { String[] uris = m_xmlWriter.getNamespaces(); if (index < uris.length) { return uris[index]; } else { index -= uris.length; String[][] uriss = m_xmlWriter.getExtensionNamespaces(); if (uriss != null) { for (int i = 0; i < uriss.length; i++) { uris = uriss[i]; if (index < uris.length) { return uris[index]; } else { index -= uris.length; } } } } return null; } /** * Get next namespace index. * * @return next namespace index */ protected int getNextNamespaceIndex() { int count = m_xmlWriter.getNamespaces().length; String[][] uriss = m_xmlWriter.getExtensionNamespaces(); if (uriss != null) { for (int i = 0; i < uriss.length; i++) { count += uriss[i].length; } } return count; } /** * Accumulate text content. This consolidates consecutive text and entities * to a single string. * * @return consolidated text string * @exception JiBXException on error in unmarshalling */ protected String accumulateText() throws JiBXException { String text = m_unmarshalContext.getText(); StringBuffer buff = null; while (true) { int cev = m_unmarshalContext.nextToken(); if (cev == IXMLReader.TEXT || (cev == IXMLReader.ENTITY_REF && m_unmarshalContext.getText() != null)) { if (buff == null) { buff = new StringBuffer(text); } buff.append(m_unmarshalContext.getText()); } else { break; } } if (buff == null) { return text; } else { return buff.toString(); } } /** * Check if a character is a space character. * * @param chr character to be checked * @returntrue
if whitespace, false
if not
*/
protected boolean isWhitespace(char chr) {
if (chr <= 0x20) {
return chr == 0x20 || chr == 0x09 || chr == 0x0A || chr == 0x0D;
} else {
return false;
}
}
} libjibx-java-1.1.6a/build/extras/org/jibx/extras/Dom4JElementMapper.java 0000644 0001750 0001750 00000014460 10071714104 025777 0 ustar moeller moeller /*
Copyright (c) 2004, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.extras;
import java.io.IOException;
import org.dom4j.Element;
import org.jibx.runtime.IAliasable;
import org.jibx.runtime.IMarshaller;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshaller;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.impl.UnmarshallingContext;
/**
* Custom element marshaller/unmarshaller to dom4j representation. This
* allows you to mix data binding and document model representations for XML
* within the same application. You simply use this marshaller/unmarshaller with
* a linked object type of org.dom4j.Element
(the actual runtime
* type - the declared type is ignored and can be anything). If a name is
* supplied on a reference that element name will always be matched when
* unmarshalling but will be ignored when marshalling (with the actual dom4j
* element name used). If no name is supplied this will unmarshal a single
* element with any name.
Custom content list marshaller/unmarshaller to dom4j representation. This
* allows you to mix data binding and document model representations for XML
* within the same application. You simply use this marshaller/unmarshaller with
* a linked object type that implements java.util.List
(the actual
* runtime type - the declared type is ignored and can be anything). When
* unmarshalling it will create an instance of java.util.ArrayList
* if a list is not passed in and any content is present, then return all the
* content up to the close tag for the enclosing element in the list. When
* marshalling, it will simply write out any content directly.
Base implementation for custom marshaller/unmarshallers to dom4j * representation. This provides the basic code used for both single element and * content list handling.
* * @author Dennis M. Sosnoski * @version 1.0 */ public class Dom4JMapperBase extends DocumentModelMapperBase { /** dom4j component construction factory. */ private static DocumentFactory s_factory = DocumentFactory.getInstance(); /** Current default namespace URI (null
if not determined). */
protected String m_defaultNamespaceURI;
/** Current default namespace index. */
protected int m_defaultNamespaceIndex;
/**
* Get index number for declared namespace.
*
* @param ns namespace of interest
* @return namespace index number, or -1
if not declared or
* masked
*/
private int findNamespaceIndex(Namespace ns) {
if (Namespace.NO_NAMESPACE.equals(ns)) {
return 0;
} else if (Namespace.XML_NAMESPACE.equals(ns)) {
return 1;
} else {
String prefix = ns.getPrefix();
if (prefix == null || prefix.length() == 0) {
if (m_defaultNamespaceURI == null) {
int index = m_xmlWriter.getPrefixIndex("");
if (index >= 0) {
m_defaultNamespaceURI = getNamespaceUri(index);
m_defaultNamespaceIndex = index;
if (m_defaultNamespaceURI.equals(ns.getURI())) {
return index;
} else {
return -1;
}
} else {
return -1;
}
} else {
return m_defaultNamespaceURI.equals(ns.getURI()) ?
m_defaultNamespaceIndex : -1;
}
} else {
int index = m_xmlWriter.getPrefixIndex(prefix);
if (index >= 0) {
return getNamespaceUri(index).equals(ns.getURI()) ?
index : -1;
} else {
return -1;
}
}
}
}
/**
* Marshal content list.
*
* @param content list of content items to marshal
* @exception JiBXException on error in marshalling
* @exception IOException on error writing to output
*/
protected void marshalContent(List content)
throws JiBXException, IOException {
int size = content.size();
for (int i = 0; i < size; i++) {
Node node = (Node)content.get(i);
switch (node.getNodeType()) {
case Node.CDATA_SECTION_NODE:
m_xmlWriter.writeCData(node.getText());
break;
case Node.COMMENT_NODE:
m_xmlWriter.writeComment(node.getText());
break;
case Node.ELEMENT_NODE:
marshalElement((Element)node);
break;
case Node.ENTITY_REFERENCE_NODE:
m_xmlWriter.writeEntityRef(node.getName());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
m_xmlWriter.writePI(((ProcessingInstruction)node).
getTarget(), node.getText());
break;
case Node.TEXT_NODE:
m_xmlWriter.writeTextContent(node.getText());
break;
default:
break;
}
}
}
/**
* Marshal element with all attributes and content.
*
* @param element element to be marshalled
* @exception JiBXException on error in marshalling
* @exception IOException on error writing to output
*/
protected void marshalElement(Element element)
throws JiBXException, IOException {
// accumulate all needed namespace declarations
int size = element.nodeCount();
Namespace ns = element.getNamespace();
int nsi = findNamespaceIndex(ns);
ArrayList nss = null;
boolean hascontent = false;
int defind = -1;
String defuri = null;
for (int i = 0; i < size; i++) {
Node node = element.node(i);
if (node instanceof Namespace) {
Namespace dns = (Namespace)node;
if (findNamespaceIndex(dns) < 0) {
if (nss == null) {
nss = new ArrayList();
}
nss.add(dns);
String prefix = dns.getPrefix();
if (prefix == null || prefix.length() == 0) {
defind = nss.size() - 1;
defuri = dns.getURI();
}
}
} else {
hascontent = true;
}
}
// check for namespace declarations required
String[] uris = null;
if (nss == null) {
m_xmlWriter.startTagOpen(nsi, element.getName());
} else {
int base = getNextNamespaceIndex();
if (defind >= 0) {
m_defaultNamespaceIndex = base + defind;
m_defaultNamespaceURI = defuri;
}
uris = new String[nss.size()];
int[] nums = new int[nss.size()];
String[] prefs = new String[nss.size()];
for (int i = 0; i < uris.length; i++) {
Namespace addns = (Namespace)nss.get(i);
uris[i] = addns.getURI();
nums[i] = base + i;
prefs[i] = addns.getPrefix();
if (nsi < 0 && ns.equals(addns)) {
nsi = base + i;
}
}
m_xmlWriter.pushExtensionNamespaces(uris);
m_xmlWriter.startTagNamespaces(nsi, element.getName(), nums, prefs);
if (defind >= 0) {
m_defaultNamespaceIndex = defind;
m_defaultNamespaceURI = defuri;
}
}
// add attributes if present
if (element.attributeCount() > 0) {
for (int i = 0; i < element.attributeCount(); i++) {
Attribute attr = element.attribute(i);
int index = findNamespaceIndex(attr.getNamespace());
m_xmlWriter.addAttribute(index, attr.getName(),
attr.getValue());
}
}
// check for content present
if (hascontent) {
m_xmlWriter.closeStartTag();
marshalContent(element.content());
m_xmlWriter.endTag(nsi, element.getName());
} else {
m_xmlWriter.closeEmptyTag();
}
// pop namespaces if defined by element
if (nss != null) {
m_xmlWriter.popExtensionNamespaces();
if (defind >= 0) {
m_defaultNamespaceURI = null;
}
}
}
/**
* Unmarshal element content. This unmarshals everything up to the
* containing element close tag, adding each component to the content list
* supplied. On return, the parse position will always be at an END_TAG.
*
* @param content list for unmarshalled content
* @exception JiBXException on error in unmarshalling
* @exception IOException on error reading input
*/
protected void unmarshalContent(List content)
throws JiBXException, IOException {
// loop until end of containing element found
loop: while (true) {
int cev = m_unmarshalContext.currentEvent();
switch (cev) {
case IXMLReader.CDSECT:
content.add(s_factory.
createCDATA(m_unmarshalContext.getText()));
break;
case IXMLReader.COMMENT:
content.add(s_factory.
createComment(m_unmarshalContext.getText()));
break;
case IXMLReader.END_TAG:
break loop;
case IXMLReader.ENTITY_REF:
if (m_unmarshalContext.getText() == null) {
content.add(s_factory.
createEntity(m_unmarshalContext.getName(), null));
break;
} else {
content.add(s_factory.createText(accumulateText()));
continue loop;
}
case IXMLReader.PROCESSING_INSTRUCTION:
{
String text = m_unmarshalContext.getText();
int index = 0;
while (++index < text.length() &&
!isWhitespace(text.charAt(index)));
if (index < text.length()) {
String target = text.substring(0, index);
while (++index < text.length() &&
isWhitespace(text.charAt(index)));
String data = text.substring(index);
content.add(s_factory.
createProcessingInstruction(target, data));
} else {
content.add(s_factory.
createProcessingInstruction(text, ""));
}
}
break;
case IXMLReader.START_TAG:
content.add(unmarshalElement());
continue loop;
case IXMLReader.TEXT:
content.add(s_factory.createText(accumulateText()));
continue loop;
}
m_unmarshalContext.nextToken();
}
}
/**
* Unmarshal element with all attributes and content. This must be called
* with the unmarshalling context positioned at a START_TAG event.
*
* @return unmarshalled element
* @exception JiBXException on error in unmarshalling
* @exception IOException on error reading input
*/
protected Element unmarshalElement() throws JiBXException, IOException {
// start by creating the actual element
QName qname = QName.get(m_unmarshalContext.getName(),
m_unmarshalContext.getPrefix(), m_unmarshalContext.getNamespace());
Element element = s_factory.createElement(qname);
// add all namespace declarations to element
int ncount = m_unmarshalContext.getNamespaceCount();
for (int i = 0; i < ncount; i++) {
String prefix = m_unmarshalContext.getNamespacePrefix(i);
String uri = m_unmarshalContext.getNamespaceUri(i);
element.addNamespace(prefix, uri);
}
// add all attributes to element
int acount = m_unmarshalContext.getAttributeCount();
for (int i = 0; i < acount; i++) {
String prefix = m_unmarshalContext.getAttributePrefix(i);
String uri = m_unmarshalContext.getAttributeNamespace(i);
String name = m_unmarshalContext.getAttributeName(i);
String value = m_unmarshalContext.getAttributeValue(i);
qname = QName.get(name, prefix, uri);
element.addAttribute(qname, value);
}
// add all content to element
int event = m_unmarshalContext.nextToken();
if (event != IXMLReader.END_TAG) {
unmarshalContent(element.content());
}
m_unmarshalContext.nextToken();
return element;
}
} libjibx-java-1.1.6a/build/extras/org/jibx/extras/DomElementMapper.java 0000644 0001750 0001750 00000014715 10071714110 025601 0 ustar moeller moeller /*
Copyright (c) 2004, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.extras;
import java.io.IOException;
import org.jibx.runtime.IAliasable;
import org.jibx.runtime.IMarshaller;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshaller;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.impl.UnmarshallingContext;
import org.w3c.dom.Element;
/**
* Custom element marshaller/unmarshaller to DOM representation. This allows
* you to mix data binding and document model representations for XML within the
* same application. You simply use this marshaller/unmarshaller with a linked
* object of type org.w3c.dom.Element
(the actual runtime type -
* the declared type is ignored and can be anything). If a name is supplied on a
* reference that element name will always be matched when unmarshalling but
* will be ignored when marshalling (with the actual DOM element name used). If
* no name is supplied this will unmarshal a single element with any name.
Custom content list marshaller/unmarshaller to DOM representation. This
* allows you to mix data binding and document model representations for XML
* within the same application. You simply use this marshaller/unmarshaller with
* a linked object type of org.w3c.dom.DocumentFragment
(the actual
* runtime type - the declared type is ignored and can be anything). When
* unmarshalling it will create a fragment to hold any content up to the close
* tag for the enclosing element in the list. When marshalling, it will simply
* write out any content directly.
Custom content list marshaller/unmarshaller to DOM representation. This
* allows you to mix data binding and document model representations for XML
* within the same application. You simply use this marshaller/unmarshaller with
* a linked object type that implements java.util.List
(the actual
* runtime type - the declared type is ignored and can be anything). When
* unmarshalling it will create an instance of java.util.ArrayList
* if a list is not passed in and any content is present, then return all the
* content up to the close tag for the enclosing element in the list. When
* marshalling, it will simply write out any content directly.
Base implementation for custom marshaller/unmarshallers to DOM * representation. This provides the basic code used for both single element and * content list handling.
* * @author Dennis M. Sosnoski * @version 1.0 */ public class DomMapperBase extends DocumentModelMapperBase { /** Actual document instance (required by DOM). */ protected Document m_document; /** Current default namespace URI (null
if not determined). */
protected String m_defaultNamespaceURI;
/** Current default namespace index. */
protected int m_defaultNamespaceIndex;
/**
* Constructor. Initializes the document used by this
* marshaller/unmarshaller instance as the owner of all DOM components.
*
* @throws JiBXException on error creating document
*/
protected DomMapperBase() throws JiBXException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
try {
m_document = dbf.newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
throw new JiBXException("Unable to create DOM document", e);
}
}
/**
* Get index number for declared namespace.
*
* @param prefix namespace prefix (null
if none)
* @param uri namespace URI (empty string if none)
* @return namespace index number, or -1
if not declared or
* masked
*/
private int findNamespaceIndex(String prefix, String uri) {
if ((prefix == null || "".equals(prefix)) &&
(uri == null || "".equals(uri))) {
return 0;
} else if ("xml".equals(prefix) && XML_NAMESPACE.equals(uri)) {
return 1;
} else {
if (prefix == null) {
if (m_defaultNamespaceURI == null) {
int index = m_xmlWriter.getPrefixIndex("");
if (index >= 0) {
m_defaultNamespaceURI = getNamespaceUri(index);
m_defaultNamespaceIndex = index;
if (m_defaultNamespaceURI.equals(uri)) {
return index;
} else {
return -1;
}
} else {
return -1;
}
} else {
return m_defaultNamespaceURI.equals(uri) ?
m_defaultNamespaceIndex : -1;
}
} else {
int index = m_xmlWriter.getPrefixIndex(prefix);
if (index >= 0) {
return getNamespaceUri(index).equals(uri) ?
index : -1;
} else {
return -1;
}
}
}
}
/**
* Marshal node.
*
* @param node node to be marshalled
* @exception JiBXException on error in marshalling
* @exception IOException on error writing to output
*/
protected void marshalNode(Node node) throws JiBXException, IOException {
switch (node.getNodeType()) {
case Node.CDATA_SECTION_NODE:
m_xmlWriter.writeCData(node.getNodeValue());
break;
case Node.COMMENT_NODE:
m_xmlWriter.writeComment(node.getNodeValue());
break;
case Node.ELEMENT_NODE:
marshalElement((Element)node);
break;
case Node.ENTITY_REFERENCE_NODE:
m_xmlWriter.writeEntityRef(node.getNodeName());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
m_xmlWriter.writePI(node.getNodeName(),
node.getNodeValue());
break;
case Node.TEXT_NODE:
m_xmlWriter.writeTextContent(node.getNodeValue());
break;
default:
break;
}
}
/**
* Marshal node list.
*
* @param content list of nodes to marshal
* @exception JiBXException on error in marshalling
* @exception IOException on error writing to output
*/
protected void marshalContent(NodeList content)
throws JiBXException, IOException {
int size = content.getLength();
for (int i = 0; i < size; i++) {
marshalNode(content.item(i));
}
}
/**
* Marshal element with all attributes and content.
*
* @param element element to be marshalled
* @exception JiBXException on error in marshalling
* @exception IOException on error writing to output
*/
protected void marshalElement(Element element)
throws JiBXException, IOException {
// accumulate all needed namespace declarations
String prefix = element.getPrefix();
String uri = element.getNamespaceURI();
int nsi = findNamespaceIndex(prefix, uri);
ArrayList nss = null;
int defind = -1;
String defuri = null;
NamedNodeMap attrs = element.getAttributes();
int size = attrs.getLength();
for (int i = 0; i < size; i++) {
Attr attr = (Attr)attrs.item(i);
if (XMLNS_NAMESPACE.equals(attr.getNamespaceURI())) {
// found namespace declaration, convert to simple prefix
String declpref = attr.getLocalName();
if ("xmlns".equals(declpref)) {
declpref = null;
}
String decluri = attr.getValue();
if (findNamespaceIndex(declpref, decluri) < 0) {
if (nss == null) {
nss = new ArrayList();
}
nss.add(declpref == null ? "" : declpref);
nss.add(decluri == null ? "" : decluri);
if (declpref == null) {
defind = (nss.size() / 2) - 1;
defuri = decluri;
}
if (uri == decluri) {
nsi = defind;
}
}
}
}
// check for namespace declarations required
String[] uris = null;
if (nss == null) {
m_xmlWriter.startTagOpen(nsi, element.getLocalName());
} else {
int base = getNextNamespaceIndex();
if (defind >= 0) {
m_defaultNamespaceIndex = base + defind;
m_defaultNamespaceURI = defuri;
}
int length = nss.size() / 2;
uris = new String[length];
int[] nums = new int[length];
String[] prefs = new String[length];
for (int i = 0; i < length; i++) {
prefs[i] = (String)nss.get(i*2);
uris[i] = (String)nss.get(i*2+1);
nums[i] = base + i;
if (nsi < 0 && uri.equals(uris[i])) {
if ((prefix == null && prefs[i] == "") ||
(prefix != null && prefix.equals(prefs[i]))) {
nsi = base + i;
}
}
}
m_xmlWriter.pushExtensionNamespaces(uris);
m_xmlWriter.startTagNamespaces(nsi, element.getLocalName(),
nums, prefs);
if (defind >= 0) {
m_defaultNamespaceIndex = defind;
m_defaultNamespaceURI = defuri;
}
}
// add attributes if present
for (int i = 0; i < size; i++) {
Attr attr = (Attr)attrs.item(i);
if (!XMLNS_NAMESPACE.equals(attr.getNamespaceURI())) {
int index = 0;
String apref = attr.getPrefix();
if (apref != null) {
index = findNamespaceIndex(apref, attr.getNamespaceURI());
}
m_xmlWriter.addAttribute(index, attr.getLocalName(),
attr.getValue());
}
}
// check for content present
NodeList nodes = element.getChildNodes();
size = nodes.getLength();
if (size > 0) {
m_xmlWriter.closeStartTag();
marshalContent(element.getChildNodes());
m_xmlWriter.endTag(nsi, element.getLocalName());
} else {
m_xmlWriter.closeEmptyTag();
}
// pop namespaces if defined by element
if (nss != null) {
m_xmlWriter.popExtensionNamespaces();
if (defind >= 0) {
m_defaultNamespaceURI = null;
}
}
}
/**
* Unmarshal single node. This unmarshals the next node from the input
* stream, up to the close tag of the containing element.
*
* @return unmarshalled node
* @exception JiBXException on error in unmarshalling
* @exception IOException on error reading input
*/
protected Node unmarshalNode() throws JiBXException, IOException {
while (true) {
int cev = m_unmarshalContext.currentEvent();
switch (cev) {
case IXMLReader.CDSECT:
{
String text = m_unmarshalContext.getText();
m_unmarshalContext.nextToken();
return m_document.createCDATASection(text);
}
case IXMLReader.COMMENT:
{
String text = m_unmarshalContext.getText();
m_unmarshalContext.nextToken();
return m_document.createComment(text);
}
case IXMLReader.END_TAG:
return null;
case IXMLReader.ENTITY_REF:
if (m_unmarshalContext.getText() == null) {
String name = m_unmarshalContext.getName();
m_unmarshalContext.nextToken();
return m_document.createEntityReference(name);
} else {
String text = accumulateText();
return m_document.createTextNode(text);
}
case IXMLReader.PROCESSING_INSTRUCTION:
{
String text = m_unmarshalContext.getText();
m_unmarshalContext.nextToken();
int index = 0;
while (++index < text.length() &&
!isWhitespace(text.charAt(index)));
if (index < text.length()) {
String target = text.substring(0, index);
while (++index < text.length() &&
isWhitespace(text.charAt(index)));
String data = text.substring(index);
return m_document.
createProcessingInstruction(target, data);
} else {
return m_document.
createProcessingInstruction(text, "");
}
}
case IXMLReader.START_TAG:
return unmarshalElement();
case IXMLReader.TEXT:
return m_document.createTextNode(accumulateText());
default:
m_unmarshalContext.nextToken();
}
}
}
/**
* Unmarshal node content. This unmarshals everything up to the containing
* element close tag, adding each component to the content list supplied. On
* return, the parse position will always be at an END_TAG.
*
* @param parent node to which children are to be added
* @exception JiBXException on error in unmarshalling
* @exception IOException on error reading input
*/
protected void unmarshalContent(Node parent)
throws JiBXException, IOException {
Node node;
while ((node = unmarshalNode()) != null) {
parent.appendChild(node);
}
}
/**
* Unmarshal element with all attributes and content. This must be called
* with the unmarshalling context positioned at a START_TAG event.
*
* @return unmarshalled element
* @exception JiBXException on error in unmarshalling
* @exception IOException on error reading input
*/
protected Element unmarshalElement() throws JiBXException, IOException {
// start by creating the actual element
String uri = m_unmarshalContext.getNamespace();
String prefix = m_unmarshalContext.getPrefix();
String name = m_unmarshalContext.getName();
if (prefix != null) {
name = prefix + ':' + name;
}
Element element = m_document.createElementNS(uri, name);
// add all namespace declarations to element
int ncount = m_unmarshalContext.getNamespaceCount();
for (int i = 0; i < ncount; i++) {
prefix = m_unmarshalContext.getNamespacePrefix(i);
uri = m_unmarshalContext.getNamespaceUri(i);
if (prefix == null) {
element.setAttributeNS(XMLNS_NAMESPACE, "xmlns", uri);
} else {
element.setAttributeNS(XMLNS_NAMESPACE, "xmlns:" + prefix, uri);
}
}
// add all attributes to element
int acount = m_unmarshalContext.getAttributeCount();
for (int i = 0; i < acount; i++) {
prefix = m_unmarshalContext.getAttributePrefix(i);
uri = m_unmarshalContext.getAttributeNamespace(i);
name = m_unmarshalContext.getAttributeName(i);
if (prefix != null) {
name = prefix + ':' + name;
}
String value = m_unmarshalContext.getAttributeValue(i);
element.setAttributeNS(uri, name, value);
}
// add all content to element
int event = m_unmarshalContext.nextToken();
if (event != IXMLReader.END_TAG) {
unmarshalContent(element);
}
m_unmarshalContext.nextToken();
return element;
}
} libjibx-java-1.1.6a/build/extras/org/jibx/extras/HashMapperStringToComplex.java 0000644 0001750 0001750 00000023072 10222700114 027446 0 ustar moeller moeller /*
Copyright (c) 2003-2005, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.extras;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jibx.runtime.IAliasable;
import org.jibx.runtime.IMarshallable;
import org.jibx.runtime.IMarshaller;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshaller;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.impl.MarshallingContext;
import org.jibx.runtime.impl.UnmarshallingContext;
/**
* Custom marshaller/unmarshaller for java.util.Map
* instances. This handles mapping hash maps with simple keys and complex values
* to and from XML. There are a number of limitations, though. First off, the
* key objects are marshalled as simple text values, using the
* toString()
method to convert them to String
. When
* unmarshalling the keys are always treated as String
values. The
* corresponding values can be any complex type with a <mapping> defined in
* the binding. The name of the top-level element in the XML structure can be
* configured in the binding definition, but the rest of the names are
* predefined and set in the code (though the namespace configured for the
* top-level element will be used with all the names).
The net effect is that the XML structure will always be of the form:
* *<map-name size="3"> * <entry key="38193"> * <customer state="WA" zip="98059"> * <name first-name="John" last-name="Smith"/> * <street>12345 Happy Lane</street> * <city>Plunk</city> * </customer> * </entry> * <entry key="39122"> * <customer state="WA" zip="98094"> * <name first-name="Sally" last-name="Port"/> * <street>932 Easy Street</street> * <city>Fort Lewis</city> * </customer> * </entry> * <entry key="83132"> * <customer state="WA" zip="98059"> * <name first-name="Mary" last-name="Smith"/> * <street>12345 Happy Lane</street> * <city>Plunk</city> * </customer> * </entry> * </map-name>* *
where "map-name" is the configured top-level element name, the "size" * attribute is the number of pairs in the hash map, and the "entry" elements * are the actual entries in the hash map.
* *This is obviously not intended to handle all types of hash maps, but it * should be useful as written for many applications and easily customized to * handle other requirements.
* * @author Dennis M. Sosnoski * @version 1.0 */ public class HashMapperStringToComplex implements IMarshaller, IUnmarshaller, IAliasable { private static final int DEFAULT_SIZE = 10; private String m_uri; private int m_index; private String m_name; /** * Default constructor. This uses a pre-defined name for the top-level * element. It'll be used by JiBX when no name information is supplied by * the mapping which references this custom marshaller/unmarshaller. */ public HashMapperStringToComplex() { m_uri = null; m_index = 0; m_name = "hashmap"; } /** * Aliased constructor. This takes a name definition for the top-level * element. It'll be used by JiBX when a name is supplied by the mapping * which references this custom marshaller/unmarshaller. * * @param uri namespace URI for the top-level element (also used for all * other names within the binding) * @param index namespace index corresponding to the defined URI within the * marshalling context definitions * @param name local name for the top-level element */ public HashMapperStringToComplex(String uri, int index, String name) { m_uri = uri; m_index = index; m_name = name; } /** * Method which can be overridden to supply a different name for the wrapper * element attribute used to give the number of items present. If present, * this attribute is used when unmarshalling to set the initial size of the * hashmap. It will be generated when marshalling if the supplied name is * non-null
.
*/
protected String getSizeAttributeName() {
return "size";
}
/**
* Method which can be overridden to supply a different name for the element
* used to represent each item in the map.
*/
protected String getEntryElementName() {
return "entry";
}
/**
* Method which can be overridden to supply a different name for the
* attribute defining the key value for each item in the map.
*/
protected String getKeyAttributeName() {
return "key";
}
/* (non-Javadoc)
* @see org.jibx.runtime.IMarshaller#isExtension(int)
*/
public boolean isExtension(int index) {
return false;
}
/* (non-Javadoc)
* @see org.jibx.runtime.IMarshaller#marshal(java.lang.Object,
* org.jibx.runtime.IMarshallingContext)
*/
public void marshal(Object obj, IMarshallingContext ictx)
throws JiBXException {
// make sure the parameters are as expected
if (!(obj instanceof Map)) {
throw new JiBXException("Invalid object type for marshaller");
} else if (!(ictx instanceof MarshallingContext)) {
throw new JiBXException("Invalid object type for marshaller");
} else {
// start by generating start tag for container
MarshallingContext ctx = (MarshallingContext)ictx;
Map map = (Map)obj;
ctx.startTagAttributes(m_index, m_name).
attribute(m_index, getSizeAttributeName(), map.size()).
closeStartContent();
// loop through all entries in map
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry)iter.next();
ctx.startTagAttributes(m_index, getEntryElementName());
ctx.attribute(m_index, getKeyAttributeName(),
entry.getKey().toString());
ctx.closeStartContent();
if (entry.getValue() instanceof IMarshallable) {
((IMarshallable)entry.getValue()).marshal(ctx);
ctx.endTag(m_index, getEntryElementName());
} else {
throw new JiBXException("Mapped value is not marshallable");
}
}
// finish with end tag for container element
ctx.endTag(m_index, m_name);
}
}
/* (non-Javadoc)
* @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext)
*/
public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException {
return ctx.isAt(m_uri, m_name);
}
/* (non-Javadoc)
* @see org.jibx.runtime.IUnmarshaller#unmarshal(java.lang.Object,
* org.jibx.runtime.IUnmarshallingContext)
*/
public Object unmarshal(Object obj, IUnmarshallingContext ictx)
throws JiBXException {
// make sure we're at the appropriate start tag
UnmarshallingContext ctx = (UnmarshallingContext)ictx;
if (!ctx.isAt(m_uri, m_name)) {
ctx.throwStartTagNameError(m_uri, m_name);
}
// create new hashmap if needed
int size = ctx.attributeInt(m_uri,
getSizeAttributeName(), DEFAULT_SIZE);
Map map = (Map)obj;
if (map == null) {
map = new HashMap(size);
}
// process all entries present in document
ctx.parsePastStartTag(m_uri, m_name);
while (ctx.isAt(m_uri, getEntryElementName())) {
Object key = ctx.attributeText(m_uri, getKeyAttributeName(), null);
ctx.parsePastStartTag(m_uri, getEntryElementName());
Object value = ctx.unmarshalElement();
map.put(key, value);
ctx.parsePastEndTag(m_uri, getEntryElementName());
}
ctx.parsePastEndTag(m_uri, m_name);
return map;
}
} libjibx-java-1.1.6a/build/extras/org/jibx/extras/HashMapperStringToSchemaType.java 0000644 0001750 0001750 00000046563 10434260002 030115 0 ustar moeller moeller /*
Copyright (c) 2004-2005, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.extras;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jibx.runtime.EnumSet;
import org.jibx.runtime.IAliasable;
import org.jibx.runtime.IMarshaller;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshaller;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.IXMLWriter;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.Utility;
import org.jibx.runtime.impl.MarshallingContext;
import org.jibx.runtime.impl.UnmarshallingContext;
/**
* Custom marshaller/unmarshaller for java.util.Map
* instances. This handles mapping hash maps with string keys and values that
* match basic schema datatypes to and from XML. The key objects are marshalled
* as simple text values, using the toString()
method to convert
* them to String
if they are not already of that type. When
* unmarshalling the keys are always treated as String
values. The
* corresponding values can be any of the object types corresponding to basic
* schema data types, and are marshalled with xsi:type attributes to specify the
* type of each value. The types currently supported are Byte
,
* Double
, Float
, Integer
,
* Long
, java.util.Date
(as xsd:dateTime),
* java.sql.Date
(as xsd:date), java.sql.Time
(as
* xsd:time), java.math.BigDecimal
(with no exponent allowed, as
* xsd:decimal), and java.math.BigInteger
(as xsd:integer). The
* xsd:type attribute is checked when unmarshalling values to select the proper
* deserialization and value type. The name of the top-level element in the XML
* structure can be configured in the binding definition, but the rest of the
* names are predefined and set in the code (though the namespace configured for
* the top-level element will be used with all the names).
The net effect is that the XML structure will always be of the form:
* *<map-name size="6" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> * <entry key="name" xsi:type="xsd:string">John Smith</entry> * <entry key="street" xsi:type="xsd:string">12345 Happy Lane</entry> * <entry key="city" xsi:type="xsd:string">Plunk</entry> * <entry key="state" xsi:type="xsd:string">WA</entry> * <entry key="rating" xsi:type="xsd:int">6</entry> * <entry key="joined" xsi:type="xsd:dateTime">2002-08-06T00:13:31Z</entry> * </map-name>* *
where "map-name" is the configured top-level element name, the "size" * attribute is the number of pairs in the hash map, and the "entry" elements * are the actual entries in the hash map.
* *For unmarshalling this requires an active namespace declaration with a * prefix for the schema namespace. All xsi:type attribute values must use this * prefix. If more than one prefix is declared for the schema namespace, the * innermost one declared must be used.
* * @author Dennis M. Sosnoski * @version 1.0 */ public class HashMapperStringToSchemaType implements IMarshaller, IUnmarshaller, IAliasable { // // Basic constants used in code private static final String SIZE_ATTRIBUTE_NAME = "size"; private static final String ENTRY_ELEMENT_NAME = "entry"; private static final String KEY_ATTRIBUTE_NAME = "key"; private static final String TYPE_ATTRIBUTE_NAME = "type"; private static final String XSI_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema-instance"; private static final String XSD_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema"; private static final String[] SCHEMA_NAMESPACE_URIS = { XSI_NAMESPACE_URI, XSD_NAMESPACE_URI }; private static final String XSI_NAMESPACE_PREFIX = "xsi"; private static final String XSD_NAMESPACE_PREFIX = "xsd"; private static final String[] SCHEMA_NAMESPACE_PREFIXES = { XSI_NAMESPACE_PREFIX, XSD_NAMESPACE_PREFIX }; private static final String XSD_PREFIX_LEAD = "xsd:"; private static final int DEFAULT_SIZE = 10; // // Supported XML schema type correspondences enumeration // numeric values for types public static final int BOOLEAN_TYPE = 0; public static final int BYTE_TYPE = 1; public static final int DOUBLE_TYPE = 2; public static final int FLOAT_TYPE = 3; public static final int INT_TYPE = 4; public static final int LONG_TYPE = 5; public static final int SHORT_TYPE = 6; public static final int DATETIME_TYPE = 7; public static final int DECIMAL_TYPE = 8; public static final int INTEGER_TYPE = 9; public static final int BYTERRAY_TYPE = 10; public static final int STRING_TYPE = 11; //#!j2me{ public static final int DATE_TYPE = 12; public static final int TIME_TYPE = 13; //#j2me} // enumeration definition (string order must match numeric list, above) private static final EnumSet s_javaTypesEnum = new EnumSet(BOOLEAN_TYPE, new String[] { "java.lang.Boolean", "java.lang.Byte", "java.lang.Double", "java.lang.Float", "java.lang.Integer", "java.lang.Long", "java.lang.Short", "java.util.Date", "java.math.BigDecimal", "java.math.BigInteger", "byte[]", "java.lang.String", //#!j2me{ "java.sql.Date", "java.sql.Time", //#j2me} } ); // corresponding schema types (string order must match numeric list, above) private static final EnumSet s_schemaTypesEnum = new EnumSet(BOOLEAN_TYPE, new String[] { "boolean", "byte", "double", "float", "int", "long", "short", "dateTime", "decimal", "integer", "base64Binary", "string", //#!j2me{ "date", "time", //#j2me} } ); // // Member fields private String m_uri; private int m_index; private String m_name; /** * Default constructor. This uses a pre-defined name for the top-level * element. It'll be used by JiBX when no name information is supplied by * the mapping which references this custom marshaller/unmarshaller. */ public HashMapperStringToSchemaType() { m_uri = null; m_index = 0; m_name = "hashmap"; } /** * Aliased constructor. This takes a name definition for the top-level * element. It'll be used by JiBX when a name is supplied by the mapping * which references this custom marshaller/unmarshaller. * * @param uri namespace URI for the top-level element (also used for all * other names within the binding) * @param index namespace index corresponding to the defined URI within the * marshalling context definitions * @param name local name for the top-level element */ public HashMapperStringToSchemaType(String uri, int index, String name) { m_uri = uri; m_index = index; m_name = name; } /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#isExtension(int) */ public boolean isExtension(int index) { return false; } /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#marshal(java.lang.Object, * org.jibx.runtime.IMarshallingContext) */ public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (!(obj instanceof Map)) { throw new JiBXException("Invalid object type for marshaller"); } else if (!(ictx instanceof MarshallingContext)) { throw new JiBXException("Invalid object type for marshaller"); } else { // start by setting up added namespaces MarshallingContext ctx = (MarshallingContext)ictx; IXMLWriter xwrite = ctx.getXmlWriter(); int ixsi = xwrite.getNamespaces().length; String[][] extens = xwrite.getExtensionNamespaces(); if (extens != null) { for (int i = 0; i < extens.length; i++) { ixsi += extens[i].length; } } xwrite.pushExtensionNamespaces(SCHEMA_NAMESPACE_URIS); // generate start tag for containing element Map map = (Map)obj; ctx.startTagNamespaces(m_index, m_name, new int[] { ixsi, ixsi+1 }, SCHEMA_NAMESPACE_PREFIXES). attribute(m_index, SIZE_ATTRIBUTE_NAME, map.size()). closeStartContent(); // loop through all entries in hashmap Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { // first make sure we have a value Map.Entry entry = (Map.Entry)iter.next(); Object value = entry.getValue(); if (value != null) { // write element with key attribute ctx.startTagAttributes(m_index, ENTRY_ELEMENT_NAME); ctx.attribute(m_index, KEY_ATTRIBUTE_NAME, entry.getKey().toString()); // translate value object class to schema type String tname = value.getClass().getName(); int type = s_javaTypesEnum.getValue(tname); if (type < 0) { throw new JiBXException("Value of type " + tname + " with key " + entry.getKey() + " is not a supported type"); } // generate xsi:type attribute for value ctx.attribute(ixsi, TYPE_ATTRIBUTE_NAME, XSD_PREFIX_LEAD + s_schemaTypesEnum.getName(type)); ctx.closeStartContent(); // handle the actual value conversion based on type switch (type) { case BOOLEAN_TYPE: ctx.content(Utility.serializeBoolean (((Boolean)value).booleanValue())); break; case BYTE_TYPE: ctx.content(Utility. serializeByte(((Byte)value).byteValue())); break; case DOUBLE_TYPE: ctx.content(Utility. serializeDouble(((Double)value).doubleValue())); break; case FLOAT_TYPE: ctx.content(Utility. serializeFloat(((Float)value).floatValue())); break; case INT_TYPE: ctx.content(((Integer)value).intValue()); break; case LONG_TYPE: ctx.content(Utility. serializeLong(((Long)value).longValue())); break; case SHORT_TYPE: ctx.content(Utility. serializeShort(((Short)value).shortValue())); break; case DATETIME_TYPE: ctx.content(Utility.serializeDateTime((Date)value)); break; //#!j2me{ case DATE_TYPE: ctx.content(Utility. serializeSqlDate((java.sql.Date)value)); break; case TIME_TYPE: ctx.content(Utility. serializeSqlTime((java.sql.Time)value)); break; //#j2me} case BYTERRAY_TYPE: ctx.content(Utility.serializeBase64((byte[])value)); break; case DECIMAL_TYPE: case INTEGER_TYPE: case STRING_TYPE: ctx.content(value.toString()); break; } // finish with close tag for entry element ctx.endTag(m_index, ENTRY_ELEMENT_NAME); } } // finish with end tag for container element ctx.endTag(m_index, m_name); xwrite.popExtensionNamespaces(); } } /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext) */ public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException { return ctx.isAt(m_uri, m_name); } /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#unmarshal(java.lang.Object, * org.jibx.runtime.IUnmarshallingContext) */ public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (!ctx.isAt(m_uri, m_name)) { ctx.throwStartTagNameError(m_uri, m_name); } // lookup the prefixes assigned to required namespaces int nscnt = ctx.getActiveNamespaceCount(); String xsdlead = null; for (int i = nscnt-1; i >= 0; i--) { String uri = ctx.getActiveNamespaceUri(i); if (XSD_NAMESPACE_URI.equals(uri)) { String prefix = ctx.getActiveNamespacePrefix(i); if (!"".equals(prefix)) { xsdlead = prefix + ':'; break; } } } if (xsdlead == null) { throw new JiBXException ("Missing required schema namespace declaration"); } // create new hashmap if needed int size = ctx.attributeInt(m_uri, SIZE_ATTRIBUTE_NAME, DEFAULT_SIZE); Map map = (Map)obj; if (map == null) { map = new HashMap(size); } // process all entries present in document ctx.parsePastStartTag(m_uri, m_name); String tdflt = xsdlead + "string"; while (ctx.isAt(m_uri, ENTRY_ELEMENT_NAME)) { // unmarshal key and type from start tag attributes Object key = ctx.attributeText(m_uri, KEY_ATTRIBUTE_NAME); String tname = ctx.attributeText(XSI_NAMESPACE_URI, TYPE_ATTRIBUTE_NAME, tdflt); // convert type name to type index number int type = -1; if (tname.startsWith(xsdlead)) { type = s_schemaTypesEnum. getValue(tname.substring(xsdlead.length())); } if (type < 0) { throw new JiBXException("Value of type " + tname + " with key " + key + " is not a supported type"); } // deserialize content as specified type String text = ctx.parseElementText(m_uri, ENTRY_ELEMENT_NAME); Object value = null; switch (type) { case BOOLEAN_TYPE: value = Utility.parseBoolean(text) ? Boolean.TRUE : Boolean.FALSE; break; case BYTE_TYPE: value = new Byte(Utility.parseByte(text)); break; case DOUBLE_TYPE: value = new Double(Utility.parseDouble(text)); break; case FLOAT_TYPE: value = new Float(Utility.parseFloat(text)); break; case INT_TYPE: value = new Integer(Utility.parseInt(text)); break; case LONG_TYPE: value = new Long(Utility.parseLong(text)); break; case SHORT_TYPE: value = new Short(Utility.parseShort(text)); break; case DATETIME_TYPE: value = Utility.deserializeDateTime(text); break; //#!j2me{ case DATE_TYPE: value = Utility.deserializeSqlDate(text); break; case TIME_TYPE: value = Utility.deserializeSqlTime(text); break; //#j2me} case BYTERRAY_TYPE: value = Utility.deserializeBase64(text); break; case DECIMAL_TYPE: value = new BigDecimal(text); break; case INTEGER_TYPE: value = new BigInteger(text); break; case STRING_TYPE: value = text; break; } // add key-value pair to map map.put(key, value); } // finish by skipping past wrapper end tag ctx.parsePastEndTag(m_uri, m_name); return map; } } libjibx-java-1.1.6a/build/extras/org/jibx/extras/IdDefRefMapperBase.java 0000644 0001750 0001750 00000016242 10270750710 025757 0 ustar moeller moeller /* Copyright (c) 2005, Dennis M. Sosnoski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jibx.extras; import java.util.HashMap; import org.jibx.runtime.IAliasable; import org.jibx.runtime.IMarshallable; import org.jibx.runtime.IMarshaller; import org.jibx.runtime.IMarshallingContext; import org.jibx.runtime.IUnmarshaller; import org.jibx.runtime.IUnmarshallingContext; import org.jibx.runtime.JiBXException; import org.jibx.runtime.impl.MarshallingContext; import org.jibx.runtime.impl.UnmarshallingContext; /** *Abstract base custom marshaller/unmarshaller for an object that may have * multiple references. The first time an object is seen when marshalling the * full XML representation is generated; successive uses of the same object then * use XML references to the object ID. To use this class you need to create a * subclass with a constructor using the same signature as the one provided * (calling the base class constructor from your subclass constructor) and * implement the abstract {@link #getIdValue(java.lang.Object)} method in your subclass. You can * also override the provided {@link #getAttributeName()} method to change the * name used for the IDREF attribute, which must not match the name of an * attribute used in the normal marshalled form of the object. The name used for * this marshaller/unmarshaller in the mapping definition must match the name * used for the base object type being handled.
* * @author Dennis M. Sosnoski * @version 1.0 */ public abstract class IdDefRefMapperBase implements IMarshaller, IUnmarshaller, IAliasable { private String m_uri; private int m_index; private String m_name; /** * Aliased constructor taking a name definition for reference elements. The * subclass version will be used by JiBX to define the element name to be * used with this custom marshaller/unmarshaller. * * @param uri namespace URI for the top-level element * @param index namespace index corresponding to the defined URI within the * marshalling context definitions * @param name local name for the reference element */ public IdDefRefMapperBase(String uri, int index, String name) { m_uri = uri; m_index = index; m_name = name; } /** * Get the ID value from object being marshalled. * * @return ID value */ protected abstract String getIdValue(Object item); /** * Method which can be overridden to supply a different name for the ID * reference attribute. The attribute name used by default is just "ref". */ protected String getAttributeName() { return "ref"; } /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#isExtension(int) */ public boolean isExtension(int index) { return false; } /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#marshal(java.lang.Object, * org.jibx.runtime.IMarshallingContext) */ public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (obj == null) { return; } else if (!(ictx instanceof MarshallingContext)) { throw new JiBXException("Invalid context type for marshaller"); } else { // check if ID already defined MarshallingContext ctx = (MarshallingContext)ictx; HashMap map = ctx.getIdMap(); String id = getIdValue(obj); Object value = map.get(id); if (value == null) { if (obj instanceof IMarshallable) { // new id, write full representation and add to map map.put(id, obj); ((IMarshallable)obj).marshal(ctx); } else { throw new JiBXException("Object of type " + obj.getClass().getName() + " is not marshallable"); } } else if (value.equals(obj)) { // generate reference to previously-defined item ctx.startTagAttributes(m_index, m_name); ctx.attribute(0, getAttributeName(), id); ctx.closeStartEmpty(); } else { throw new JiBXException("Duplicate definition for ID " + id); } } } /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext) */ public boolean isPresent(IUnmarshallingContext ictx) throws JiBXException { return ictx.isAt(m_uri, m_name); } /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#unmarshal(java.lang.Object, * org.jibx.runtime.IUnmarshallingContext) */ public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (!ctx.isAt(m_uri, m_name)) { return null; } else { // check for reference to existing ID String id = ctx.attributeText(null, getAttributeName(), null); if (id == null) { // no ID value supplied, unmarshal full definition obj = ctx.unmarshalElement(); } else { // find object based on ID obj = ctx.findID(id, 0); ctx.parsePastEndTag(m_uri, m_name); if (obj == null) { ctx.throwStartTagException("Reference to undefined ID " + id); } } } return obj; } } libjibx-java-1.1.6a/build/extras/org/jibx/extras/IdRefMapperBase.java 0000644 0001750 0001750 00000013511 10217761632 025342 0 ustar moeller moeller /* Copyright (c) 2005, Dennis M. Sosnoski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jibx.extras; import org.jibx.runtime.IAliasable; import org.jibx.runtime.IMarshaller; import org.jibx.runtime.IMarshallingContext; import org.jibx.runtime.IUnmarshaller; import org.jibx.runtime.IUnmarshallingContext; import org.jibx.runtime.JiBXException; import org.jibx.runtime.impl.MarshallingContext; import org.jibx.runtime.impl.UnmarshallingContext; /** *Abstract base custom marshaller/unmarshaller for an object reference. This * marshals the reference as an empty element with a single IDREF attribute, and * unmarshals an element with the same structure to create a reference to the * object with that ID value. To use this class you need to create a subclass * with a constructor using the same signature as the one provided (calling the * base class constructor from your subclass constructor) and implement the * abstract {@link #getIdValue} method in your subclass. You can also override * the provided {@link #getAttributeName} method to change the name used for the * IDREF attribute. Note that this class can only be used when the definitions * precede the references in the XML document; if a referenced ID is not defined * the unmarshaller throws an exception.
* * @author Dennis M. Sosnoski * @version 1.0 */ public abstract class IdRefMapperBase implements IMarshaller, IUnmarshaller, IAliasable { private String m_uri; private int m_index; private String m_name; /** * Aliased constructor taking a name definition for the element. The * subclass version will be used by JiBX to define the element name to be * used with this custom marshaller/unmarshaller. * * @param uri namespace URI for the top-level element * @param index namespace index corresponding to the defined URI within the * marshalling context definitions * @param name local name for the top-level element */ public IdRefMapperBase(String uri, int index, String name) { m_uri = uri; m_index = index; m_name = name; } /** * Get the ID value from object being marshalled. * * @return ID value */ protected abstract String getIdValue(Object item); /** * Method which can be overridden to supply a different name for the ID * reference attribute. The attribute name used by default is just "ref". */ protected String getAttributeName() { return "ref"; } /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#isExtension(int) */ public boolean isExtension(int index) { return false; } /* (non-Javadoc) * @see org.jibx.runtime.IMarshaller#marshal(java.lang.Object, * org.jibx.runtime.IMarshallingContext) */ public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (obj == null) { return; } else if (!(ictx instanceof MarshallingContext)) { throw new JiBXException("Invalid context type for marshaller"); } else { // generate the element start tag MarshallingContext ctx = (MarshallingContext)ictx; ctx.startTagAttributes(m_index, m_name); // add attribute reference to object ID ctx.attribute(0, getAttributeName(), getIdValue(obj)); // close start tag for empty element ctx.closeStartEmpty(); } } /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext) */ public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException { return ctx.isAt(m_uri, m_name); } /* (non-Javadoc) * @see org.jibx.runtime.IUnmarshaller#unmarshal(java.lang.Object, * org.jibx.runtime.IUnmarshallingContext) */ public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (!ctx.isAt(m_uri, m_name)) { return null; } // get object reference for ID obj = ctx.attributeExistingIDREF(null, getAttributeName(), 0); // skip past the element ctx.parsePastEndTag(m_uri, m_name); return obj; } } libjibx-java-1.1.6a/build/extras/org/jibx/extras/JDOMWriter.java 0000644 0001750 0001750 00000017145 10270321622 024334 0 ustar moeller moeller /* Copyright (c) 2004, Dennis M. Sosnoski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jibx.extras; import java.io.IOException; import org.jdom.CDATA; import org.jdom.Comment; import org.jdom.DocType; import org.jdom.Document; import org.jdom.Element; import org.jdom.EntityRef; import org.jdom.Namespace; import org.jdom.ProcessingInstruction; import org.jdom.Text; import org.jibx.runtime.impl.XMLWriterNamespaceBase; /** * JDOM implementation of XML writer interface. TheDocument
that is
* created can be accessed by using getDocument()
.
*
* @author Andreas Brenk
* @version 1.0
*/
public class JDOMWriter extends XMLWriterNamespaceBase {
/**
* The JDOM Document
this writer is creating.
*/
private Document document;
/**
* The currently open Element
that is used for add* methods.
*/
private Element currentElement;
/**
* Creates a new instance with the given namespace URIs.
*/
public JDOMWriter(String[] namespaces) {
super(namespaces);
reset();
}
/**
* Creates a new instance with the given Document as target for marshalling.
*
* @param document must not be null
*/
public JDOMWriter(String[] namespaces, Document document) {
this(namespaces);
this.document = document;
if(document.hasRootElement()) {
this.currentElement = document.getRootElement();
}
}
/**
* Creates a new instance with the given Element as target for marshalling.
*
* @param currentElement must not be null
*/
public JDOMWriter(String[] namespaces, Element currentElement) {
this(namespaces, currentElement.getDocument());
this.currentElement = currentElement;
}
/**
* Does nothing.
*/
public void setIndentSpaces(int count, String newline, char indent) {
// do nothing
}
/**
* Does nothing.
*/
public void writeXMLDecl(String version, String encoding, String standalone) throws IOException {
// do nothing
}
public void startTagOpen(int index, String name) throws IOException {
Element newElement = new Element(name, getNamespace(index));
if(this.currentElement == null) {
this.document.setRootElement(newElement);
} else {
this.currentElement.addContent(newElement);
}
this.currentElement = newElement;
}
public void startTagNamespaces(int index, String name, int[] nums, String[] prefs) throws IOException {
// find the namespaces actually being declared
int[] deltas = openNamespaces(nums, prefs);
// create the start tag for element
startTagOpen(index, name);
// add namespace declarations to open element
for (int i = 0; i < deltas.length; i++) {
int slot = deltas[i];
this.currentElement.addNamespaceDeclaration(getNamespace(slot));
}
}
public void addAttribute(int index, String name, String value)
throws IOException {
this.currentElement.setAttribute(name, value, getNamespace(index));
}
public void closeStartTag() throws IOException {
incrementNesting();
}
public void closeEmptyTag() throws IOException {
incrementNesting();
decrementNesting();
this.currentElement = this.currentElement.getParentElement();
}
public void startTagClosed(int index, String name) throws IOException {
startTagOpen(index, name);
closeStartTag();
}
public void endTag(int index, String name) throws IOException {
decrementNesting();
this.currentElement = this.currentElement.getParentElement();
}
public void writeTextContent(String text) throws IOException {
this.currentElement.addContent(new Text(text));
}
public void writeCData(String text) throws IOException {
this.currentElement.addContent(new CDATA(text));
}
public void writeComment(String text) throws IOException {
this.currentElement.addContent(new Comment(text));
}
public void writeEntityRef(String name) throws IOException {
this.currentElement.addContent(new EntityRef(name));
}
public void writeDocType(String name, String sys, String pub, String subset)
throws IOException {
DocType docType;
if(null != pub) {
docType = new DocType(name, pub, sys);
} else if(null != sys) {
docType = new DocType(name, sys);
} else {
docType = new DocType(name);
}
if(null != subset) {
docType.setInternalSubset(subset);
}
this.document.setDocType(docType);
}
public void writePI(String target, String data) throws IOException {
this.currentElement.addContent(new ProcessingInstruction(target, data));
}
/**
* Does nothing.
*/
public void indent() throws IOException {
// do nothing
}
/**
* Does nothing.
*/
public void flush() throws IOException {
// do nothing
}
/**
* Does nothing.
*/
public void close() throws IOException {
// do nothing
}
public void reset() {
super.reset();
this.document = new Document();
this.currentElement = null;
}
/**
* @return the JDOM Document
this writer created.
*/
public Document getDocument() {
return document;
}
/**
* Does nothing.
*/
protected void defineNamespace(int index, String prefix) throws IOException {
// do nothing
}
/**
* Does nothing.
*/
protected void undefineNamespace(int index) {
// do nothing
}
/**
* This will retrieve (if in existence) or create (if not) a
* Namespace
for the supplied namespace index.
*/
private Namespace getNamespace(int index) {
String prefix = getNamespacePrefix(index);
String uri = getNamespaceUri(index);
if(prefix == null) {
return Namespace.getNamespace(uri);
} else {
return Namespace.getNamespace(prefix, uri);
}
}
}
libjibx-java-1.1.6a/build/extras/org/jibx/extras/ObjectArrayMapper.java 0000644 0001750 0001750 00000016035 10071714112 025754 0 ustar moeller moeller /*
Copyright (c) 2003, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.extras;
import java.util.ArrayList;
import org.jibx.runtime.IAliasable;
import org.jibx.runtime.IMarshallable;
import org.jibx.runtime.IMarshaller;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshaller;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.impl.MarshallingContext;
import org.jibx.runtime.impl.UnmarshallingContext;
/**
* Custom marshaller/unmarshaller for Object[]
instances. This
* handles mapping arrays typed as java.lang.Object[]
, where each
* item in the array must be of a mapped type. If a name is specified by the
* mapping definition that name is used as a wrapper around the elements
* representing the items in the array; otherwise, the elements are just handled
* inline.
Custom marshaller/unmarshaller for reference arrays of a particular type.
* This handles mapping arrays typed as object-type[]
, where the
* object-type is any class name (not a primitive type). All items in the
* array must be of a mapped type. If a name is specified by the mapping
* definition that name is used as a wrapper around the elements representing
* the items in the array; otherwise, the elements are just handled inline.