You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by da...@apache.org on 2004/03/25 23:00:29 UTC
cvs commit: xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal MarshalResult.java RuntimeBindingTypeTable.java RuntimeTypeFactory.java
daveremy 2004/03/25 14:00:29
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
BindingProperty.java BindingType.java
BindingTypeVisitor.java ByNameBean.java
JaxrpcEnumType.java SimpleContentBean.java
v2/src/binding/org/apache/xmlbeans/impl/binding/compile
EnumerationPrintHelper.java Schema2Java.java
v2/src/binding/org/apache/xmlbeans/impl/binding/joust
CompilingJavaOutputStream.java
v2/src/configschema/schema binding-config.xsd
v2/src/marshal/org/apache/xmlbeans/impl/marshal
MarshalResult.java RuntimeBindingTypeTable.java
RuntimeTypeFactory.java
Added: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
GenericXmlProperty.java ListArrayType.java
Log:
Added JAX-RPC style lists and wildcards mapping to Schema2Java.
Contributed by Radu Preotiuc.
Revision Changes Path
1.16 +1 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingProperty.java
Index: BindingProperty.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingProperty.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- BindingProperty.java 25 Mar 2004 03:19:28 -0000 1.15
+++ BindingProperty.java 25 Mar 2004 22:00:28 -0000 1.16
@@ -225,6 +225,7 @@
registerClassAndType(QNameProperty.class, org.apache.xml.xmlbeans.bindingConfig.QnameProperty.type);
registerClassAndType(SimpleContentProperty.class, org.apache.xml.xmlbeans.bindingConfig.SimpleContentProperty.type);
registerClassAndType(ParticleProperty.class, org.apache.xml.xmlbeans.bindingConfig.ParticleProperty.type);
+ registerClassAndType(GenericXmlProperty.class, org.apache.xml.xmlbeans.bindingConfig.GenericXmlProperty.type);
}
public String toString()
1.16 +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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- BindingType.java 13 Mar 2004 03:46:57 -0000 1.15
+++ BindingType.java 25 Mar 2004 22:00:28 -0000 1.16
@@ -114,6 +114,7 @@
registerClassAndType(ByNameBean.class, org.apache.xml.xmlbeans.bindingConfig.ByNameBean.type);
registerClassAndType(SimpleContentBean.class, org.apache.xml.xmlbeans.bindingConfig.SimpleContentBean.type);
registerClassAndType(WrappedArrayType.class, org.apache.xml.xmlbeans.bindingConfig.WrappedArray.type);
+ registerClassAndType(ListArrayType.class, org.apache.xml.xmlbeans.bindingConfig.ListArray.type);
registerClassAndType(SimpleBindingType.class, org.apache.xml.xmlbeans.bindingConfig.SimpleType.type);
registerClassAndType(JaxrpcEnumType.class, org.apache.xml.xmlbeans.bindingConfig.JaxrpcEnumType.type);
registerClassAndType(SimpleDocumentBinding.class, org.apache.xml.xmlbeans.bindingConfig.SimpleDocumentBinding.type);
1.4 +3 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingTypeVisitor.java
Index: BindingTypeVisitor.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingTypeVisitor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BindingTypeVisitor.java 13 Mar 2004 03:46:57 -0000 1.3
+++ BindingTypeVisitor.java 25 Mar 2004 22:00:28 -0000 1.4
@@ -39,4 +39,7 @@
void visit(WrappedArrayType wrappedArrayType)
throws XmlException;
+
+ void visit(ListArrayType wrappedArrayType)
+ throws XmlException;
}
1.11 +35 -1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/ByNameBean.java
Index: ByNameBean.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/ByNameBean.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ByNameBean.java 13 Mar 2004 03:46:57 -0000 1.10
+++ ByNameBean.java 25 Mar 2004 22:00:28 -0000 1.11
@@ -41,6 +41,8 @@
private List props = new ArrayList(); // of QNameProperties
private Map eltProps = new HashMap(); // QName -> prop (elts)
private Map attProps = new HashMap(); // QName -> prop (attrs)
+ private GenericXmlProperty anyElement;
+ private GenericXmlProperty anyAttribute;
// ========================================================================
// Constructors
@@ -52,8 +54,20 @@
public ByNameBean(org.apache.xml.xmlbeans.bindingConfig.BindingType node) {
super(node);
+ org.apache.xml.xmlbeans.bindingConfig.ByNameBean bnNode =
+ (org.apache.xml.xmlbeans.bindingConfig.ByNameBean) node;
+
+ org.apache.xml.xmlbeans.bindingConfig.GenericXmlProperty gxp =
+ bnNode.getAnyProperty();
+ if (gxp != null)
+ setAnyElementProperty((GenericXmlProperty) BindingProperty.forNode(gxp));
+
+ gxp = bnNode.getAnyAttributeProperty();
+ if (gxp != null)
+ setAnyAttributeProperty((GenericXmlProperty) BindingProperty.forNode(gxp));
+
org.apache.xml.xmlbeans.bindingConfig.QnameProperty[] propArray =
- ((org.apache.xml.xmlbeans.bindingConfig.ByNameBean) node).getQnamePropertyArray();
+ bnNode.getQnamePropertyArray();
for (int i = 0; i < propArray.length; i++) {
addProperty((QNameProperty) BindingProperty.forNode(propArray[i]));
@@ -63,6 +77,22 @@
// ========================================================================
// Public methods
+ public GenericXmlProperty getAnyElementProperty() {
+ return anyElement;
+ }
+
+ public void setAnyElementProperty(GenericXmlProperty prop) {
+ anyElement = prop;
+ }
+
+ public GenericXmlProperty getAnyAttributeProperty() {
+ return anyAttribute;
+ }
+
+ public void setAnyAttributeProperty(GenericXmlProperty prop) {
+ anyAttribute = prop;
+ }
+
/**
* Returns an unmodifiable collection of QNameProperty objects.
*/
@@ -110,6 +140,10 @@
org.apache.xml.xmlbeans.bindingConfig.ByNameBean bnNode =
(org.apache.xml.xmlbeans.bindingConfig.ByNameBean) super.write(node);
+ if (anyElement != null)
+ anyElement.write(bnNode.addNewAnyProperty());
+ if (anyAttribute != null)
+ anyAttribute.write(bnNode.addNewAnyAttributeProperty());
for (Iterator i = props.iterator(); i.hasNext();) {
QNameProperty qProp = (QNameProperty) i.next();
org.apache.xml.xmlbeans.bindingConfig.QnameProperty qpNode = bnNode.addNewQnameProperty();
1.4 +2 -2 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/JaxrpcEnumType.java
Index: JaxrpcEnumType.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/JaxrpcEnumType.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JaxrpcEnumType.java 25 Mar 2004 03:19:28 -0000 1.3
+++ JaxrpcEnumType.java 25 Mar 2004 22:00:28 -0000 1.4
@@ -92,8 +92,8 @@
fromValueMethod.write(jnode.addNewFromValueMethod());
}
- if (getValueMethod != null) {
- getValueMethod.write(jnode.addNewGetValueMethod());
+ if (toXMLMethod != null) {
+ toXMLMethod.write(jnode.addNewToXMLMethod());
}
if (fromStringMethod != null) {
1.2 +25 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/SimpleContentBean.java
Index: SimpleContentBean.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/SimpleContentBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SimpleContentBean.java 9 Mar 2004 23:57:17 -0000 1.1
+++ SimpleContentBean.java 25 Mar 2004 22:00:28 -0000 1.2
@@ -36,6 +36,7 @@
// Variables
private SimpleContentProperty simpleContentProperty;
+ private GenericXmlProperty anyAttributeProperty;
private Map attProps = new LinkedHashMap(); // QName -> prop (attrs)
// ========================================================================
@@ -65,6 +66,12 @@
final SimpleContentProperty bprop =
(SimpleContentProperty)SimpleContentProperty.forNode(scp);
setSimpleContentProperty(bprop);
+
+ final org.apache.xml.xmlbeans.bindingConfig.GenericXmlProperty gxp =
+ simpleContentBean.getAnyAttributeProperty();
+
+ if (gxp != null)
+ setAnyAttributeProperty((GenericXmlProperty) GenericXmlProperty.forNode(gxp));
}
// ========================================================================
@@ -93,6 +100,17 @@
this.simpleContentProperty = simpleContentProperty;
}
+ public GenericXmlProperty getAnyAttributeProperty()
+ {
+ return anyAttributeProperty;
+ }
+
+ public void setAnyAttributeProperty(GenericXmlProperty prop)
+ {
+ anyAttributeProperty = prop;
+ }
+
+
/**
* Adds a new property
@@ -130,6 +148,13 @@
final org.apache.xml.xmlbeans.bindingConfig.SimpleContentProperty sc_prop =
bnNode.addNewSimpleContentProperty();
simpleContentProperty.write(sc_prop);
+
+ if (anyAttributeProperty != null)
+ {
+ final org.apache.xml.xmlbeans.bindingConfig.GenericXmlProperty gx_prop =
+ bnNode.addNewAnyAttributeProperty();
+ anyAttributeProperty.write(gx_prop);
+ }
for (Iterator i = attProps.entrySet().iterator(); i.hasNext();) {
Map.Entry e = (Map.Entry)i.next();
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/GenericXmlProperty.java
Index: GenericXmlProperty.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;
/**
* Property used by the <xs:any> mapping
*/
public class GenericXmlProperty extends BindingProperty {
// ========================================================================
// Constructors
public GenericXmlProperty() {
super();
}
public GenericXmlProperty(org.apache.xml.xmlbeans.bindingConfig.BindingProperty node) {
super(node);
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/ListArrayType.java
Index: ListArrayType.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 org.apache.xmlbeans.XmlException;
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 ListArrayType extends BindingType
{
// ========================================================================
// Variables
private BindingTypeName itemType;
// ========================================================================
// Constructors
public ListArrayType(BindingTypeName btName)
{
super(btName);
}
public ListArrayType(org.apache.xml.xmlbeans.bindingConfig.BindingType node)
{
this((org.apache.xml.xmlbeans.bindingConfig.ListArray)node);
}
public ListArrayType(org.apache.xml.xmlbeans.bindingConfig.ListArray node)
{
super(node);
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);
}
protected org.apache.xml.xmlbeans.bindingConfig.BindingType write(org.apache.xml.xmlbeans.bindingConfig.BindingType node)
{
final org.apache.xml.xmlbeans.bindingConfig.ListArray wa =
(org.apache.xml.xmlbeans.bindingConfig.ListArray)super.write(node);
final org.apache.xml.xmlbeans.bindingConfig.Mapping mapping =
wa.addNewItemType();
mapping.setJavatype(itemType.getJavaName().toString());
mapping.setXmlcomponent(itemType.getXmlName().toString());
return wa;
}
public void accept(BindingTypeVisitor visitor) throws XmlException
{
visitor.visit(this);
}
// ========================================================================
// Public methods
public BindingTypeName getItemType()
{
return itemType;
}
public void setItemType(BindingTypeName itemType)
{
this.itemType = itemType;
}
}
1.2 +25 -5 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/EnumerationPrintHelper.java
Index: EnumerationPrintHelper.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/EnumerationPrintHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EnumerationPrintHelper.java 21 Mar 2004 01:58:27 -0000 1.1
+++ EnumerationPrintHelper.java 25 Mar 2004 22:00:28 -0000 1.2
@@ -85,10 +85,11 @@
private static final int T_URI = 21; // java.net.URI
private static final int T_BYTE_ARRAY = 22; // byte[]
- EnumerationPrintHelper(JavaTypeName typeName, ExpressionFactory exprFactory, int schemaTypeCode)
+ EnumerationPrintHelper(JavaTypeName typeName, ExpressionFactory exprFactory, SchemaType schemaType)
{
- if (schemaTypeCode == SchemaType.BTC_BASE_64_BINARY ||
- schemaTypeCode == SchemaType.BTC_HEX_BINARY)
+ mSchemaTypeCode = extractTypeCode(schemaType);
+ if (mSchemaTypeCode == SchemaType.BTC_BASE_64_BINARY ||
+ mSchemaTypeCode == SchemaType.BTC_HEX_BINARY)
mArray = typeName.getArrayDepth() > 1;
else
mArray = typeName.getArrayDepth() > 0;
@@ -99,7 +100,7 @@
t = typeName.getArrayItemType(1).toString();
else
t = typeName.toString();
- mSchemaTypeCode = schemaTypeCode;
+
switch (t.charAt(0))
{
case 'j':
@@ -311,7 +312,7 @@
return result;
}
- public Expression getFromStringExpr(Variable param) {
+ public Expression getFromStringExpr(Expression param) {
Expression result = null;
String s = param.getMemento().toString();
switch (mTypeCode)
@@ -575,5 +576,24 @@
{
return mSchemaTypeCode == SchemaType.BTC_BASE_64_BINARY ||
mSchemaTypeCode == SchemaType.BTC_HEX_BINARY;
+ }
+
+ private int extractTypeCode(SchemaType sType) {
+ boolean done = false;
+ while (!done) {
+ switch (sType.getSimpleVariety()) {
+ case SchemaType.ATOMIC:
+ done = true;
+ break;
+ case SchemaType.UNION:
+ throw new IllegalArgumentException("Unions are not currently supported");
+ case SchemaType.LIST:
+ sType = sType.getListItemType();
+ break;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+ return sType.getPrimitiveType().getBuiltinTypeCode();
}
}
1.18 +278 -52 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java
Index: Schema2Java.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Schema2Java.java 21 Mar 2004 01:58:27 -0000 1.17
+++ Schema2Java.java 25 Mar 2004 22:00:28 -0000 1.18
@@ -75,6 +75,9 @@
{"java.lang.Integer", "java.lang.Boolean", "java.lang.Float",
"java.lang.Long", "java.lang.Double", "java.lang.Short",
"java.lang.Character"};
+ private static String WILDCARD_ELEMENT_MAPPING = "javax.xml.soap.SOAPElement";
+ private static String WILDCARD_ATTRIBUTE_MAPPING = "javax.xml.soap.SOAPElement";
+ private static final String xsns = "http://www.w3.org/2001/XMLSchema";
// ========================================================================
// Constructors
@@ -265,9 +268,13 @@
if (sType.isSimpleType()) {
// simple types are atomic
+ // the order of these checks is important: an enumeration of lists will
+ // be both an enumeration and a list
// todo: what about simple content, custom codecs, etc?
if (isEnumeration(sType))
scratch = new Scratch(sType, xmlName, Scratch.ENUM_TYPE);
+ else if (isList(sType))
+ scratch = new Scratch(sType, xmlName, Scratch.LIST_TYPE);
else
scratch = new Scratch(sType, xmlName, Scratch.ATOMIC_TYPE);
} else if (sType.isDocumentType()) {
@@ -331,6 +338,23 @@
return;
}
+ case Scratch.LIST_TYPE:
+ {
+ SchemaType itemType = getListItemType(scratch.getSchemaType());
+ Scratch itemScratch = scratchForSchemaType(itemType);
+ JavaTypeName itemName = null;
+ if (itemScratch == null) {
+ itemName = getTypeNameFromLoader(itemType);
+ }
+ else {
+ // The type is in the current scratch area
+ resolveJavaName(itemScratch);
+ itemName = itemScratch.getJavaName();
+ }
+ if (itemName != null)
+ scratch.setJavaName(JavaTypeName.forArray(itemName, 1));
+ return;
+ }
case Scratch.LITERALARRAY_TYPE:
{
SchemaType itemType = getLiteralArrayItemType(scratch.getSchemaType());
@@ -338,18 +362,8 @@
getProperties()[0].hasNillable() != SchemaProperty.NEVER;
Scratch itemScratch = scratchForSchemaType(itemType);
JavaTypeName itemName = null;
- if (itemScratch == null)
- {
- BindingType bType = mLoader.getBindingType(mLoader.
- lookupPojoFor(XmlTypeName.forSchemaType(itemType)));
- if (bType != null)
- itemName = bType.getName().getJavaName();
- else if (itemType.isBuiltinType())
- logError("Bultin type " + itemType.getName() + " is not supported",
- null, itemType);
- else
- throw new IllegalStateException(itemType.getName().toString()+
- " type is not on mLoader");
+ if (itemScratch == null) {
+ itemName = getTypeNameFromLoader(itemType);
}
else
{
@@ -488,10 +502,16 @@
bindingFile.addBindingType(enumResult, true, true);
break;
+ case Scratch.LIST_TYPE:
+ ListArrayType listResult = new ListArrayType(btName);
+ scratch.setBindingType(listResult);
+ bindingFile.addBindingType(listResult, shouldBeFromJavaDefault(btName), true);
+ break;
+
case Scratch.LITERALARRAY_TYPE:
WrappedArrayType arrayResult = new WrappedArrayType(btName);
scratch.setBindingType(arrayResult);
- bindingFile.addBindingType(arrayResult, true, true);
+ bindingFile.addBindingType(arrayResult, shouldBeFromJavaDefault(btName), true);
break;
case Scratch.SOAPARRAY:
@@ -563,8 +583,7 @@
seenMethodNames.add(prop.getSetterName());
}
- if (schemaType.getContentType() == SchemaType.SIMPLE_CONTENT/* &&
- baseType.isSimpleType()*/) {
+ if (schemaType.getContentType() == SchemaType.SIMPLE_CONTENT) {
// Go up the type hierarchy to find the first simple type ancestor of
// this complex type
while (!baseType.isSimpleType())
@@ -581,7 +600,33 @@
bType.getName().getJavaName()));
prop.setGetterName(MethodName.create("get" + propName));
prop.setBindingType(bType);
- scratch.addSimpleContentProperty(prop);
+ scratch.setSimpleContentProperty(prop);
+ }
+ else {
+ // Handle the element wildcards
+ if (schemaType.hasElementWildcards()) {
+ // First, we have to see if it's just one wildcard or more
+ boolean multiple = countWildcards(schemaType.getContentModel()) > 1;
+ // We have to look at the base type and check multiplicity
+ if (baseType != null &&
+ baseType.getBuiltinTypeCode() != SchemaType.BTC_ANY_TYPE) {
+ boolean hasBaseElementWildcards = baseType.hasElementWildcards();
+ boolean baseMultiple = countWildcards(baseType.getContentModel()) > 1;
+ if (hasBaseElementWildcards && multiple != baseMultiple)
+ logError("Could not bind type\"" + schemaType.getName() +
+ "\" because its base type \"" + baseType.getName() +
+ "\" has only one element wildcard and the current type has more.",
+ null, schemaType);
+ }
+ GenericXmlProperty prop = new GenericXmlProperty();
+ String propName = "_any";
+ BindingType bType = getWildcardElementBindingType(multiple);
+ prop.setSetterName(MethodName.create("set" + propName,
+ bType.getName().getJavaName()));
+ prop.setGetterName(MethodName.create("get" + propName));
+ prop.setBindingType(bType);
+ scratch.setAnyElementProperty(prop);
+ }
}
if (derivationType == SchemaType.DT_RESTRICTION)
@@ -590,7 +635,20 @@
return;
}
- // now deal with remaining props
+ // Handle the attribute wildcards
+ // No check is necessary, because it always maps to the same type if present
+ if (schemaType.hasAttributeWildcards()) {
+ String propName = "_anyAttribute";
+ GenericXmlProperty prop = new GenericXmlProperty();
+ BindingType bType = getWildcardAttributeBindingType();
+ prop.setSetterName(MethodName.create("set" + propName,
+ bType.getName().getJavaName()));
+ prop.setGetterName(MethodName.create("get" + propName));
+ prop.setBindingType(bType);
+ scratch.setAnyAttributeProperty(prop);
+ }
+
+ // Now deal with remaining props
SchemaProperty[] props = schemaType.getProperties();
for (int i = 0; i < props.length; i++) {
QNameProperty prop = (QNameProperty) (props[i].isAttribute() ? seenAttrProps : seenEltProps).get(props[i].getName());
@@ -598,8 +656,8 @@
// already seen property: verify multiplicity looks cool
if (prop.isMultiple() != isMultiple(props[i])) {
logError("Could not bind element \"" + props[i].getName() +
- "\" because the corresponding element in the base type has a " +
- "different 'maxOccurs' value", null, props[i]);
+ "\" because the corresponding element in the base type has a " +
+ "different 'maxOccurs' value", null, props[i]);
}
// todo: think about optionality and nillability too
@@ -639,7 +697,8 @@
*/
private void resolveJavaArray(Scratch scratch)
{
- if (scratch.getCategory() != Scratch.LITERALARRAY_TYPE)
+ if (scratch.getCategory() != Scratch.LITERALARRAY_TYPE &&
+ scratch.getCategory() != Scratch.LIST_TYPE)
return;
if (scratch.isStructureResolved())
@@ -647,24 +706,39 @@
scratch.setStructureResolved(true);
- if (!(scratch.getBindingType() instanceof WrappedArrayType))
+ BindingType scratchBindingType = scratch.getBindingType();
+ if (scratchBindingType instanceof WrappedArrayType) {
+ WrappedArrayType bType = (WrappedArrayType) scratchBindingType;
+ JavaTypeName itemName = scratch.getJavaName().getArrayItemType(1);
+ assert(itemName != null);
+ SchemaType sType = getLiteralArrayItemType(scratch.getSchemaType());
+ assert sType != null : "This was already checked and determined to be non-null";
+ SchemaProperty prop = scratch.getSchemaType().getProperties()[0];
+ bType.setItemName(prop.getName());
+ BindingType itemType = bindingTypeForSchemaType(sType);
+ if (itemType == null)
+ throw new IllegalStateException("Type " + sType.getName() +
+ " not found in type loader");
+
+ bType.setItemNillable(prop.hasNillable() != SchemaProperty.NEVER);
+ if (bType.isItemNillable())
+ itemType = findBoxedType(itemType);
+ bType.setItemType(itemType.getName());
+ }
+ else if (scratchBindingType instanceof ListArrayType) {
+ ListArrayType bType = (ListArrayType) scratchBindingType;
+ JavaTypeName itemName = scratch.getJavaName().getArrayItemType(1);
+ assert (itemName != null);
+ SchemaType sType = getListItemType(scratch.getSchemaType());
+ assert (sType != null);
+ BindingType itemType = bindingTypeForSchemaType(sType);
+ if (itemType == null)
+ throw new IllegalStateException("Type " + sType.getName() +
+ " not found in the type loader");
+ bType.setItemType(itemType.getName());
+ }
+ else
throw new IllegalStateException();
- WrappedArrayType bType = (WrappedArrayType) scratch.getBindingType();
- JavaTypeName itemName = scratch.getJavaName().getArrayItemType(1);
- assert(itemName != null);
- SchemaType sType = getLiteralArrayItemType(scratch.getSchemaType());
- assert sType != null : "This was already checked and determined to be non-null";
- SchemaProperty prop = scratch.getSchemaType().getProperties()[0];
- bType.setItemName(prop.getName());
- BindingType itemType = bindingTypeForSchemaType(sType);
- if (itemType == null)
- throw new IllegalStateException("Type " + sType.getName() +
- " not found in type loader");
-
- bType.setItemNillable(prop.hasNillable() != SchemaProperty.NEVER);
- if (bType.isItemNillable())
- itemType = findBoxedType(itemType);
- bType.setItemType(itemType.getName());
}
/**
@@ -732,8 +806,13 @@
// case 1: it's in the current area
Scratch scratch = scratchForSchemaType(sType);
if (scratch != null) {
- resolveJavaStructure(scratch);
- return scratch.getQNameProperties();
+ // The type found may not be a structure
+ if (scratch.getCategory() == Scratch.STRUCT_TYPE) {
+ resolveJavaStructure(scratch);
+ return scratch.getQNameProperties();
+ }
+ else
+ return null;
}
// case 2: it's in the mLoader
@@ -774,6 +853,28 @@
return bType;
}
+ /**
+ * Returns a BindingType representing the default type for <xs:any> content
+ */
+ private BindingType getWildcardElementBindingType(boolean multiple) {
+ JavaTypeName javaName;
+ javaName = JavaTypeName.forString(WILDCARD_ELEMENT_MAPPING);
+ if (multiple)
+ javaName = JavaTypeName.forArray(javaName, 1);
+ XmlTypeName xmlName = XmlTypeName.forTypeNamed(new QName(xsns, "anyType"));
+ return new SimpleBindingType(BindingTypeName.forPair(javaName, xmlName));
+ }
+
+ /**
+ * Returns a BindingType representing the default type for <xs:anyAttribute>
+ */
+ private BindingType getWildcardAttributeBindingType() {
+ JavaTypeName javaName;
+ javaName = JavaTypeName.forString(WILDCARD_ATTRIBUTE_MAPPING);
+ XmlTypeName xmlName = XmlTypeName.forTypeNamed(new QName(xsns, "anyType"));
+ return new SimpleBindingType(BindingTypeName.forPair(javaName, xmlName));
+ }
+
private JavaTypeName getBoxedName(JavaTypeName jName)
{
// We could use a map here and initialize it on first use
@@ -904,6 +1005,41 @@
}
/**
+ * Searches the content of a complex type to see if more than one <xs:any>
+ * wildcard was defined
+ */
+ private int countWildcards(SchemaParticle p)
+ {
+ int totalWildcards = 0;
+ switch (p.getParticleType()) {
+ case SchemaParticle.ALL:
+ case SchemaParticle.SEQUENCE:
+ {
+ SchemaParticle[] children = p.getParticleChildren();
+ for (int i = 0; i < children.length; i++)
+ totalWildcards += countWildcards(children[i]);
+ }
+ break;
+ case SchemaParticle.CHOICE:
+ {
+ SchemaParticle[] children = p.getParticleChildren();
+ for (int i = 0; i < children.length; i++) {
+ int n = countWildcards(children[i]);
+ if (n > totalWildcards)
+ totalWildcards = n;
+ }
+ }
+ break;
+ case SchemaParticle.ELEMENT:
+ break;
+ case SchemaParticle.WILDCARD:
+ totalWildcards = p.getIntMaxOccurs();
+ break;
+ }
+ return totalWildcards;
+ }
+
+ /**
* Picks a unique fully-qualified Java class name for the given schema
* type. Uses and updates the "usedNames" set.
*/
@@ -981,6 +1117,25 @@
}
/**
+ * Searches on the mLoader for the given schema type and
+ * returns the java name of the type found or errors
+ * if it cannot find the type
+ */
+ private JavaTypeName getTypeNameFromLoader(SchemaType sType) {
+ BindingType bType = mLoader.getBindingType(mLoader.
+ lookupPojoFor(XmlTypeName.forSchemaType(sType)));
+ if (bType != null)
+ return bType.getName().getJavaName();
+ else if (sType.isBuiltinType())
+ logError("Bultin type " + sType.getName() + " is not supported",
+ null, sType);
+ else
+ throw new IllegalStateException(sType.getName().toString()+
+ " type is not on mLoader");
+ return null;
+ }
+
+ /**
* Looks on both the mLoader and in the current scratch area for
* the binding type corresponding to the given schema type. Must
* be called after all the binding types have been created.
@@ -1033,6 +1188,10 @@
return prop[0].getType();
}
+ private static SchemaType getListItemType(SchemaType sType) {
+ return sType.getListItemType();
+ }
+
/**
* True if the given schema type is interpreted as a .NET-style
* array.
@@ -1049,6 +1208,13 @@
}
/**
+ * True if the given schema type is a list type
+ */
+ private static boolean isList(SchemaType sType) {
+ return getListItemType(sType) != null;
+ }
+
+ /**
* Scratch area corresponding to a schema type, used for the binding
* computation.
*/
@@ -1074,11 +1240,12 @@
public static final int ATOMIC_TYPE = 1;
public static final int STRUCT_TYPE = 2;
public static final int ENUM_TYPE = 3;
- public static final int LITERALARRAY_TYPE = 4;
- public static final int SOAPARRAY_REF = 5;
- public static final int SOAPARRAY = 6;
- public static final int ELEMENT = 7;
- public static final int ATTRIBUTE = 8;
+ public static final int LIST_TYPE = 4;
+ public static final int LITERALARRAY_TYPE = 5;
+ public static final int SOAPARRAY_REF = 6;
+ public static final int SOAPARRAY = 7;
+ public static final int ELEMENT = 8;
+ public static final int ATTRIBUTE = 9;
public int getCategory() {
return category;
@@ -1138,7 +1305,7 @@
throw new IllegalStateException();
}
- public void addSimpleContentProperty(SimpleContentProperty prop) {
+ public void setSimpleContentProperty(SimpleContentProperty prop) {
if (bindingType instanceof SimpleContentBean)
((SimpleContentBean) bindingType).setSimpleContentProperty(prop);
else
@@ -1152,6 +1319,38 @@
return null;
}
+ public void setAnyAttributeProperty(GenericXmlProperty prop) {
+ if (bindingType instanceof ByNameBean)
+ ((ByNameBean) bindingType).setAnyAttributeProperty(prop);
+ else if (bindingType instanceof SimpleContentBean)
+ ((SimpleContentBean) bindingType).setAnyAttributeProperty(prop);
+ else
+ throw new IllegalStateException();
+ }
+
+ public GenericXmlProperty getAnyAttributeProperty() {
+ if (bindingType instanceof ByNameBean)
+ return ((ByNameBean) bindingType).getAnyAttributeProperty();
+ else if (bindingType instanceof SimpleContentBean)
+ return ((SimpleContentBean) bindingType).getAnyAttributeProperty();
+ else
+ throw new IllegalStateException();
+ }
+
+ public void setAnyElementProperty(GenericXmlProperty prop) {
+ if (bindingType instanceof ByNameBean)
+ ((ByNameBean) bindingType).setAnyElementProperty(prop);
+ else
+ throw new IllegalStateException();
+ }
+
+ public GenericXmlProperty getAnyElementProperty() {
+ if (bindingType instanceof ByNameBean)
+ return ((ByNameBean) bindingType).getAnyElementProperty();
+ else
+ throw new IllegalStateException();
+ }
+
public boolean isStructureResolved() {
return this.isStructureResolved;
}
@@ -1337,6 +1536,24 @@
scprop.getGetterName().getSimpleName(), scprop.getSetterName().getSimpleName());
}
+ // Write out the Generic Xml properties, if needed
+ GenericXmlProperty gxprop = scratch.getAnyElementProperty();
+ if (gxprop != null) {
+ String fieldName = pickUniqueFieldName(gxprop.getGetterName().getSimpleName(),
+ seenFieldNames);
+ JavaTypeName jType = gxprop.getTypeName().getJavaName();
+ addJavaBeanProperty(fieldName, jType.toString(),
+ gxprop.getGetterName().getSimpleName(), gxprop.getSetterName().getSimpleName());
+ }
+ gxprop = scratch.getAnyAttributeProperty();
+ if (gxprop != null) {
+ String fieldName = pickUniqueFieldName(gxprop.getGetterName().getSimpleName(),
+ seenFieldNames);
+ JavaTypeName jType = gxprop.getTypeName().getJavaName();
+ addJavaBeanProperty(fieldName, jType.toString(),
+ gxprop.getGetterName().getSimpleName(), gxprop.getSetterName().getSimpleName());
+ }
+
Collection props = scratch.getQNameProperties();
Map fieldNames = new HashMap();
@@ -1395,7 +1612,7 @@
JavaTypeName baseType = enumType.getBaseTypeName().getJavaName();
EnumerationPrintHelper enumHelper =
new EnumerationPrintHelper(baseType, mJoust.getExpressionFactory(),
- scratch.getSchemaType().getPrimitiveType().getBuiltinTypeCode());
+ scratch.getSchemaType());
// figure out what import statements we need
boolean useArrays = enumHelper.isArray() || enumHelper.isBinary();
@@ -1505,10 +1722,18 @@
new String[] {baseType.toString()},
new String[] {"value"},
null);
+ String valueVarName = "value";
+ if (useArrays) {
+ mJoust.writeStatement(shortClassName + " new" + valueVarName + " = new " +
+ shortClassName + "(" + valueVarName + ")");
+ valueVarName = "new" + valueVarName;
+ }
mJoust.writeStatement("if (" + instanceMapName + ".containsKey(" +
- (useArrays ? "new " + shortClassName + "(value)" : enumHelper.getObjectVersion("value")) +
+ (useArrays ? valueVarName : enumHelper.getObjectVersion("value")) +
")) return (" + shortClassName + ") " +
- instanceMapName + ".get(" + enumHelper.getObjectVersion("value") + ")");
+ instanceMapName + ".get(" +
+ (useArrays ? valueVarName : enumHelper.getObjectVersion("value"))
+ + ")");
mJoust.writeStatement("else throw new IllegalArgumentException()");
mJoust.endMethodOrConstructor();
@@ -1529,7 +1754,8 @@
baseType.getArrayItemType(1).toString() + "[" + STRING_PARTS + ".length" + "]");
mJoust.writeStatement("for (int i = 0; i < " + BASETYPE_ARRAY + ".length; i++) " +
BASETYPE_ARRAY + "[i] = " +
- enumHelper.getFromStringExpr(params[0]).getMemento().toString());
+ enumHelper.getFromStringExpr(mJoust.getExpressionFactory().createVerbatim(
+ STRING_PARTS + "[i]")).getMemento().toString());
mJoust.writeReturnStatement(mJoust.getExpressionFactory().createVerbatim(
enumType.getFromValueMethod().getSimpleName() + "(" + BASETYPE_ARRAY + ")"));
}
@@ -1553,7 +1779,7 @@
mJoust.writeStatement("for (int i = 0; i < " + instanceVarName + ".length; i++) " +
STRING_LIST + ".append(" + enumHelper.getToXmlString(instanceVar, "i") +
").append(' ')");
- mJoust.writeReturnStatement(mJoust.getExpressionFactory().createVerbatim(STRING_LIST));
+ mJoust.writeReturnStatement(mJoust.getExpressionFactory().createVerbatim(STRING_LIST + ".toString()"));
}
else {
mJoust.writeReturnStatement(enumHelper.getToXmlExpr(instanceVar));
@@ -1572,7 +1798,7 @@
STRING_LIST + ".append(String.valueOf(" +
instanceVarName + "[i]" +
")).append(' ')");
- mJoust.writeReturnStatement(mJoust.getExpressionFactory().createVerbatim(STRING_LIST));
+ mJoust.writeReturnStatement(mJoust.getExpressionFactory().createVerbatim(STRING_LIST + ".toString()"));
}
else {
mJoust.writeReturnStatement(mJoust.getExpressionFactory().createVerbatim(
@@ -1613,7 +1839,7 @@
if (enumHelper.isArray()) {
mJoust.writeStatement("int val = 0;");
mJoust.writeStatement("for (int i = 0; i < " + instanceVarName + ".length; i++) " +
- "{ val *= 19; val =+ " +
+ "{ val *= 19; val += " +
enumHelper.getHashCode(instanceVarName).getMemento().toString() +
"; }");
mJoust.writeStatement("return val");
1.5 +3 -3 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/CompilingJavaOutputStream.java
Index: CompilingJavaOutputStream.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/CompilingJavaOutputStream.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CompilingJavaOutputStream.java 12 Feb 2004 20:06:07 -0000 1.4
+++ CompilingJavaOutputStream.java 25 Mar 2004 22:00:29 -0000 1.5
@@ -161,9 +161,9 @@
mLogger.logVerbose(PREFIX+i.next().toString());
}
boolean verbose = mLogger.isVerbose();
- boolean result = CodeGenUtil.externalCompile
- (mSourceFiles,mCompileDir,mJavacClasspath,
- verbose,mJavacPath,null,null,!verbose,verbose);
+ boolean result = mSourceFiles.size() > 0 ? CodeGenUtil.
+ externalCompile(mSourceFiles,mCompileDir,mJavacClasspath,
+ verbose,mJavacPath,null,null,!verbose,verbose) : true;
mLogger.logVerbose(PREFIX+" compilation result: "+result);
if (!result) {
throw new IOException("Compilation of sources failed, " +
1.19 +25 -3 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- binding-config.xsd 25 Mar 2004 03:19:28 -0000 1.18
+++ binding-config.xsd 25 Mar 2004 22:00:29 -0000 1.19
@@ -95,9 +95,13 @@
<xs:complexType name="by-name-bean">
<xs:complexContent>
<xs:extension base="tns:binding-type">
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="qname-property" type="tns:qname-property"/>
- </xs:choice>
+ <xs:sequence>
+ <xs:element name="any-property" type="tns:generic-xml-property" minOccurs="0"/>
+ <xs:element name="anyAttribute-property" type="tns:generic-xml-property" minOccurs="0"/>
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element name="qname-property" type="tns:qname-property"/>
+ </xs:choice>
+ </xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
@@ -106,6 +110,7 @@
<xs:complexContent>
<xs:extension base="tns:binding-type">
<xs:sequence>
+ <xs:element name="anyAttribute-property" type="tns:generic-xml-property" minOccurs="0"/>
<xs:element name="simple-content-property" type="tns:simple-content-property"/>
<xs:element name="attribute-property" type="tns:qname-property"
minOccurs="0" maxOccurs="unbounded"/>
@@ -126,6 +131,16 @@
</xs:complexContent>
</xs:complexType>
+ <xs:complexType name="list-array">
+ <xs:complexContent>
+ <xs:extension base="tns:binding-type">
+ <xs:sequence>
+ <xs:element name="item-type" type="tns:mapping"/>
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
<xs:complexType name="jaxb-bean">
<xs:complexContent>
<xs:extension base="tns:binding-type">
@@ -201,6 +216,13 @@
<xs:element name="optional" type="xs:boolean" default="false" minOccurs="0"/>
<xs:element name="default" type="xs:string" minOccurs="0"/>
</xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="generic-xml-property">
+ <xs:complexContent>
+ <xs:extension base="tns:binding-property">
</xs:extension>
</xs:complexContent>
</xs:complexType>
1.21 +6 -0 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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- MarshalResult.java 13 Mar 2004 03:46:57 -0000 1.20
+++ MarshalResult.java 25 Mar 2004 22:00:29 -0000 1.21
@@ -24,6 +24,7 @@
import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
+import org.apache.xmlbeans.impl.binding.bts.ListArrayType;
import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
import org.apache.xmlbeans.impl.binding.bts.SimpleContentBean;
import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
@@ -712,6 +713,11 @@
xmlTypeVisitor = new WrappedArrayTypeVisitor(runtimeBindingProperty,
parentObject,
marshalResult);
+ }
+
+ public void visit(ListArrayType listArrayType)
+ {
+ // todo: implement
}
}
1.23 +7 -0 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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- RuntimeBindingTypeTable.java 25 Mar 2004 03:19:28 -0000 1.22
+++ RuntimeBindingTypeTable.java 25 Mar 2004 22:00:29 -0000 1.23
@@ -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.JavaTypeName;
+import org.apache.xmlbeans.impl.binding.bts.ListArrayType;
import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
import org.apache.xmlbeans.impl.binding.bts.SimpleContentBean;
import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
@@ -506,6 +507,12 @@
runtimeBindingTypeTable,
loader);
typeUnmarshaller = new WrappedArrayUnmarshaller(rtt);
+ }
+
+ public void visit(ListArrayType listArrayType)
+ throws XmlException
+ {
+ // todo: implement
}
public TypeUnmarshaller getUnmarshaller()
1.14 +6 -0 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- RuntimeTypeFactory.java 13 Mar 2004 03:46:57 -0000 1.13
+++ RuntimeTypeFactory.java 25 Mar 2004 22:00:29 -0000 1.14
@@ -21,6 +21,7 @@
import org.apache.xmlbeans.impl.binding.bts.BindingTypeVisitor;
import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
+import org.apache.xmlbeans.impl.binding.bts.ListArrayType;
import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
import org.apache.xmlbeans.impl.binding.bts.SimpleContentBean;
import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
@@ -210,6 +211,11 @@
runtimeBindingType = new WrappedArrayRuntimeBindingType(wrappedArrayType);
}
+ public void visit(ListArrayType listArrayType)
+ throws XmlException
+ {
+ // todo: Implement
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org