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 2004/03/02 03:54:07 UTC
cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases MarshalTests.java
zieg 2004/03/01 18:54:07
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
BindingType.java
v2/src/configschema/schema binding-config.xsd
v2/src/marshal/org/apache/xmlbeans/impl/marshal
ByNameRuntimeBindingType.java
ByNameTypeVisitor.java ByNameUnmarshaller.java
MarshalResult.java NamedXmlTypeVisitor.java
RuntimeBindingProperty.java
RuntimeBindingTypeTable.java
RuntimeGlobalProperty.java RuntimeTypeFactory.java
SimpleTypeVisitor.java UnmarshalResult.java
XmlTypeVisitor.java
v2/test/cases/marshal example_config.xml
v2/test/cases/marshal/com/mytest YourClass.java
v2/test/src/drt/drtcases MarshalTests.java
Added: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
WrappedArrayType.java
v2/src/marshal/org/apache/xmlbeans/impl/marshal
WrappedArrayRuntimeBindingType.java
WrappedArrayTypeVisitor.java
WrappedArrayUnmarshaller.java
Log:
support for wrapped array types
Revision Changes Path
1.12 +1 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingType.java
Index: BindingType.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingType.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- BindingType.java 12 Feb 2004 20:06:06 -0000 1.11
+++ BindingType.java 2 Mar 2004 02:54:07 -0000 1.12
@@ -108,6 +108,7 @@
static {
registerClassAndType(JaxbBean.class, org.apache.xml.xmlbeans.bindingConfig.JaxbBean.type);
registerClassAndType(ByNameBean.class, org.apache.xml.xmlbeans.bindingConfig.ByNameBean.type);
+ registerClassAndType(WrappedArrayType.class, org.apache.xml.xmlbeans.bindingConfig.WrappedArray.type);
registerClassAndType(SimpleBindingType.class, org.apache.xml.xmlbeans.bindingConfig.SimpleType.type);
registerClassAndType(SimpleDocumentBinding.class, org.apache.xml.xmlbeans.bindingConfig.SimpleDocumentBinding.type);
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/WrappedArrayType.java
Index: WrappedArrayType.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.binding.bts;
import javax.xml.namespace.QName;
/**
* A binding of a simple user-defined type that operates by
* delegating to another well-known (e.g., builtin) binding.
*/
public class WrappedArrayType extends BindingType
{
// ========================================================================
// Variables
private QName itemName;
private BindingTypeName itemType;
private boolean nillable;
// ========================================================================
// Constructors
public WrappedArrayType(BindingTypeName btName)
{
super(btName);
}
public WrappedArrayType(org.apache.xml.xmlbeans.bindingConfig.BindingType node)
{
this((org.apache.xml.xmlbeans.bindingConfig.WrappedArray)node);
}
public WrappedArrayType(org.apache.xml.xmlbeans.bindingConfig.WrappedArray node)
{
super(node);
this.itemName = node.getItemName();
final org.apache.xml.xmlbeans.bindingConfig.Mapping itype =
node.getItemType();
final JavaTypeName jName = JavaTypeName.forString(itype.getJavatype());
final XmlTypeName xName = XmlTypeName.forString(itype.getXmlcomponent());
this.itemType = BindingTypeName.forPair(jName, xName);
nillable = node.getNillable();
}
protected org.apache.xml.xmlbeans.bindingConfig.BindingType write(org.apache.xml.xmlbeans.bindingConfig.BindingType node)
{
final org.apache.xml.xmlbeans.bindingConfig.WrappedArray wa =
(org.apache.xml.xmlbeans.bindingConfig.WrappedArray)super.write(node);
wa.setItemName(itemName);
final org.apache.xml.xmlbeans.bindingConfig.Mapping mapping =
wa.addNewItemType();
mapping.setJavatype(itemType.getJavaName().toString());
mapping.setXmlcomponent(itemType.getXmlName().toString());
wa.setNillable(nillable);
return wa;
}
// ========================================================================
// Public methods
public QName getItemName()
{
return itemName;
}
public void setItemName(QName itemName)
{
this.itemName = itemName;
}
public BindingTypeName getItemType()
{
return itemType;
}
public void setItemType(BindingTypeName itemType)
{
this.itemType = itemType;
}
public boolean isNillable()
{
return nillable;
}
public void setNillable(boolean nillable)
{
this.nillable = nillable;
}
}
1.14 +2 -2 xml-xmlbeans/v2/src/configschema/schema/binding-config.xsd
Index: binding-config.xsd
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/configschema/schema/binding-config.xsd,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- binding-config.xsd 12 Feb 2004 21:18:15 -0000 1.13
+++ binding-config.xsd 2 Mar 2004 02:54:07 -0000 1.14
@@ -78,9 +78,9 @@
<xs:complexContent>
<xs:extension base="tns:binding-type">
<xs:sequence>
+ <xs:element name="item-name" type="xs:QName"/>
<xs:element name="item-type" type="tns:mapping"/>
- <xs:element name="array-rank" type="xs:int" minOccurs="0"/>
- <xs:element name="element-qname" type="xs:QName" minOccurs="0"/>
+ <xs:element name="nillable" type="xs:boolean" default="false" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
1.33 +6 -65 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java
Index: ByNameRuntimeBindingType.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- ByNameRuntimeBindingType.java 20 Feb 2004 00:38:44 -0000 1.32
+++ ByNameRuntimeBindingType.java 2 Mar 2004 02:54:07 -0000 1.33
@@ -18,14 +18,12 @@
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlRuntimeException;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
-import org.apache.xmlbeans.impl.binding.bts.BindingProperty;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
import org.apache.xmlbeans.impl.binding.bts.JavaTypeName;
import org.apache.xmlbeans.impl.binding.bts.MethodName;
import org.apache.xmlbeans.impl.binding.bts.QNameProperty;
-import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
import org.apache.xmlbeans.impl.marshal.util.collections.Accumulator;
import org.apache.xmlbeans.impl.marshal.util.collections.AccumulatorFactory;
@@ -179,12 +177,7 @@
final QName qn = prop.getQName();
- if (qn.getLocalPart().equals(localname)) {
- //QNames always uses "" for no namespace, but the incoming uri
- //might use null or "".
- return qn.getNamespaceURI().equals(uri == null ? "" : uri);
- }
- return false;
+ return UnmarshalResult.doesElementMatch(qn, localname, uri);
}
public int getElementPropertyCount()
@@ -251,12 +244,13 @@
this.beanClass = beanClass;
this.beanHasMulti = bean_has_multis;
this.bindingProperty = prop;
- this.unmarshaller = lookupUnmarshaller(prop, typeTable, loader);
- this.marshaller = lookupMarshaller(prop.getTypeName(), typeTable, loader);
+ final BindingTypeName type_name = prop.getTypeName();
+ this.unmarshaller = typeTable.lookupUnmarshaller(type_name, loader);
+ this.marshaller = typeTable.lookupMarshaller(type_name, loader);
- final BindingType binding_type = loader.getBindingType(prop.getTypeName());
+ final BindingType binding_type = loader.getBindingType(type_name);
if (binding_type == null) {
- throw new XmlException("unable to load " + prop.getTypeName());
+ throw new XmlException("unable to load " + type_name);
}
runtimeBindingType =
rttFactory.createRuntimeType(binding_type, typeTable, loader);
@@ -361,11 +355,6 @@
}
- public BindingType getType()
- {
- return getRuntimeBindingType().getBindingType();
- }
-
public RuntimeBindingType getRuntimeBindingType()
{
return runtimeBindingType;
@@ -383,54 +372,6 @@
public QName getName()
{
return bindingProperty.getQName();
- }
-
- private TypeUnmarshaller lookupUnmarshaller(BindingProperty prop,
- RuntimeBindingTypeTable table,
- BindingLoader loader)
- throws XmlException
- {
- assert prop != null;
- final BindingTypeName type_name = prop.getTypeName();
- assert type_name != null;
- final BindingType binding_type = loader.getBindingType(type_name);
- if (binding_type == null) {
- throw new XmlException("failed to load type: " + type_name);
- }
-
- TypeUnmarshaller um =
- table.getOrCreateTypeUnmarshaller(binding_type, loader);
- if (um == null) {
- throw new AssertionError("failed to get unmarshaller for " +
- type_name);
- }
- return um;
- }
-
- private TypeMarshaller lookupMarshaller(BindingTypeName type_name,
- RuntimeBindingTypeTable typeTable,
- BindingLoader loader)
- throws XmlException
- {
- final BindingType binding_type = loader.getBindingType(type_name);
- if (binding_type == null) {
- final String msg = "unable to load type for " + type_name;
- throw new XmlException(msg);
- }
- TypeMarshaller m = typeTable.getTypeMarshaller(binding_type);
- if (m != null) return m;
-
- if (binding_type instanceof SimpleBindingType) {
- SimpleBindingType stype = (SimpleBindingType)binding_type;
-
- final BindingTypeName asif_name = stype.getAsIfBindingTypeName();
- if (asif_name == null)
- throw new XmlException("no asif for " + stype);
-
- return lookupMarshaller(asif_name, typeTable, loader);
- }
-
- return null;
}
1.19 +0 -6 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java
Index: ByNameTypeVisitor.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ByNameTypeVisitor.java 19 Feb 2004 18:43:56 -0000 1.18
+++ ByNameTypeVisitor.java 2 Mar 2004 02:54:07 -0000 1.19
@@ -16,7 +16,6 @@
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.impl.binding.bts.BindingType;
import org.apache.xmlbeans.impl.util.XsTypeConverter;
import javax.xml.namespace.QName;
@@ -44,11 +43,8 @@
throws XmlException
{
super(obj, property, result);
- final BindingType pt = property.getType();
type = (ByNameRuntimeBindingType)getActualRuntimeBindingType();
-
-
maxElementPropCount = obj == null ? 0 : type.getElementPropertyCount();
maxAttributePropCount = obj == null ? 0 : type.getAttributePropertyCount();
}
@@ -170,8 +166,6 @@
protected int getAttributeCount()
throws XmlException
{
- if (attributeValues == null) initAttributes();
-
assert attributeNames.size() == attributeValues.size();
return attributeValues.size();
1.16 +2 -46 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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ByNameUnmarshaller.java 20 Feb 2004 00:38:44 -0000 1.15
+++ ByNameUnmarshaller.java 2 Mar 2004 02:54:07 -0000 1.16
@@ -17,7 +17,6 @@
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
-import org.apache.xmlbeans.impl.common.InvalidLexicalValueException;
final class ByNameUnmarshaller implements TypeUnmarshaller
{
@@ -60,7 +59,7 @@
context.skipElement();
} else {
//TODO: implement first one wins?, this is last one wins
- fillElementProp(prop, context, inter);
+ UnmarshalResult.fillElementProp(prop, context, inter);
}
}
@@ -76,49 +75,6 @@
}
- private static void fillElementProp(RuntimeBindingProperty prop,
- UnmarshalResult context,
- Object inter)
- throws XmlException
- {
- final TypeUnmarshaller um = prop.getTypeUnmarshaller(context);
- assert um != null;
-
- try {
- final String lexical_default = prop.getLexicalDefault();
- if (lexical_default != null) {
- context.setNextElementDefault(lexical_default);
- }
- final Object prop_val = um.unmarshal(context);
- prop.fill(inter, prop_val);
- }
- catch (InvalidLexicalValueException ilve) {
- //unlike attributes, the error has been added to the context
- //already via BaseSimpleTypeConveter...
- }
- }
-
-
- private static void fillAttributeProp(RuntimeBindingProperty prop,
- UnmarshalResult context,
- Object inter)
- throws XmlException
- {
- final TypeUnmarshaller um = prop.getTypeUnmarshaller(context);
- assert um != null;
-
- try {
- final Object prop_val = um.unmarshalAttribute(context);
- prop.fill(inter, prop_val);
- }
- catch (InvalidLexicalValueException ilve) {
- //TODO: review error messages
- String msg = "invalid value for " + prop.getName() +
- ": " + ilve.getMessage();
- context.addError(msg, ilve.getLocation());
- }
- }
-
private void deserializeAttributes(Object inter, UnmarshalResult context)
throws XmlException
{
@@ -126,7 +82,7 @@
RuntimeBindingProperty prop = findMatchingAttributeProperty(context);
if (prop != null) {
- fillAttributeProp(prop, context, inter);
+ UnmarshalResult.fillAttributeProp(prop, context, inter);
}
context.advanceAttribute();
1.16 +17 -2 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java
Index: MarshalResult.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- MarshalResult.java 19 Feb 2004 18:43:56 -0000 1.15
+++ MarshalResult.java 2 Mar 2004 02:54:07 -0000 1.16
@@ -24,6 +24,7 @@
import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
+import org.apache.xmlbeans.impl.binding.bts.WrappedArrayType;
import org.apache.xmlbeans.impl.common.XmlStreamUtils;
import org.apache.xmlbeans.impl.common.XmlWhitespace;
import org.apache.xmlbeans.impl.marshal.util.collections.ArrayIterator;
@@ -57,6 +58,8 @@
private boolean initedAttributes = false;
private int prefixCnt = 0;
+ //used for some array types
+ private int currIndex;
private static final String ATTRIBUTE_XML_TYPE = "CDATA";
private static final String NSPREFIX = "n";
@@ -92,15 +95,17 @@
{
assert property != null;
- BindingType btype = property.getType();
+ BindingType btype = property.getRuntimeBindingType().getBindingType();
- //TODO: cleanup instanceof
+ //TODO: cleanup instanceof -- Visitor?
if (btype instanceof ByNameBean) {
return new ByNameTypeVisitor(property, obj, result);
} else if (btype instanceof SimpleBindingType) {
return new SimpleTypeVisitor(property, obj, result);
} else if (btype instanceof BuiltinBindingType) {
return new SimpleTypeVisitor(property, obj, result);
+ } else if (btype instanceof WrappedArrayType) {
+ return new WrappedArrayTypeVisitor(property, obj, result);
}
throw new AssertionError("UNIMP TYPE: " + btype);
@@ -613,5 +618,15 @@
return result.createRuntimeBindingType(btype, property_value);
}
+
+ int getCurrIndex()
+ {
+ return currIndex;
+ }
+
+ void setCurrIndex(int currIndex)
+ {
+ this.currIndex = currIndex;
+ }
}
1.8 +3 -0 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NamedXmlTypeVisitor.java
Index: NamedXmlTypeVisitor.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NamedXmlTypeVisitor.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- NamedXmlTypeVisitor.java 19 Feb 2004 18:43:56 -0000 1.7
+++ NamedXmlTypeVisitor.java 2 Mar 2004 02:54:07 -0000 1.8
@@ -16,6 +16,7 @@
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.impl.util.XsTypeConverter;
import javax.xml.namespace.QName;
@@ -26,6 +27,8 @@
{
private final QName name;
private final RuntimeBindingType actualRuntimeBindingType;
+ protected static final String NIL_ATT_VAL =
+ XsTypeConverter.printBoolean(true).intern();
NamedXmlTypeVisitor(Object parentObject,
RuntimeBindingProperty property,
1.16 +1 -4 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingProperty.java
Index: RuntimeBindingProperty.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingProperty.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- RuntimeBindingProperty.java 20 Feb 2004 00:38:44 -0000 1.15
+++ RuntimeBindingProperty.java 2 Mar 2004 02:54:07 -0000 1.16
@@ -16,15 +16,12 @@
package org.apache.xmlbeans.impl.marshal;
import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.impl.binding.bts.BindingType;
import javax.xml.namespace.QName;
interface RuntimeBindingProperty
{
- BindingType getType();
-
RuntimeBindingType getRuntimeBindingType();
RuntimeBindingType getActualRuntimeType(Object property_value,
@@ -39,7 +36,7 @@
void fill(Object inter, Object prop_obj)
throws XmlException;
- //non simple type props can throw some runtime exception.
+ //non simple type props can throw an exception
CharSequence getLexical(Object parent, MarshalResult result)
throws XmlException;
1.15 +84 -1 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- RuntimeBindingTypeTable.java 19 Feb 2004 18:43:56 -0000 1.14
+++ RuntimeBindingTypeTable.java 2 Mar 2004 02:54:07 -0000 1.15
@@ -25,6 +25,7 @@
import org.apache.xmlbeans.impl.binding.bts.JavaTypeName;
import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
+import org.apache.xmlbeans.impl.binding.bts.WrappedArrayType;
import org.apache.xmlbeans.impl.common.ConcurrentReaderHashMap;
import org.apache.xmlbeans.impl.common.XmlWhitespace;
@@ -87,7 +88,7 @@
BindingLoader loader)
throws XmlException
{
- TypeUnmarshaller type_um;
+ final TypeUnmarshaller type_um;
//TODO: cleanup this nasty instanceof stuff (Visitor?)
if (type instanceof SimpleBindingType) {
@@ -102,6 +103,11 @@
ByNameRuntimeBindingType runtimeType =
(ByNameRuntimeBindingType)runtimeTypeFactory.createRuntimeType(type, this, loader);
type_um = new ByNameUnmarshaller(runtimeType);
+ } else if (type instanceof WrappedArrayType) {
+ WrappedArrayType wat = (WrappedArrayType)type;
+ WrappedArrayRuntimeBindingType runtimeType =
+ (WrappedArrayRuntimeBindingType)runtimeTypeFactory.createRuntimeType(type, this, loader);
+ type_um = new WrappedArrayUnmarshaller(runtimeType);
} else {
throw new AssertionError("UNIMPLEMENTED TYPE: " + type);
}
@@ -309,6 +315,83 @@
String msg = "unable to get simple type unmarshaller for " + stype +
" resolved to " + resolved;
throw new AssertionError(msg);
+ }
+
+ TypeUnmarshaller lookupUnmarshaller(BindingTypeName type_name,
+ BindingLoader loader)
+ throws XmlException
+ {
+ assert type_name != null;
+
+ final BindingType binding_type = loader.getBindingType(type_name);
+ if (binding_type == null) {
+ throw new XmlException("failed to load type: " + type_name);
+ }
+
+ return lookupUnmarshaller(binding_type, loader);
+ }
+
+ TypeUnmarshaller lookupUnmarshaller(BindingType binding_type,
+ BindingLoader loader)
+ throws XmlException
+ {
+ TypeUnmarshaller um =
+ this.getOrCreateTypeUnmarshaller(binding_type, loader);
+ if (um == null) {
+ throw new AssertionError("failed to get unmarshaller for " +
+ binding_type);
+ }
+ return um;
+ }
+
+ /**
+ *
+ * find marshaller for given type. Can return null if not found
+ *
+ * @param type_name
+ * @param loader
+ * @return marshaller or null if not found.
+ * @throws XmlException
+ */
+ TypeMarshaller lookupMarshaller(BindingTypeName type_name,
+ BindingLoader loader)
+ throws XmlException
+ {
+ final BindingType binding_type = loader.getBindingType(type_name);
+ if (binding_type == null) {
+ final String msg = "unable to load type for " + type_name;
+ throw new XmlException(msg);
+ }
+
+ return lookupMarshaller(binding_type, loader);
+ }
+
+ /**
+ * find marshaller for given type. Can return null if not found
+ *
+ * @param binding_type
+ * @param loader
+ * @return marshaller or null if not found.
+ * @throws XmlException
+ */
+ TypeMarshaller lookupMarshaller(BindingType binding_type,
+ BindingLoader loader)
+ throws XmlException
+ {
+ TypeMarshaller m = this.getTypeMarshaller(binding_type);
+ if (m != null) return m;
+
+ if (binding_type instanceof SimpleBindingType) {
+ SimpleBindingType stype = (SimpleBindingType)binding_type;
+
+ final BindingTypeName asif_name = stype.getAsIfBindingTypeName();
+ if (asif_name == null)
+ throw new XmlException("no asif for " + stype);
+
+ return lookupMarshaller(asif_name, loader);
+ }
+
+ return null;
}
}
1.15 +1 -1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeGlobalProperty.java
Index: RuntimeGlobalProperty.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeGlobalProperty.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- RuntimeGlobalProperty.java 20 Feb 2004 00:38:44 -0000 1.14
+++ RuntimeGlobalProperty.java 2 Mar 2004 02:54:07 -0000 1.15
@@ -33,7 +33,7 @@
this.runtimeBindingType = runtimeBindingType;
}
- public BindingType getType()
+ private BindingType getType()
{
return runtimeBindingType.getBindingType();
}
1.10 +4 -1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeTypeFactory.java
Index: RuntimeTypeFactory.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeTypeFactory.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- RuntimeTypeFactory.java 19 Feb 2004 18:43:56 -0000 1.9
+++ RuntimeTypeFactory.java 2 Mar 2004 02:54:07 -0000 1.10
@@ -18,9 +18,10 @@
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
-import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
+import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
+import org.apache.xmlbeans.impl.binding.bts.WrappedArrayType;
import org.apache.xmlbeans.impl.common.ConcurrentReaderHashMap;
import java.util.HashMap;
@@ -76,6 +77,8 @@
return new BuiltinRuntimeBindingType((BuiltinBindingType)type);
} else if (type instanceof SimpleBindingType) {
return new SimpleRuntimeBindingType((SimpleBindingType)type);
+ } else if (type instanceof WrappedArrayType) {
+ return new WrappedArrayRuntimeBindingType((WrappedArrayType)type);
}
throw new AssertionError("unknown type: " + type);
1.13 +4 -6 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleTypeVisitor.java
Index: SimpleTypeVisitor.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleTypeVisitor.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- SimpleTypeVisitor.java 19 Feb 2004 18:43:56 -0000 1.12
+++ SimpleTypeVisitor.java 2 Mar 2004 02:54:07 -0000 1.13
@@ -20,16 +20,15 @@
import javax.xml.namespace.QName;
-final class SimpleTypeVisitor extends NamedXmlTypeVisitor
+final class SimpleTypeVisitor
+ extends NamedXmlTypeVisitor
{
+ private final CharacterVisitor charVisitor;
+
private int state = START;
private QName attributeName;
private String xsiTypeAttVal;
- private static final String NIL_ATT_VAL =
- XsTypeConverter.printBoolean(true).intern();
- private final CharacterVisitor charVisitor;
-
public SimpleTypeVisitor(RuntimeBindingProperty property, Object obj,
MarshalResult result)
throws XmlException
@@ -95,7 +94,6 @@
protected int getAttributeCount()
throws XmlException
{
- //TODO: xsi:type for polymorphism
return attributeName == null ? 0 : 1;
}
1.8 +61 -0 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalResult.java
Index: UnmarshalResult.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalResult.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- UnmarshalResult.java 20 Feb 2004 00:38:44 -0000 1.7
+++ UnmarshalResult.java 2 Mar 2004 02:54:07 -0000 1.8
@@ -28,6 +28,7 @@
import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
import org.apache.xmlbeans.impl.richParser.XMLStreamReaderExt;
import org.apache.xmlbeans.impl.richParser.XMLStreamReaderExtImpl;
+import org.apache.xmlbeans.impl.common.InvalidLexicalValueException;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
@@ -824,6 +825,66 @@
catch (XMLStreamException e) {
throw new XmlException(e);
}
+ }
+
+ static void fillElementProp(RuntimeBindingProperty prop,
+ UnmarshalResult context,
+ Object inter)
+ throws XmlException
+ {
+ final TypeUnmarshaller um = prop.getTypeUnmarshaller(context);
+ assert um != null;
+
+ try {
+ final String lexical_default = prop.getLexicalDefault();
+ if (lexical_default != null) {
+ context.setNextElementDefault(lexical_default);
+ }
+ final Object prop_val = um.unmarshal(context);
+ prop.fill(inter, prop_val);
+ }
+ catch (InvalidLexicalValueException ilve) {
+ //unlike attributes, the error has been added to the context
+ //already via BaseSimpleTypeConveter...
+ }
+ }
+
+ static void fillAttributeProp(RuntimeBindingProperty prop,
+ UnmarshalResult context,
+ Object inter)
+ throws XmlException
+ {
+ final TypeUnmarshaller um = prop.getTypeUnmarshaller(context);
+ assert um != null;
+
+ try {
+ final Object prop_val = um.unmarshalAttribute(context);
+ prop.fill(inter, prop_val);
+ }
+ catch (InvalidLexicalValueException ilve) {
+ //TODO: review error messages
+ String msg = "invalid value for " + prop.getName() +
+ ": " + ilve.getMessage();
+ context.addError(msg, ilve.getLocation());
+ }
+ }
+
+ /**
+ * Do the supplied localname, uri pair match the given qname?
+ *
+ * @param qn name of element
+ * @param localname candidate localname
+ * @param uri candidtate uri
+ * @return
+ */
+ static boolean doesElementMatch(QName qn, String localname, String uri)
+ {
+ if (qn.getLocalPart().equals(localname)) {
+ //QNames always uses "" for no namespace, but the incoming uri
+ //might use null or "".
+ return qn.getNamespaceURI().equals(uri == null ? "" : uri);
+ }
+ return false;
}
}
1.10 +1 -1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/XmlTypeVisitor.java
Index: XmlTypeVisitor.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/XmlTypeVisitor.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XmlTypeVisitor.java 19 Feb 2004 18:43:56 -0000 1.9
+++ XmlTypeVisitor.java 2 Mar 2004 02:54:07 -0000 1.10
@@ -86,7 +86,7 @@
{
return this.getClass().getName() +
" prop=" + bindingProperty.getName() +
- " type=" + bindingProperty.getType().getName();
+ " type=" + bindingProperty.getRuntimeBindingType().getBindingType();
}
protected QName fillPrefix(final QName pname)
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayRuntimeBindingType.java
Index: WrappedArrayRuntimeBindingType.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.XmlException;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
import org.apache.xmlbeans.impl.binding.bts.WrappedArrayType;
import org.apache.xmlbeans.impl.marshal.util.collections.Accumulator;
import org.apache.xmlbeans.impl.marshal.util.collections.AccumulatorFactory;
import javax.xml.namespace.QName;
import java.lang.reflect.Array;
final class WrappedArrayRuntimeBindingType
extends RuntimeBindingType
{
private final WrappedArrayType wrappedArrayType;
private WAProperty elementProperty;
public WrappedArrayRuntimeBindingType(WrappedArrayType binding_type)
throws XmlException
{
super(binding_type);
wrappedArrayType = binding_type;
}
void initialize(RuntimeBindingTypeTable typeTable,
BindingLoader bindingLoader,
RuntimeTypeFactory rttFactory)
throws XmlException
{
final BindingTypeName item_type_name = wrappedArrayType.getItemType();
assert item_type_name != null;
final BindingType item_type = bindingLoader.getBindingType(item_type_name);
if (item_type == null) {
final String msg = "unable to lookup " + item_type_name +
" from type " + wrappedArrayType;
throw new XmlException(msg);
}
final RuntimeBindingType item_rtt =
rttFactory.createRuntimeType(item_type, typeTable, bindingLoader);
elementProperty =
new WAProperty(wrappedArrayType.getItemName(), item_rtt,
typeTable, bindingLoader);
}
RuntimeBindingProperty getElementProperty()
{
assert elementProperty != null;
return elementProperty;
}
Object createIntermediary(Object context)
{
return AccumulatorFactory.createAccumulator(getJavaType(),
elementProperty.getElementClass());
}
Object getFinalObjectFromIntermediary(Object inter, Object context)
{
Accumulator acc = (Accumulator)inter;
return acc.getFinalArray();
}
private static final class WAProperty
implements RuntimeBindingProperty
{
private final QName itemName;
private final RuntimeBindingType itemType;
private final TypeMarshaller marshaller; // used only for simple types
private final TypeUnmarshaller unmarshaller;
public WAProperty(QName item_name,
RuntimeBindingType item_type,
RuntimeBindingTypeTable type_table,
BindingLoader loader)
throws XmlException
{
itemName = item_name;
itemType = item_type;
final BindingType binding_type = item_type.getBindingType();
marshaller =
type_table.lookupMarshaller(binding_type, loader);
unmarshaller =
type_table.lookupUnmarshaller(binding_type, loader);
}
Class getElementClass()
{
return itemType.getJavaType();
}
public RuntimeBindingType getRuntimeBindingType()
{
return itemType;
}
public RuntimeBindingType getActualRuntimeType(Object property_value,
MarshalResult result)
throws XmlException
{
return MarshalResult.findActualRuntimeType(property_value,
itemType,
result);
}
public QName getName()
{
return itemName;
}
public TypeUnmarshaller getTypeUnmarshaller(UnmarshalResult context)
throws XmlException
{
return unmarshaller;
}
public void fill(Object inter, Object prop_obj)
throws XmlException
{
Accumulator acc = (Accumulator)inter;
acc.append(prop_obj);
}
//non simple type props can throw some runtime exception.
public CharSequence getLexical(Object value, MarshalResult result)
throws XmlException
{
assert value != null;
assert result != null;
assert marshaller != null;
return marshaller.print(value, result);
}
public Object getValue(Object parentObject, MarshalResult result)
throws XmlException
{
return Array.get(parentObject, result.getCurrIndex());
}
public boolean isSet(Object parentObject, MarshalResult result)
throws XmlException
{
if (itemType.isJavaPrimitive()) return true;
//TODO: call isSet? check nillable??
return getValue(parentObject, result) != null;
}
public boolean isMultiple()
{
throw new UnsupportedOperationException();
}
public boolean isNillable()
{
throw new UnsupportedOperationException();
}
public String getLexicalDefault()
{
return null;
}
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayTypeVisitor.java
Index: WrappedArrayTypeVisitor.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.XmlException;
import org.apache.xmlbeans.impl.util.XsTypeConverter;
import javax.xml.namespace.QName;
import java.lang.reflect.Array;
public class WrappedArrayTypeVisitor extends NamedXmlTypeVisitor
{
private final WrappedArrayRuntimeBindingType type;
private final int arrayLength;
private QName attributeName;
private String xsiTypeAttVal;
private int currIndex = -1;
WrappedArrayTypeVisitor(RuntimeBindingProperty property,
Object obj,
MarshalResult result)
throws XmlException
{
super(obj, property, result);
type = (WrappedArrayRuntimeBindingType)getActualRuntimeBindingType();
arrayLength = getArrayLength(obj);
}
private static int getArrayLength(Object obj)
{
return Array.getLength(obj);
}
protected int getState()
{
assert currIndex <= arrayLength; //ensure we don't go past the end
if (currIndex < 0) return START;
if (currIndex >= arrayLength) return END;
return CONTENT;
}
protected int advance()
throws XmlException
{
assert currIndex < arrayLength; //ensure we don't go past the end
do {
currIndex++;
if (currIndex == arrayLength) return END;
}
while (!currentItemHasValue());
assert currIndex >= 0;
assert (getState() == CONTENT);
return CONTENT;
}
private boolean currentItemHasValue()
throws XmlException
{
marshalResult.setCurrIndex(currIndex);
return type.getElementProperty().isSet(getParentObject(),
marshalResult);
}
private Object getCurrentValue()
throws XmlException
{
marshalResult.setCurrIndex(currIndex);
return type.getElementProperty().getValue(getParentObject(),
marshalResult);
}
public XmlTypeVisitor getCurrentChild()
throws XmlException
{
final Object value = getCurrentValue();
//TODO: avoid excessive object creation
return MarshalResult.createVisitor(type.getElementProperty(),
value,
marshalResult);
}
protected int getAttributeCount()
throws XmlException
{
return attributeName == null ? 0 : 1;
}
protected String getAttributeValue(int idx)
{
assert attributeName != null;
return xsiTypeAttVal == null ? NIL_ATT_VAL : xsiTypeAttVal;
}
protected QName getAttributeName(int idx)
{
assert attributeName != null;
return attributeName;
}
protected CharSequence getCharData()
{
throw new IllegalStateException("not text: " + this);
}
//TODO: refactor to avoid duplicate code in SimpleTypeVisitor
protected void initAttributes()
throws XmlException
{
if (getParentObject() == null) {
attributeName = fillPrefix(MarshalStreamUtils.XSI_NIL_QNAME);
} else if (needsXsiType()) {
attributeName = fillPrefix(MarshalStreamUtils.XSI_TYPE_QNAME);
final QName schema_type_name =
getActualRuntimeBindingType().getSchemaTypeName();
QName tn = fillPrefix(schema_type_name);
xsiTypeAttVal = XsTypeConverter.getQNameString(tn.getNamespaceURI(),
tn.getLocalPart(),
tn.getPrefix());
} else {
attributeName = null;
}
}
}
1.1 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayUnmarshaller.java
Index: WrappedArrayUnmarshaller.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.XmlException;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
import javax.xml.namespace.QName;
public class WrappedArrayUnmarshaller
implements TypeUnmarshaller
{
private final WrappedArrayRuntimeBindingType type;
public WrappedArrayUnmarshaller(WrappedArrayRuntimeBindingType rtt)
{
type = rtt;
}
public Object unmarshal(UnmarshalResult result)
throws XmlException
{
final Object inter = type.createIntermediary(result);
deserializeContents(inter, result);
return type.getFinalObjectFromIntermediary(inter, result);
}
//TODO: cleanup this code. We are doing extra work for assertion checking
//also might consider consolidating the common code with the ByNameUnmarshaller
private void deserializeContents(Object inter,
UnmarshalResult context)
throws XmlException
{
assert context.isStartElement();
final String ourStartUri = context.getNamespaceURI();
final String ourStartLocalName = context.getLocalName();
context.next();
while (context.advanceToNextStartElement()) {
assert context.isStartElement();
if (matchesItemElement(context)) {
UnmarshalResult.fillElementProp(type.getElementProperty(), context, inter);
}
}
assert context.isEndElement();
final String ourEndUri = context.getNamespaceURI();
final String ourEndLocalName = context.getLocalName();
assert ourStartUri.equals(ourEndUri) :
"expected=" + ourStartUri + " got=" + ourEndUri;
assert ourStartLocalName.equals(ourEndLocalName) :
"expected=" + ourStartLocalName + " got=" + ourEndLocalName;
if (context.hasNext()) context.next();
}
private boolean matchesItemElement(UnmarshalResult context)
{
final QName el_name = type.getElementProperty().getName();
return UnmarshalResult.doesElementMatch(el_name,
context.getLocalName(),
context.getNamespaceURI());
}
public Object unmarshalAttribute(UnmarshalResult result)
throws XmlException
{
throw new AssertionError("UNIMP");
}
public void initialize(RuntimeBindingTypeTable typeTable,
BindingLoader bindingLoader)
{
}
}
1.21 +50 -0 xml-xmlbeans/v2/test/cases/marshal/example_config.xml
Index: example_config.xml
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/example_config.xml,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- example_config.xml 20 Feb 2004 00:38:44 -0000 1.20
+++ example_config.xml 2 Mar 2004 02:54:07 -0000 1.21
@@ -172,7 +172,57 @@
<bin:qname>java:StringArray</bin:qname>
<bin:multiple>true</bin:multiple>
</bin:qname-property>
+
+ <bin:qname-property>
+ <bin:xmlcomponent>t=ArrayOfString@java:com.mytest</bin:xmlcomponent>
+ <bin:javatype>java.lang.String[]</bin:javatype>
+ <bin:getter>
+ <bin:method-name>getWrappedArrayOne</bin:method-name>
+ </bin:getter>
+ <bin:setter>
+ <bin:method-name>setWrappedArrayOne</bin:method-name>
+ <bin:param-type>java.lang.String[]</bin:param-type>
+ </bin:setter>
+ <bin:qname>java:WrappedArrayOne</bin:qname>
+ </bin:qname-property>
+
+ <bin:qname-property>
+ <bin:xmlcomponent>t=ArrayOfArrayOfString@java:com.mytest</bin:xmlcomponent>
+ <bin:javatype>java.lang.String[][]</bin:javatype>
+ <bin:getter>
+ <bin:method-name>getWrappedArrayTwo</bin:method-name>
+ </bin:getter>
+ <bin:setter>
+ <bin:method-name>setWrappedArrayTwo</bin:method-name>
+ <bin:param-type>java.lang.String[][]</bin:param-type>
+ </bin:setter>
+ <bin:qname>java:WrappedArrayTwo</bin:qname>
+ </bin:qname-property>
+
</bin:binding-type>
+
+
+ <bin:binding-type xsi:type="bin:wrapped-array" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <bin:xmlcomponent>t=ArrayOfString@java:com.mytest</bin:xmlcomponent>
+ <bin:javatype>java.lang.String[]</bin:javatype>
+ <bin:item-name>item</bin:item-name>
+ <bin:item-type>
+ <bin:xmlcomponent>t=string@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
+ <bin:javatype>java.lang.String</bin:javatype>
+ </bin:item-type>
+ </bin:binding-type>
+
+ <bin:binding-type xsi:type="bin:wrapped-array" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <bin:xmlcomponent>t=ArrayOfArrayOfString@java:com.mytest</bin:xmlcomponent>
+ <bin:javatype>java.lang.String[][]</bin:javatype>
+ <bin:item-name>aos</bin:item-name>
+ <bin:item-type>
+ <bin:xmlcomponent>t=ArrayOfString@java:com.mytest</bin:xmlcomponent>
+ <bin:javatype>java.lang.String[]</bin:javatype>
+ </bin:item-type>
+ </bin:binding-type>
+
+
<bin:binding-type xsi:type="bin:by-name-bean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<bin:xmlcomponent>t=MyClass@java:com.mytest</bin:xmlcomponent>
<bin:javatype>com.mytest.MyClass</bin:javatype>
1.11 +25 -0 xml-xmlbeans/v2/test/cases/marshal/com/mytest/YourClass.java
Index: YourClass.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/com/mytest/YourClass.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- YourClass.java 12 Feb 2004 20:06:30 -0000 1.10
+++ YourClass.java 2 Mar 2004 02:54:07 -0000 1.11
@@ -44,6 +44,11 @@
private QName qn = new QName("URI" + RND.nextInt(), "LNAME"+RND.nextInt());
private QName qn2 = new QName("URI" + RND.nextInt(), "LNAME"+RND.nextInt());
+
+ private String[] wrappedArrayOne = {"W1", "W2"};
+ private String[][] wrappedArrayTwo = {wrappedArrayOne, null, wrappedArrayOne};
+
+
//hack alert
static final Random RND = new Random();
@@ -214,6 +219,25 @@
this.qn2 = qn2;
}
+ public String[] getWrappedArrayOne()
+ {
+ return wrappedArrayOne;
+ }
+
+ public void setWrappedArrayOne(String[] wrappedArrayOne)
+ {
+ this.wrappedArrayOne = wrappedArrayOne;
+ }
+
+ public String[][] getWrappedArrayTwo()
+ {
+ return wrappedArrayTwo;
+ }
+
+ public void setWrappedArrayTwo(String[][] wrappedArrayTwo)
+ {
+ this.wrappedArrayTwo = wrappedArrayTwo;
+ }
public boolean equals(Object o)
{
@@ -231,6 +255,7 @@
if (myClass != null ? !myClass.equals(yourClass.myClass) : yourClass.myClass != null) return false;
if (!Arrays.equals(myClassArray, yourClass.myClassArray)) return false;
if (!Arrays.equals(stringArray, yourClass.stringArray)) return false;
+ if (!Arrays.equals(wrappedArrayOne, yourClass.wrappedArrayOne)) return false;
// if (strs != null ? !strs.equals(yourClass.strs) : yourClass.strs != null) return false;
if (qn != null ? !qn.equals(yourClass.qn) : yourClass.qn != null) return false;
1.37 +3 -1 xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java
Index: MarshalTests.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- MarshalTests.java 20 Feb 2004 00:38:44 -0000 1.36
+++ MarshalTests.java 2 Mar 2004 02:54:07 -0000 1.37
@@ -500,6 +500,8 @@
myelt.setAttrib(rnd.nextFloat());
myelt.setMyFloat(rnd.nextFloat());
myelt.setBooleanArray(bools);
+ myelt.setWrappedArrayOne(new String[]{"W1"+rnd.nextInt(), "W2" + rnd.nextInt()});
+ myelt.setWrappedArrayTwo(null);
final com.mytest.MyClass my_c = new com.mytest.MyClass();
myelt.setMyClass(my_c);
curr.setMyelt(myelt);
@@ -547,7 +549,7 @@
}
final long after_millis = System.currentTimeMillis();
final long diff = (after_millis - before_millis);
-// inform(" perf_out_obj = " + top_obj);
+ inform(" perf_out_obj = " + top_obj);
Assert.assertTrue(errors.isEmpty());
Assert.assertEquals(top_obj, out_obj);
inform("milliseconds: " + diff + " trials: " + trials);
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org