You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by zi...@apache.org on 2003/12/05 03:45:54 UTC
cvs commit: xml-xmlbeans/v2/test/cases/marshal doc2.xml
zieg 2003/12/04 18:45:54
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
BuiltinBindingLoader.java
v2/src/marshal/org/apache/xmlbeans/impl/marshal
ByNameUnmarshaller.java MarshalStreamUtils.java
NullUnmarshaller.java RuntimeBindingTypeTable.java
TypeUnmarshaller.java UnmarshalContextImpl.java
UnmarshallerImpl.java
v2/test/cases/marshal doc2.xml
Added: v2/src/marshal/org/apache/xmlbeans/impl/marshal
BaseSimpleTypeConverter.java
BooleanTypeConverter.java ByteTypeConverter.java
DoubleTypeConverter.java FloatTypeConverter.java
IntTypeConverter.java LongTypeConverter.java
ShortTypeConverter.java StringTypeConverter.java
Removed: v2/src/marshal/org/apache/xmlbeans/impl/marshal
AtomicLexerPrinter.java
AtomicSimpleTypeConverter.java
TransientCharSequence.java
v2/src/marshal/org/apache/xmlbeans/impl/marshal/builtin
BooleanLexerPrinter.java ByteLexerPrinter.java
DoubleLexerPrinter.java FloatLexerPrinter.java
IntLexerPrinter.java LongLexerPrinter.java
ShortLexerPrinter.java StringLexerPrinter.java
Log:
update unmarshalling to use new org.apache.xmlbeans.impl.richParser.XMLStreamReaderExt
and so delete lots of code that is now no longer needed
Revision Changes Path
1.6 +1 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BuiltinBindingLoader.java
Index: BuiltinBindingLoader.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BuiltinBindingLoader.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BuiltinBindingLoader.java 4 Dec 2003 21:14:55 -0000 1.5
+++ BuiltinBindingLoader.java 5 Dec 2003 02:45:54 -0000 1.6
@@ -182,6 +182,7 @@
addPojoJava("int", Integer.class.getName());
addPojoJava("short", Short.class.getName());
addPojoJava("byte", Byte.class.getName());
+ addPojoJava("boolean", Boolean.class.getName());
//TODO: deal with char and java.lang.Character
}
1.4 +17 -19 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameUnmarshaller.java
Index: ByNameUnmarshaller.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameUnmarshaller.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ByNameUnmarshaller.java 14 Nov 2003 00:40:29 -0000 1.3
+++ ByNameUnmarshaller.java 5 Dec 2003 02:45:54 -0000 1.4
@@ -76,8 +76,7 @@
return type.getFinalObjectFromIntermediary(inter, context);
}
- public Object unmarshalSimpleType(CharSequence lexicalValue,
- UnmarshalContextImpl context)
+ public Object unmarshalAttribute(UnmarshalContextImpl context)
{
throw new UnsupportedOperationException();
}
@@ -127,44 +126,43 @@
private static void fillAttributeProp(RuntimeBindingProperty prop,
- CharSequence lexical,
UnmarshalContextImpl context,
Object inter)
{
final TypeUnmarshaller um = prop.getTypeUnmarshaller(context);
assert um != null;
- final Object prop_val = um.unmarshalSimpleType(lexical, context);
+
+ final Object prop_val = um.unmarshalAttribute(context);
prop.fill(inter, prop_val);
}
private void deserializeAttributes(Object inter, UnmarshalContextImpl context)
{
- final int cnt = context.getAttributeCount();
- for (int att_idx = 0; att_idx < cnt; att_idx++) {
- RuntimeBindingProperty prop =
- findMatchingAttributeProperty(att_idx, context);
+ while (context.hasMoreAttributes()) {
+ RuntimeBindingProperty prop = findMatchingAttributeProperty(context);
+
if (prop != null) {
- String att_val = context.getAttributeValue(att_idx);
- fillAttributeProp(prop, att_val, context, inter);
+ fillAttributeProp(prop, context, inter);
}
+
+ context.advanceAttribute();
}
}
+ private RuntimeBindingProperty findMatchingAttributeProperty(UnmarshalContextImpl context)
+ {
+ String uri = context.getCurrentAttributeNamespaceURI();
+ String lname = context.getCurrentAttributeLocalName();
+
+ return type.getMatchingAttributeProperty(uri, lname);
+ }
+
private RuntimeBindingProperty findMatchingElementProperty(UnmarshalContextImpl context)
{
String uri = context.getNamespaceURI();
String lname = context.getLocalName();
return type.getMatchingElementProperty(uri, lname);
- }
-
- private RuntimeBindingProperty findMatchingAttributeProperty(int att_idx,
- UnmarshalContextImpl context)
- {
- String uri = context.getAttributeNamespaceURI(att_idx);
- String lname = context.getAttributeLocalName(att_idx);
-
- return type.getMatchingAttributeProperty(uri, lname);
}
//prepare internal data structures for use
1.6 +41 -104 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalStreamUtils.java
Index: MarshalStreamUtils.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalStreamUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MarshalStreamUtils.java 17 Nov 2003 19:29:35 -0000 1.5
+++ MarshalStreamUtils.java 5 Dec 2003 02:45:54 -0000 1.6
@@ -76,110 +76,6 @@
static final QName XSI_NIL_QNAME = new QName(XSI_NS, XSI_NIL_ATTR);
- //more efficient (hopefully) version of XmlStreamReader.getElementText()
- //TODO: plenty of room for optimizations here...
- static CharSequence getContent(XMLStreamReader reader, Collection errors)
- throws XMLStreamException
- {
- assert reader.isStartElement();
-
- reader.next(); //move past start element
-
- String content = null;
- StringBuffer buf = null;
-
- FOL:
- for (int state = reader.getEventType(); ; state = reader.next()) {
- switch (state) {
- case XMLStreamReader.END_DOCUMENT:
- throw new XmlRuntimeException("unexpected end of XML");
- case XMLStreamReader.END_ELEMENT:
- if (content == null) {
- content = "";
- }
- reader.next(); // eat the matching end elem
- break FOL;
- case XMLStreamReader.START_ELEMENT:
- //TODO: better error handling
- errors.add("skipping unexpected child element");
- skipElement(reader);
- break;
- case XMLStreamReader.CHARACTERS:
- if (content == null) {
- content = reader.getText();
- } else {
- if (buf == null) {
- buf = new StringBuffer(content);
- }
- buf.append(reader.getText());
- }
- break;
- case XMLStreamReader.PROCESSING_INSTRUCTION:
- case XMLStreamReader.COMMENT:
- break;
- default:
- throw new AssertionError("unexpected xml state " + state);
- }
-
- if (!reader.hasNext()) {
- throw new XmlRuntimeException("unexpected end of xml stream");
- }
-
- }
-
- if (buf == null) {
- assert (content != null) ;
- return content;
- } else {
- return buf.toString();
- }
- }
-
-
- static void getContent(TransientCharSequence cs,
- XMLStreamReader reader, Collection errors)
- throws XMLStreamException
- {
- assert reader.isStartElement();
-
- assert reader.hasNext();
- reader.next(); //move past start element
-
- cs.clear();
-
- FOL:
- for (int state = reader.getEventType(); ; state = reader.next()) {
- switch (state) {
- case XMLStreamReader.END_DOCUMENT:
- throw new XmlRuntimeException("unexpected end of XML");
- case XMLStreamReader.END_ELEMENT:
- reader.next(); // eat the matching end elem
- break FOL;
- case XMLStreamReader.START_ELEMENT:
- //TODO: better error handling
- errors.add("skipping unexpected child element");
- skipElement(reader);
- break;
- case XMLStreamReader.CHARACTERS:
- cs.append(reader.getTextCharacters(),
- reader.getTextStart(),
- reader.getTextLength());
- break;
- case XMLStreamReader.PROCESSING_INSTRUCTION:
- case XMLStreamReader.COMMENT:
- break;
- default:
- throw new AssertionError("unexpected xml state " + state);
- }
-
- if (!reader.hasNext()) {
- throw new XmlRuntimeException("unexpected end of xml stream");
- }
-
- }
- }
-
-
static void getXsiAttributes(XsiAttributeHolder holder,
XMLStreamReader reader,
Collection errors)
@@ -344,6 +240,47 @@
if (isXsiNilTrue(reader, i, errors)) return true;
}
return false;
+ }
+
+ static void advanceToFirstItemOfInterest(XMLStreamReader rdr)
+ {
+ try {
+ for (int state = rdr.getEventType(); rdr.hasNext(); state = rdr.next()) {
+ switch (state) {
+
+ //these are things we can handle...
+ case XMLStreamReader.START_ELEMENT:
+ return;
+
+ //eventually we'll handle these...
+ case XMLStreamReader.ATTRIBUTE:
+ case XMLStreamReader.CHARACTERS:
+ throw new AssertionError("UNIMPLEMENTED TYPE: " + state);
+
+ //bad news in the xml stream
+ case XMLStreamReader.END_DOCUMENT:
+ throw new XmlRuntimeException("unexpected end of XML");
+ case XMLStreamReader.END_ELEMENT:
+ throw new XmlRuntimeException("unexpected end of XML");
+
+ //skip these and keep going
+ case XMLStreamReader.PROCESSING_INSTRUCTION:
+ case XMLStreamReader.COMMENT:
+ case XMLStreamReader.START_DOCUMENT:
+ case XMLStreamReader.SPACE:
+ break;
+
+ default:
+ //this case pretty much means malformed xml or a bug
+ throw new XmlRuntimeException("unexpected xml state:" + state +
+ "in" + rdr);
+ }
+ }
+ throw new XmlRuntimeException("unexpected end of xml stream");
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
}
1.3 +1 -2 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NullUnmarshaller.java
Index: NullUnmarshaller.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NullUnmarshaller.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NullUnmarshaller.java 14 Nov 2003 00:40:29 -0000 1.2
+++ NullUnmarshaller.java 5 Dec 2003 02:45:54 -0000 1.3
@@ -73,8 +73,7 @@
return null;
}
- public Object unmarshalSimpleType(CharSequence lexicalValue,
- UnmarshalContextImpl context)
+ public Object unmarshalAttribute(UnmarshalContextImpl context)
{
throw new UnsupportedOperationException();
}
1.7 +18 -27 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingTypeTable.java
Index: RuntimeBindingTypeTable.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingTypeTable.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RuntimeBindingTypeTable.java 4 Dec 2003 21:14:56 -0000 1.6
+++ RuntimeBindingTypeTable.java 5 Dec 2003 02:45:54 -0000 1.7
@@ -62,14 +62,6 @@
import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
import org.apache.xmlbeans.impl.binding.bts.JavaTypeName;
import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
-import org.apache.xmlbeans.impl.marshal.builtin.BooleanLexerPrinter;
-import org.apache.xmlbeans.impl.marshal.builtin.ByteLexerPrinter;
-import org.apache.xmlbeans.impl.marshal.builtin.DoubleLexerPrinter;
-import org.apache.xmlbeans.impl.marshal.builtin.FloatLexerPrinter;
-import org.apache.xmlbeans.impl.marshal.builtin.IntLexerPrinter;
-import org.apache.xmlbeans.impl.marshal.builtin.LongLexerPrinter;
-import org.apache.xmlbeans.impl.marshal.builtin.ShortLexerPrinter;
-import org.apache.xmlbeans.impl.marshal.builtin.StringLexerPrinter;
import javax.xml.namespace.QName;
import java.util.HashMap;
@@ -80,7 +72,7 @@
/**
* Table of TypeMarshaller and TypeUnmarshaller objects keyed by BindingType
*/
-class RuntimeBindingTypeTable
+final class RuntimeBindingTypeTable
{
//key is BindingType, value is TTEntry
private final Map typeMap = new HashMap();
@@ -184,46 +176,45 @@
private void addBuiltins()
{
addXsdBuiltin("float", float.class.getName(),
- new AtomicSimpleTypeConverter(new FloatLexerPrinter()));
+ new FloatTypeConverter());
addXsdBuiltin("float", Float.class.getName(),
- new AtomicSimpleTypeConverter(new FloatLexerPrinter()));
+ new FloatTypeConverter());
addXsdBuiltin("double", double.class.getName(),
- new AtomicSimpleTypeConverter(new DoubleLexerPrinter()));
+ new DoubleTypeConverter());
addXsdBuiltin("double", Double.class.getName(),
- new AtomicSimpleTypeConverter(new DoubleLexerPrinter()));
+ new DoubleTypeConverter());
addXsdBuiltin("long", long.class.getName(),
- new AtomicSimpleTypeConverter(new LongLexerPrinter()));
+ new LongTypeConverter());
addXsdBuiltin("long", Long.class.getName(),
- new AtomicSimpleTypeConverter(new LongLexerPrinter()));
+ new LongTypeConverter());
addXsdBuiltin("int", int.class.getName(),
- new AtomicSimpleTypeConverter(new IntLexerPrinter()));
+ new IntTypeConverter());
addXsdBuiltin("int", Integer.class.getName(),
- new AtomicSimpleTypeConverter(new IntLexerPrinter()));
+ new IntTypeConverter());
addXsdBuiltin("short", short.class.getName(),
- new AtomicSimpleTypeConverter(new ShortLexerPrinter()));
+ new ShortTypeConverter());
addXsdBuiltin("short", Short.class.getName(),
- new AtomicSimpleTypeConverter(new ShortLexerPrinter()));
+ new ShortTypeConverter());
addXsdBuiltin("byte", byte.class.getName(),
- new AtomicSimpleTypeConverter(new ByteLexerPrinter()));
+ new ByteTypeConverter());
addXsdBuiltin("byte", Byte.class.getName(),
- new AtomicSimpleTypeConverter(new ByteLexerPrinter()));
+ new ByteTypeConverter());
addXsdBuiltin("boolean", boolean.class.getName(),
- new AtomicSimpleTypeConverter(new BooleanLexerPrinter()));
-// addXsdBuiltin("boolean", Boolean.class.getName(),
-// new AtomicSimpleTypeConverter(new BooleanLexerPrinter()));
-
+ new BooleanTypeConverter());
+ addXsdBuiltin("boolean", Boolean.class.getName(),
+ new BooleanTypeConverter());
addXsdBuiltin("string", String.class.getName(),
- new AtomicSimpleTypeConverter(new StringLexerPrinter()));
+ new StringTypeConverter());
addXsdBuiltin("token", String.class.getName(),
- new AtomicSimpleTypeConverter(new StringLexerPrinter()));
+ new StringTypeConverter());
}
1.4 +1 -3 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/TypeUnmarshaller.java
Index: TypeUnmarshaller.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/TypeUnmarshaller.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TypeUnmarshaller.java 14 Nov 2003 00:40:29 -0000 1.3
+++ TypeUnmarshaller.java 5 Dec 2003 02:45:54 -0000 1.4
@@ -80,7 +80,6 @@
* unmarshal the lexical value of an instance of xsd:anySimpleType.
* This could be called on an attribute value or on element content.
*
- * @param lexicalValue
* @param context
* @return Object representing java value of lexical
*
@@ -88,8 +87,7 @@
* <tt>unmarshalSimpleType</tt> operation is not supported
* by this TypeUnmarshaller.
*/
- Object unmarshalSimpleType(CharSequence lexicalValue,
- UnmarshalContextImpl context);
+ Object unmarshalAttribute(UnmarshalContextImpl context);
/**
1.4 +367 -41 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalContextImpl.java
Index: UnmarshalContextImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalContextImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UnmarshalContextImpl.java 4 Dec 2003 21:14:56 -0000 1.3
+++ UnmarshalContextImpl.java 5 Dec 2003 02:45:54 -0000 1.4
@@ -57,16 +57,25 @@
package org.apache.xmlbeans.impl.marshal;
+import org.apache.xmlbeans.GDate;
+import org.apache.xmlbeans.GDuration;
import org.apache.xmlbeans.UnmarshalContext;
+import org.apache.xmlbeans.XmlCalendar;
import org.apache.xmlbeans.XmlRuntimeException;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
+import org.apache.xmlbeans.impl.richParser.XMLStreamReaderExt;
+import org.apache.xmlbeans.impl.richParser.XMLStreamReaderExtImpl;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.Collection;
+import java.util.Date;
/**
* An UnmarshalContext holds the mutable state using by an Unmarshaller
@@ -80,25 +89,33 @@
final class UnmarshalContextImpl
implements UnmarshalContext
{
- private XMLStreamReader baseReader;
+ private XMLStreamReaderExt baseReader;
private final BindingLoader bindingLoader;
private final RuntimeBindingTypeTable typeTable;
private final Collection errors;
private final XsiAttributeHolder xsiAttributeHolder =
new XsiAttributeHolder();
+
+ private static final int INVALID = -1;
+
private boolean gotXsiAttributes;
- private final TransientCharSequence transientCharSequence =
- new TransientCharSequence();
+ private int currentAttributeIndex = INVALID;
+ private int currentAttributeCount = INVALID;
+
- UnmarshalContextImpl(XMLStreamReader baseReader,
+ UnmarshalContextImpl(XMLStreamReader reader,
BindingLoader bindingLoader,
RuntimeBindingTypeTable typeTable,
Collection errors)
{
- this.baseReader = baseReader;
+ this.baseReader = createExtendedReader(reader);
this.bindingLoader = bindingLoader;
this.errors = errors;
this.typeTable = typeTable;
+
+ if (reader != null) {
+ updateAttributeState();
+ }
}
@@ -106,23 +123,33 @@
RuntimeBindingTypeTable typeTable,
Collection errors)
{
- this.bindingLoader = bindingLoader;
- this.errors = errors;
- this.typeTable = typeTable;
+ this(null, bindingLoader, typeTable, errors);
}
public void setXmlStream(XMLStreamReader reader)
{
- baseReader = reader;
- xsiAttributeHolder.reset();
+ assert reader != null;
+
+ baseReader = createExtendedReader(reader);
+ updateAttributeState();
+ }
+
+ private static XMLStreamReaderExt createExtendedReader(XMLStreamReader reader)
+ {
+ if (reader instanceof XMLStreamReaderExt) {
+ return (XMLStreamReaderExt)reader;
+ } else {
+ return new XMLStreamReaderExtImpl(reader);
+ }
}
/**
*
* @return true if we have a non null XMLStreamReader
*/
- boolean hasXmlStream() {
+ boolean hasXmlStream()
+ {
return (baseReader != null);
}
@@ -166,18 +193,276 @@
// ======================= xml access methods =======================
- CharSequence getElementText()
+ String getStringValue()
+ {
+ try {
+ return baseReader.getStringValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ boolean getBooleanValue()
+ {
+ try {
+ return baseReader.getBooleanValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public byte getByteValue()
+ {
+ try {
+ return baseReader.getByteValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public short getShortValue()
+ {
+ try {
+ return baseReader.getShortValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public int getIntValue()
+ {
+ try {
+ return baseReader.getIntValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public long getLongValue()
+ {
+ try {
+ return baseReader.getLongValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public BigInteger getBigIntegerValue()
+ {
+ try {
+ return baseReader.getBigIntegerValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public BigDecimal getBigDecimalValue()
+ {
+ try {
+ return baseReader.getBigDecimalValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public float getFloatValue()
+ {
+ try {
+ return baseReader.getFloatValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public double getDoubleValue()
+ {
+ try {
+ return baseReader.getDoubleValue();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ InputStream getHexBinaryValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ InputStream getBase64Value()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ XmlCalendar getCalendarValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ Date getDateValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ GDate getGDateValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ GDuration getGDurationValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ QName getQNameValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ String getAttributeStringValue()
+ {
+ try {
+ return baseReader.getAttributeStringValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ boolean getAttributeBooleanValue()
+ {
+ try {
+ return baseReader.getAttributeBooleanValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public byte getAttributeByteValue()
+ {
+ try {
+ return baseReader.getAttributeByteValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public short getAttributeShortValue()
+ {
+ try {
+ return baseReader.getAttributeShortValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public int getAttributeIntValue()
+ {
+ try {
+ return baseReader.getAttributeIntValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public long getAttributeLongValue()
+ {
+ try {
+ return baseReader.getAttributeLongValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public BigInteger getAttributeBigIntegerValue()
{
try {
- MarshalStreamUtils.getContent(transientCharSequence,
- baseReader, errors);
- return transientCharSequence;
+ return baseReader.getAttributeBigIntegerValue(currentAttributeIndex);
}
catch (XMLStreamException e) {
throw new XmlRuntimeException(e);
}
}
+ public BigDecimal getAttributeBigDecimalValue()
+ {
+ try {
+ return baseReader.getAttributeBigDecimalValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public float getAttributeFloatValue()
+ {
+ try {
+ return baseReader.getAttributeFloatValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ public double getAttributeDoubleValue()
+ {
+ try {
+ return baseReader.getAttributeDoubleValue(currentAttributeIndex);
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ InputStream getAttributeHexBinaryValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ InputStream getAttributeBase64Value()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ XmlCalendar getAttributeCalendarValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ Date getAttributeDateValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ GDate getAttributeGDateValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ GDuration getAttributeGDurationValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
+ QName getAttributeQNameValue()
+ {
+ throw new AssertionError("unimp");
+ }
+
/**
* return the QName value found for xsi:type
@@ -214,11 +499,49 @@
*/
boolean advanceToNextStartElement()
{
+ boolean ret = MarshalStreamUtils.advanceToNextStartElement(baseReader);
+ updateAttributeState();
+ return ret;
+ }
+
+
+ int next()
+ {
+ try {
+ final int new_state = baseReader.next();
+ updateAttributeState();
+ return new_state;
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+ boolean hasNext()
+ {
+ try {
+ return baseReader.hasNext();
+ }
+ catch (XMLStreamException e) {
+ throw new XmlRuntimeException(e);
+ }
+ }
+
+
+ void updateAttributeState()
+ {
xsiAttributeHolder.reset();
gotXsiAttributes = false;
- return MarshalStreamUtils.advanceToNextStartElement(baseReader);
+ if (baseReader.isStartElement()) {
+ currentAttributeCount = baseReader.getAttributeCount();
+ currentAttributeIndex = 0;
+ } else {
+ currentAttributeIndex = INVALID;
+ currentAttributeCount = INVALID;
+ }
}
+
boolean isStartElement()
{
return baseReader.isStartElement();
@@ -246,45 +569,48 @@
return baseReader.getNamespaceURI();
}
- String getAttributeNamespaceURI(int att_idx)
+ void skipElement()
{
- return baseReader.getAttributeNamespace(att_idx);
+ MarshalStreamUtils.skipElement(baseReader);
+ updateAttributeState();
}
- String getAttributeLocalName(int att_idx)
- {
- return baseReader.getAttributeLocalName(att_idx);
- }
- String getAttributeValue(int att_idx)
+ void advanceAttribute()
{
- return baseReader.getAttributeValue(att_idx);
+ assert hasMoreAttributes();
+ assert currentAttributeCount != INVALID;
+ assert currentAttributeIndex != INVALID;
+
+ currentAttributeIndex++;
+
+ assert currentAttributeIndex <= currentAttributeCount;
}
- void skipElement()
+ boolean hasMoreAttributes()
{
- MarshalStreamUtils.skipElement(baseReader);
+ assert baseReader.isStartElement();
+
+ assert currentAttributeCount != INVALID;
+ assert currentAttributeIndex != INVALID;
+
+ return (currentAttributeIndex < currentAttributeCount);
}
- int next()
+ String getCurrentAttributeNamespaceURI()
{
- xsiAttributeHolder.reset();
- try {
- return baseReader.next();
- }
- catch (XMLStreamException e) {
- throw new XmlRuntimeException(e);
- }
+ assert currentAttributeCount != INVALID;
+ assert currentAttributeIndex != INVALID;
+
+ return baseReader.getAttributeNamespace(currentAttributeIndex);
}
- boolean hasNext()
+ String getCurrentAttributeLocalName()
{
- try {
- return baseReader.hasNext();
- }
- catch (XMLStreamException e) {
- throw new XmlRuntimeException(e);
- }
+ assert currentAttributeCount != INVALID;
+ assert currentAttributeIndex != INVALID;
+
+ return baseReader.getAttributeLocalName(currentAttributeIndex);
}
}
1.7 +7 -70 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshallerImpl.java
Index: UnmarshallerImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshallerImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- UnmarshallerImpl.java 4 Dec 2003 21:14:56 -0000 1.6
+++ UnmarshallerImpl.java 5 Dec 2003 02:45:54 -0000 1.7
@@ -67,11 +67,9 @@
import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
/**
* A Unmarshaller knows how to convert xml to java objects.
@@ -94,11 +92,11 @@
public Object unmarshal(XMLStreamReader reader)
throws XmlException
{
+ MarshalStreamUtils.advanceToFirstItemOfInterest(reader);
+
UnmarshalContextImpl context = createUnmarshallContext(reader,
new ArrayList());
- advanceToFirstItemOfInterest(reader);
-
final BindingType bindingType = determineRootType(context);
return unmarshalBindingType(bindingType, context);
@@ -108,7 +106,7 @@
UnmarshalContext context)
throws XmlException
{
- TypeUnmarshaller um =
+ final TypeUnmarshaller um =
typeTable.getTypeUnmarshaller(bindingType);
if (um == null) {
@@ -120,18 +118,10 @@
throw new XmlException("UnmarshalContext must have a" +
" non null XMLStreamReader");
}
- Object type_instance = um.unmarshal(our_context);
- final Collection errors = our_context.getErrorCollection();
- if (!errors.isEmpty()) {
- //TODO: review this ctor
- System.out.println("errors = " + errors);
- String msg = errorsToMsg(errors);
- throw new XmlException(msg, null,
- Collections.unmodifiableCollection(errors));
- }
+ our_context.updateAttributeState();
- return type_instance;
+ return um.unmarshal(our_context);
}
public Object unmarshallType(QName schemaType,
@@ -156,60 +146,6 @@
return bindingLoader.getBindingType(btname);
}
- private static String errorsToMsg(final Collection errors)
- {
- final int sz = errors.size();
- assert sz > 0;
-
- if (sz == 1) {
- return "unmarshalling error: " + errors.iterator().next();
- } else {
- return "unmarshalling errors (" + sz + ")";
- }
- }
-
- private void advanceToFirstItemOfInterest(XMLStreamReader rdr)
- throws XmlException
- {
- try {
- for (int state = rdr.getEventType(); rdr.hasNext(); state = rdr.next()) {
- switch (state) {
-
- //these are things we can handle...
- case XMLStreamReader.START_ELEMENT:
- return;
-
- //eventually we'll handle these...
- case XMLStreamReader.ATTRIBUTE:
- case XMLStreamReader.CHARACTERS:
- throw new AssertionError("UNIMPLEMENTED TYPE: " + state);
-
- //bad news in the xml stream
- case XMLStreamReader.END_DOCUMENT:
- throw new XmlException("unexpected end of XML");
- case XMLStreamReader.END_ELEMENT:
- throw new XmlException("unexpected end of XML");
-
- //skip these and keep going
- case XMLStreamReader.PROCESSING_INSTRUCTION:
- case XMLStreamReader.COMMENT:
- case XMLStreamReader.START_DOCUMENT:
- case XMLStreamReader.SPACE:
- break;
-
- default:
- //this case pretty much means malformed xml or a bug
- throw new XmlException("unexpected xml state:" + state +
- "in" + rdr);
- }
- }
- throw new XmlException("unexpected end of xml stream");
- }
- catch (XMLStreamException e) {
- throw new XmlException(e);
- }
- }
-
private BindingType determineRootType(UnmarshalContextImpl context)
throws XmlException
{
@@ -218,7 +154,8 @@
if (xsi_type == null) {
QName root_elem_qname = new QName(context.getNamespaceURI(),
context.getLocalName());
- final XmlTypeName type_name = XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, root_elem_qname);
+ final XmlTypeName type_name =
+ XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, root_elem_qname);
final BindingType doc_binding_type = getPojoBindingType(type_name);
SimpleDocumentBinding sd = (SimpleDocumentBinding)doc_binding_type;
return getPojoBindingType(sd.getTypeOfElement());
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BaseSimpleTypeConverter.java
Index: BaseSimpleTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
/**
* Basic XmlStreamReader based impl that can handle converting
* simple types of the form <a>4.54</a>.
*/
abstract class BaseSimpleTypeConverter
implements TypeConverter
{
public void initialize(RuntimeBindingTypeTable typeTable,
BindingLoader bindingLoader)
{
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BooleanTypeConverter.java
Index: BooleanTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.common.XsTypeConverter;
final class BooleanTypeConverter
extends BaseSimpleTypeConverter
{
public Object unmarshal(UnmarshalContextImpl context)
{
boolean b = context.getBooleanValue();
assert context.isEndElement();
context.next();
return Boolean.valueOf(b);
}
public Object unmarshalAttribute(UnmarshalContextImpl context)
{
boolean b = context.getAttributeBooleanValue();
return Boolean.valueOf(b);
}
//non simple types can throw a runtime exception
public CharSequence print(Object value, MarshalContextImpl context)
{
Boolean b = (Boolean)value;
return XsTypeConverter.printBoolean(b.booleanValue());
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByteTypeConverter.java
Index: ByteTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.common.XsTypeConverter;
final class ByteTypeConverter
extends BaseSimpleTypeConverter
{
public Object unmarshal(UnmarshalContextImpl context)
{
byte val = context.getByteValue();
assert context.isEndElement();
context.next();
return new Byte(val);
}
public Object unmarshalAttribute(UnmarshalContextImpl context)
{
byte val = context.getAttributeByteValue();
return new Byte(val);
}
//non simple types can throw a runtime exception
public CharSequence print(Object value, MarshalContextImpl context)
{
Byte val = (Byte)value;
return XsTypeConverter.printByte(val.byteValue());
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/DoubleTypeConverter.java
Index: DoubleTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.common.XsTypeConverter;
final class DoubleTypeConverter
extends BaseSimpleTypeConverter
{
public Object unmarshal(UnmarshalContextImpl context)
{
double val = context.getDoubleValue();
assert context.isEndElement();
context.next();
return new Double(val);
}
public Object unmarshalAttribute(UnmarshalContextImpl context)
{
double val = context.getAttributeDoubleValue();
return new Double(val);
}
//non simple types can throw a runtime exception
public CharSequence print(Object value, MarshalContextImpl context)
{
Double val = (Double)value;
return XsTypeConverter.printDouble(val.doubleValue());
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/FloatTypeConverter.java
Index: FloatTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.common.XsTypeConverter;
final class FloatTypeConverter
extends BaseSimpleTypeConverter
{
public Object unmarshal(UnmarshalContextImpl context)
{
float val = context.getFloatValue();
assert context.isEndElement();
context.next();
return new Float(val);
}
public Object unmarshalAttribute(UnmarshalContextImpl context)
{
float val = context.getAttributeFloatValue();
return new Float(val);
}
//non simple types can throw a runtime exception
public CharSequence print(Object value, MarshalContextImpl context)
{
Float val = (Float)value;
return XsTypeConverter.printFloat(val.floatValue());
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/IntTypeConverter.java
Index: IntTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.common.XsTypeConverter;
final class IntTypeConverter
extends BaseSimpleTypeConverter
{
public Object unmarshal(UnmarshalContextImpl context)
{
int val = context.getIntValue();
assert context.isEndElement();
context.next();
return new Integer(val);
}
public Object unmarshalAttribute(UnmarshalContextImpl context)
{
int val = context.getAttributeIntValue();
return new Integer(val);
}
//non simple types can throw a runtime exception
public CharSequence print(Object value, MarshalContextImpl context)
{
Integer val = (Integer)value;
return XsTypeConverter.printInt(val.intValue());
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/LongTypeConverter.java
Index: LongTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.common.XsTypeConverter;
final class LongTypeConverter
extends BaseSimpleTypeConverter
{
public Object unmarshal(UnmarshalContextImpl context)
{
long val = context.getLongValue();
assert context.isEndElement();
context.next();
return new Long(val);
}
public Object unmarshalAttribute(UnmarshalContextImpl context)
{
long val = context.getAttributeLongValue();
return new Long(val);
}
//non simple types can throw a runtime exception
public CharSequence print(Object value, MarshalContextImpl context)
{
Long val = (Long)value;
return XsTypeConverter.printLong(val.longValue());
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ShortTypeConverter.java
Index: ShortTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.common.XsTypeConverter;
final class ShortTypeConverter
extends BaseSimpleTypeConverter
{
public Object unmarshal(UnmarshalContextImpl context)
{
short val = context.getShortValue();
assert context.isEndElement();
context.next();
return new Short(val);
}
public Object unmarshalAttribute(UnmarshalContextImpl context)
{
short val = context.getAttributeShortValue();
return new Short(val);
}
//non simple types can throw a runtime exception
public CharSequence print(Object value, MarshalContextImpl context)
{
Short val = (Short)value;
return XsTypeConverter.printShort(val.shortValue());
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/StringTypeConverter.java
Index: StringTypeConverter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.impl.common.XsTypeConverter;
final class StringTypeConverter
extends BaseSimpleTypeConverter
{
public Object unmarshal(UnmarshalContextImpl context)
{
String val = context.getStringValue();
assert context.isEndElement();
context.next();
return val;
}
public Object unmarshalAttribute(UnmarshalContextImpl context)
{
return context.getAttributeStringValue();
}
//non simple types can throw a runtime exception
public CharSequence print(Object value, MarshalContextImpl context)
{
String val = (String)value;
return XsTypeConverter.printString(val);
}
}
1.4 +4 -1 xml-xmlbeans/v2/test/cases/marshal/doc2.xml
Index: doc2.xml
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/doc2.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- doc2.xml 17 Nov 2003 19:29:35 -0000 1.3
+++ doc2.xml 5 Dec 2003 02:45:54 -0000 1.4
@@ -14,13 +14,16 @@
<!-- <n1:Myelt></n1:Myelt>-->
<n1:Myatt>TheVeryImportant<!-- <n1:Myelt></n1:Myelt>-->Value</n1:Myatt>
</n1:MyClass>
- <n1:MyFloat>5555.4443</n1:MyFloat>
+
+<!-- test default ns-->
+ <MyFloat xmlns="java:com.mytest">888888.4443</MyFloat>
<n1:SomeBool>fal<!-- ok -->se</n1:SomeBool>
<n1:SomeBool>false</n1:SomeBool>
<n1:SomeBool>true</n1:SomeBool>
<n1:SomeBool>0</n1:SomeBool>
<n1:SomeBool>1</n1:SomeBool>
+ <SomeBool xmlns="java:com.mytest">1</SomeBool>
</n1:Myelt>
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org