You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by da...@apache.org on 2003/10/10 22:09:28 UTC
cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts BaseBindingLoader.java BindingFile.java BindingLoader.java BindingProperty.java BindingType.java BuiltinBindingLoader.java BuiltinBindingType.java ByNameBean.java JavaName.java JaxbBean.java KindRegistry.java ParticleProperty.java PathBindingLoader.java QNameProperty.java SimpleBindingType.java XmlName.java
davidbau 2003/10/10 13:09:28
Added: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
BaseBindingLoader.java BindingFile.java
BindingLoader.java BindingProperty.java
BindingType.java BuiltinBindingLoader.java
BuiltinBindingType.java ByNameBean.java
JavaName.java JaxbBean.java KindRegistry.java
ParticleProperty.java PathBindingLoader.java
QNameProperty.java SimpleBindingType.java
XmlName.java
Removed: v2/src/binding/org/apache/xmlbeans/impl/binding
BindingFile.java BindingLoader.java
BindingProperty.java BindingType.java
BuiltinBindingLoader.java BuiltinBindingType.java
ByNameBean.java JavaName.java JaxbBean.java
KindRegistry.java ParticleProperty.java
PathBindingLoader.java QNameProperty.java
SimpleBindingType.java XmlName.java
Log:
Moved binding type API into "bts" package and incorporating
Patrick's and Scott's feedback into the API.
I see more feedback is coming, so more changes are coming.
Code review: Scott
DRT: passed
Revision Changes Path
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BaseBindingLoader.java
Index: BaseBindingLoader.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) 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.binding.bts;
import java.util.Map;
import java.util.LinkedHashMap;
/**
* Base class
*/
public abstract class BaseBindingLoader implements BindingLoader
{
protected Map bindingTypes = new LinkedHashMap(); // name-pair -> BindingType
protected Map xmlFromJava = new LinkedHashMap(); // javaName -> pair
protected Map javaFromXmlPojo = new LinkedHashMap(); // xmlName -> pair (pojo)
protected Map javaFromXmlObj = new LinkedHashMap(); // xmlName -> pair (xmlobj)
public BindingType getBindingType(JavaName jName, XmlName xName)
{
return (BindingType)bindingTypes.get(pair(jName, xName));
}
public BindingType getBindingTypeForXmlPojo(XmlName xName)
{
NamePair pair = (NamePair)javaFromXmlPojo.get(xName);
if (pair == null)
return null;
return (BindingType)bindingTypes.get(pair);
}
public BindingType getBindingTypeForXmlObj(XmlName xName)
{
NamePair pair = (NamePair)javaFromXmlObj.get(xName);
if (pair == null)
return null;
return (BindingType)bindingTypes.get(pair);
}
public BindingType getBindingTypeForJava(JavaName jName)
{
NamePair pair = (NamePair)xmlFromJava.get(jName);
if (pair == null)
return null;
return (BindingType)bindingTypes.get(pair);
}
protected static NamePair pair(JavaName jName, XmlName xName)
{
return new NamePair(jName, xName);
}
protected static class NamePair
{
private final JavaName jName;
private final XmlName xName;
NamePair(JavaName jName, XmlName xName)
{
this.jName = jName;
this.xName = xName;
}
public JavaName getJavaName()
{
return jName;
}
public XmlName getXmlName()
{
return xName;
}
public boolean equals(Object o)
{
if (this == o) return true;
if (!(o instanceof BindingFile.NamePair)) return false;
final BindingFile.NamePair namePair = (BindingFile.NamePair) o;
if (!jName.equals(namePair.jName)) return false;
if (!xName.equals(namePair.xName)) return false;
return true;
}
public int hashCode()
{
int result;
result = jName.hashCode();
result = 29 * result + xName.hashCode();
return result;
}
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingFile.java
Index: BindingFile.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) 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.binding.bts;
import org.apache.xmlbeans.XmlOptions;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.io.IOException;
/**
* Represents a BindingLoader whose contents are loaded from a
* single binding-config file. (See binding-config.xsd)
*/
public class BindingFile extends BaseBindingLoader
{
/**
* This constructor is used when making a new one out of the blue.
*/
public BindingFile()
{
// nothing to do - all maps are empty
}
/**
* Loader
*/
public static BindingFile forDoc(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument doc)
{
return new BindingFile(doc);
}
/**
* This constructor loads an instance from an XML file
*/
protected BindingFile(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument doc)
{
List errors = new ArrayList();
if (!doc.validate(new XmlOptions().setErrorListener(errors)))
throw new IllegalArgumentException(errors.size() > 0 ? errors.get(0).toString() : "Invalid binding-config document");
// todo: in the loops below, validate that entries are unique, or modify schema to do so.
org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType[] btNodes =
doc.getBindingConfig().getBindings().getBindingTypeArray();
for (int i = 0; i < btNodes.length; i++)
{
BindingType next = BindingType.loadFromBindingTypeNode(this, btNodes[i]);
addBindingType(next, false, false);
}
org.apache.xmlbeans.x2003.x09.bindingConfig.Mapping[] mNodes =
doc.getBindingConfig().getJavaToXml().getMappingArray();
for (int i = 0; i < mNodes.length; i++)
{
JavaName jName = JavaName.forString(mNodes[i].getJavatype());
XmlName xName = XmlName.forString(mNodes[i].getXmlcomponent());
xmlFromJava.put(jName, xName);
}
mNodes = doc.getBindingConfig().getXmlToPojo().getMappingArray();
for (int i = 0; i < mNodes.length; i++)
{
JavaName jName = JavaName.forString(mNodes[i].getJavatype());
XmlName xName = XmlName.forString(mNodes[i].getXmlcomponent());
javaFromXmlPojo.put(xName, jName);
}
mNodes = doc.getBindingConfig().getXmlToXmlobj().getMappingArray();
for (int i = 0; i < mNodes.length; i++)
{
JavaName jName = JavaName.forString(mNodes[i].getJavatype());
XmlName xName = XmlName.forString(mNodes[i].getXmlcomponent());
javaFromXmlObj.put(xName, jName);
}
}
/**
* Writes out to XML
*/
public org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument write() throws IOException
{
org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument doc =
org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument.Factory.newInstance();
write(doc);
return doc;
}
/**
* This function copies an instance into an empty doc.
*/
private void write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument doc)
{
if (doc.getBindingConfig() != null)
throw new IllegalArgumentException("Can only write into empty doc");
org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument.BindingConfig bcNode = doc.addNewBindingConfig();
// make tables
org.apache.xmlbeans.x2003.x09.bindingConfig.BindingTable btabNode = bcNode.addNewBindings();
org.apache.xmlbeans.x2003.x09.bindingConfig.MappingTable jtabNode = bcNode.addNewJavaToXml();
org.apache.xmlbeans.x2003.x09.bindingConfig.MappingTable pojotabNode = bcNode.addNewXmlToPojo();
org.apache.xmlbeans.x2003.x09.bindingConfig.MappingTable xotabNode = bcNode.addNewXmlToXmlobj();
// fill em in: binding types (delegate to BindingType.write)
for (Iterator i = bindingTypes.values().iterator(); i.hasNext(); )
{
BindingType bType = (BindingType)i.next();
org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType btNode = btabNode.addNewBindingType();
bType.write(btNode);
}
// from-java mappings
for (Iterator i = xmlFromJava.entrySet().iterator(); i.hasNext(); )
{
Map.Entry entry = (Map.Entry)i.next();
JavaName jName = (JavaName)entry.getKey();
XmlName xName = (XmlName)entry.getValue();
org.apache.xmlbeans.x2003.x09.bindingConfig.Mapping mNode = jtabNode.addNewMapping();
mNode.setJavatype(jName.toString());
mNode.setXmlcomponent(xName.toString());
}
// to-pojo
for (Iterator i = javaFromXmlPojo.entrySet().iterator(); i.hasNext(); )
{
Map.Entry entry = (Map.Entry)i.next();
JavaName jName = (JavaName)entry.getValue();
XmlName xName = (XmlName)entry.getKey();
org.apache.xmlbeans.x2003.x09.bindingConfig.Mapping mNode = pojotabNode.addNewMapping();
mNode.setJavatype(jName.toString());
mNode.setXmlcomponent(xName.toString());
}
// to-xmlobj
for (Iterator i = javaFromXmlObj.entrySet().iterator(); i.hasNext(); )
{
Map.Entry entry = (Map.Entry)i.next();
JavaName jName = (JavaName)entry.getValue();
XmlName xName = (XmlName)entry.getKey();
org.apache.xmlbeans.x2003.x09.bindingConfig.Mapping mNode = xotabNode.addNewMapping();
mNode.setJavatype(jName.toString());
mNode.setXmlcomponent(xName.toString());
}
}
public void addBindingType(BindingType bType, boolean fromJavaDefault, boolean fromXmlDefault)
{
bindingTypes.put(BaseBindingLoader.pair(bType.getJavaName(), bType.getXmlName()), bType);
if (fromJavaDefault)
{
if (bType.isXmlObject())
javaFromXmlObj.put(bType.getXmlName(), bType.getJavaName());
else
javaFromXmlPojo.put(bType.getXmlName(), bType.getJavaName());
}
if (fromXmlDefault)
{
xmlFromJava.put(bType.getJavaName(), bType.getXmlName());
}
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingLoader.java
Index: BindingLoader.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) 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.binding.bts;
/**
* Represents a resource capable of providing BindingTypes, based on
* XML and Java component names. Implementations of this interface
* may load from files, classpaths, etc.
*/
public interface BindingLoader
{
BindingType getBindingType(JavaName jName, XmlName xName);
BindingType getBindingTypeForXmlPojo(XmlName xName);
BindingType getBindingTypeForXmlObj(XmlName xName);
BindingType getBindingTypeForJava(JavaName jName);
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingProperty.java
Index: BindingProperty.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) 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.binding.bts;
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
/**
* Represents a property. Every property corresponds to a
* Java getter/setter or a field. On the XML side, there
* are different forms of properties, some which bind based
* on sequencing, and others which bind based on name.
*/
public abstract class BindingProperty
{
private JavaName tJava;
protected XmlName tXml;
private String getter;
private String setter;
private String field;
private JavaName collection;
/**
* This kind of constructor is used when making a new one out of the blue.
*
* Subclasses should call super(..) when defining constructors that init new BindingTypes.
*/
protected BindingProperty()
{
}
/**
* This constructor loads an instance from an XML file
*
* Subclasses should have ctors of the same signature and call super(..) first.
*/
protected BindingProperty(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty node)
{
this.tJava = JavaName.forString(node.getJavatype());
this.tXml = XmlName.forString(node.getXmlcomponent());
this.getter = node.getGetter();
this.setter = node.getSetter();
this.field = node.getField();
String collection = node.getCollection();
if (collection != null)
this.collection = JavaName.forString(collection);
}
/**
* This function copies an instance back out to the relevant part of the XML file.
*
* Subclasses should override and call super.write first.
*/
protected org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty node)
{
node = (org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty)node.changeType(kinds.typeForClass(this.getClass()));
node.setJavatype(tJava.toString());
node.setXmlcomponent(tXml.toString());
if (getFieldName() != null)
node.setField(getFieldName());
if (getGetterName() != null)
node.setGetter(getGetterName());
if (getSetterName() != null)
node.setSetter(getSetterName());
if (getCollectionClass() != null)
node.setCollection(getCollectionClass().toString());
return node;
}
public boolean isField()
{
return field != null;
}
public BindingType getBindingType(BindingLoader loader)
{
return loader.getBindingType(tJava, tXml);
}
public void setBindingType(BindingType bType)
{
this.tJava = bType.getJavaName();
this.tXml = bType.getXmlName();
}
public String getGetterName()
{
return isField() ? null : getter;
}
public void setGetterName(String getter)
{
this.getter = getter;
}
public boolean hasSetter()
{
return !isField() && setter != null;
}
public String getSetterName()
{
return isField() ? null : setter;
}
public void setSetterName(String setter)
{
this.setter = setter;
}
public String getFieldName()
{
return field;
}
public void setFieldName(String field)
{
this.field = field;
}
public JavaName getCollectionClass()
{
return collection;
}
public void setCollectionClass(JavaName jName)
{
collection = jName;
}
/* REGISTRY OF SUBCLASSES */
private static final Class[] ctorArgs = new Class[] {org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty.class};
public static BindingProperty forNode(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty node)
{
try
{
Class clazz = kinds.classForType(node.schemaType());
return (BindingProperty)clazz.getConstructor(ctorArgs).newInstance(new Object[] {node});
}
catch (Exception e)
{
throw (IllegalStateException)new IllegalStateException("Cannot load class for " + node.schemaType() + ": should be registered.").initCause(e);
}
}
/**
* Should only be called by BindingFile, when loading up bindingtypes
*/
static KindRegistry kinds = new KindRegistry();
public static void registerClassAndType(Class clazz, SchemaType type)
{
if (!BindingProperty.class.isAssignableFrom(clazz))
throw new IllegalArgumentException("Classes must inherit from BindingProperty");
if (!org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty.type.isAssignableFrom(type))
throw new IllegalArgumentException("Schema types must inherit from binding-property");
kinds.registerClassAndType(clazz, type);
}
static
{
registerClassAndType(QNameProperty.class, org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty.type);
registerClassAndType(ParticleProperty.class, org.apache.xmlbeans.x2003.x09.bindingConfig.ParticleProperty.type);
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingType.java
Index: BindingType.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) 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.binding.bts;
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
/**
* Represents a Java+XML component and a rule for getting between
* them.
*/
public abstract class BindingType
{
private JavaName jName;
private XmlName xName;
private boolean isXmlObj;
/**
* This kind of constructor is used when making a new one out of the blue.
*
* Subclasses should call super(..) when defining constructors that init new BindingTypes.
*/
protected BindingType(JavaName jName, XmlName xName, boolean isXmlObj)
{
this.jName = jName;
this.xName = xName;
this.isXmlObj = isXmlObj;
}
/**
* This constructor loads an instance from an XML file
*
* Subclasses should have ctors of the same signature and call super(..) first.
*/
protected BindingType(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
this.jName = JavaName.forString(node.getJavatype());
this.xName = XmlName.forString(node.getXmlcomponent());
this.isXmlObj = node.getXmlobj();
}
/**
* This function copies an instance back out to the relevant part of the XML file.
*
* Subclasses should override and call super.write first.
*/
protected org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
node = (org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType)node.changeType(kinds.typeForClass(this.getClass()));
node.setJavatype(jName.toString());
node.setXmlcomponent(xName.toString());
node.setXmlobj(isXmlObj);
return node;
}
public final JavaName getJavaName()
{
return jName;
}
public final XmlName getXmlName()
{
return xName;
}
public final boolean isXmlObject()
{
return isXmlObj;
}
/* REGISTRY OF SUBCLASSES */
private static final Class[] ctorArgs = new Class[] {org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType.class};
public static BindingType loadFromBindingTypeNode(BindingLoader bLoader, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
try
{
Class clazz = kinds.classForType(node.schemaType());
return (BindingType)clazz.getConstructor(ctorArgs).newInstance(new Object[] {node});
}
catch (Exception e)
{
throw (IllegalStateException)new IllegalStateException("Cannot load class for " + node.schemaType() + ": should be registered.").initCause(e);
}
}
/**
* Should only be called by BindingFile, when loading up bindingtypes
*/
static KindRegistry kinds = new KindRegistry();
public static void registerClassAndType(Class clazz, SchemaType type)
{
if (!BindingType.class.isAssignableFrom(clazz))
throw new IllegalArgumentException("Classes must inherit from BindingType");
if (!org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType.type.isAssignableFrom(type))
throw new IllegalArgumentException("Schema types must inherit from binding-type");
kinds.registerClassAndType(clazz, type);
}
static
{
registerClassAndType(JaxbBean.class, org.apache.xmlbeans.x2003.x09.bindingConfig.JaxbBean.type);
registerClassAndType(ByNameBean.class, org.apache.xmlbeans.x2003.x09.bindingConfig.ByNameBean.type);
registerClassAndType(SimpleBindingType.class, org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType.type);
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BuiltinBindingLoader.java
Index: BuiltinBindingLoader.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) 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.binding.bts;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
import javax.xml.namespace.QName;
import java.util.Map;
import java.util.LinkedHashMap;
/**
*
*/
public class BuiltinBindingLoader extends BaseBindingLoader
{
private Map bindingTypes = new LinkedHashMap(); // name-pair -> BindingType
private Map xmlFromJava = new LinkedHashMap(); // javaName -> xmlName
private Map javaFromXmlPojo = new LinkedHashMap(); // xmlName -> javaName (pojo)
private Map javaFromXmlObj = new LinkedHashMap(); // xmlName -> javaName (xmlobj)
private static final String xsns = "http://www.w3.org/2001/XMLSchema";
private void addMapping(String xmlType, String javaName, boolean pojo, boolean defaultForJava, boolean defaultForXml)
{
XmlName xn = XmlName.forTypeNamed(new QName(xsns, xmlType));
JavaName jn = JavaName.forString(javaName);
BindingType bt = new BuiltinBindingType(jn, xn, !pojo);
NamePair pair = pair(jn, xn);
bindingTypes.put(pair, bt);
if (defaultForJava)
xmlFromJava.put(jn, pair);
if (defaultForXml)
{
if (pojo)
javaFromXmlPojo.put(xn, pair);
else
javaFromXmlObj.put(xn, pair);
}
}
private void addPojoTwoWay(String xmlType, String javaName)
{
addMapping(xmlType, javaName, true, true, true);
}
private void addPojoXml(String xmlType, String javaName)
{
addMapping(xmlType, javaName, true, false, true);
}
private void addPojoJava(String xmlType, String javaName)
{
addMapping(xmlType, javaName, true, true, false);
}
private void addPojo(String xmlType, String javaName)
{
addMapping(xmlType, javaName, true, true, false);
}
public BuiltinBindingLoader()
{
// todo: should each builtin binding type know about it's print/parse methods?
addPojoXml("anySimpleType", "java.lang.String");
addPojoTwoWay("string", "java.lang.String");
addPojoXml("normalizedString", "java.lang.String");
addPojoXml("token", "java.lang.String");
addPojoXml("language", "java.lang.String");
addPojoXml("Name", "java.lang.String");
addPojoXml("NCName", "java.lang.String");
addPojoXml("NMTOKEN", "java.lang.String");
addPojoXml("ID", "java.lang.String");
addPojoXml("IDREF", "java.lang.String");
addPojoXml("ENTITY", "java.lang.String");
addPojoTwoWay("duration", "org.apache.xmlbeans.GDuration");
addPojoTwoWay("dateTime", "java.util.Calendar");
addPojoJava("dateTime", "java.util.Date");
addPojoXml("time", "java.util.Calendar");
addPojoXml("date", "java.util.Calendar");
addPojo("date", "java.util.Date");
addPojoXml("gYearMonth", "java.util.Calendar");
addPojoXml("gYear", "java.util.Calendar");
addPojo("gYear", "int");
addPojoXml("gMonthDay", "java.util.Calendar");
addPojoXml("gMonth", "java.util.Calendar");
addPojo("gMonth", "int");
addPojoXml("gDay", "java.util.Calendar");
addPojo("gDay", "int");
addPojoTwoWay("boolean", "boolean");
addPojoTwoWay("base64Binary", "byte[]");
addPojoJava("base64Binary", "java.io.InputStream");
addPojoXml("hexBinary", "byte[]");
addPojo("hexBinary", "java.io.InputStream");
addPojoTwoWay("float", "float");
addPojoTwoWay("double", "double");
addPojoTwoWay("decimal", "java.math.BigDecimal");
addPojoTwoWay("integer", "java.math.BigInteger");
addPojoTwoWay("long", "long");
addPojoTwoWay("int", "int");
addPojoTwoWay("short", "short");
addPojoTwoWay("byte", "byte");
addPojoXml("nonPositiveInteger", "java.math.BigInteger");
addPojoXml("negativeInteger", "java.math.BigInteger");
addPojoXml("nonNegativeInteger", "java.math.BigInteger");
addPojoXml("positiveInteger", "java.math.BigInteger");
addPojoXml("unsignedLong", "java.math.BigInteger");
addPojoXml("unsignedInt", "long");
addPojoXml("unsignedShort", "int");
addPojoXml("unsignedByte", "short");
addPojoXml("anyURI", "java.lang.String");
addPojoJava("anyURI", "java.net.URI");
addPojoTwoWay("QName", "javax.xml.namespace.QName");
addPojoXml("NOTATION", "java.lang.String");
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BuiltinBindingType.java
Index: BuiltinBindingType.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) 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.binding.bts;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
/**
* A "builtin" binding type is one that doesn't explicitly specify
* how the conversion works because it is assumed that the runtime
* has builtin knowledge of how to make it happen. Instances should
* only be created by BuiltinBindingLoader.
*/
public class BuiltinBindingType extends BindingType
{
// note: only this one constructor; builtin binding types can't be loaded
public BuiltinBindingType(JavaName jName, XmlName xName, boolean isXmlObj)
{
super(jName, xName, isXmlObj);
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/ByNameBean.java
Index: ByNameBean.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) 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.binding.bts;
import org.apache.xmlbeans.impl.binding.bts.BindingProperty;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
import javax.xml.namespace.QName;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Collections;
import java.util.Collection;
/**
* A by-name binding is one that connects XML and Java based on the
* QNames of XML elements and attributes, rather than by sequencing
* or particle trees.
*/
public class ByNameBean extends BindingType
{
List props = new ArrayList(); // of QNameProperties
Map eltProps = new HashMap(); // QName -> prop (elts)
Map attProps = new HashMap(); // QName -> prop (attrs)
public ByNameBean(JavaName jName, XmlName xName, boolean isXmlObj)
{
super(jName, xName, isXmlObj);
}
public ByNameBean(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
super(node);
org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty[] propArray =
((org.apache.xmlbeans.x2003.x09.bindingConfig.ByNameBean)node).getQnamePropertyArray();
for (int i = 0; i < propArray.length; i++)
{
addProperty((QNameProperty)BindingProperty.forNode(propArray[i]));
}
}
/**
* This function copies an instance back out to the relevant part of the XML file.
*
* Subclasses should override and call super.write first.
*/
protected org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
org.apache.xmlbeans.x2003.x09.bindingConfig.ByNameBean bnNode = (org.apache.xmlbeans.x2003.x09.bindingConfig.ByNameBean)super.write(node);
for (Iterator i = props.iterator(); i.hasNext(); )
{
QNameProperty qProp = (QNameProperty)i.next();
org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty qpNode = bnNode.addNewQnameProperty();
qProp.write(qpNode);
}
return bnNode;
}
/**
* Returns an unmodifiable collection of QNameProperty objects.
*/
public Collection getProperties()
{
return Collections.unmodifiableCollection(props);
}
/**
* Looks up a property by attribute name, null if no match.
*/
public QNameProperty getPropertyForAttribute(QName name)
{
return (QNameProperty)attProps.get(name);
}
/**
* Looks up a property by element name, null if no match.
*/
public QNameProperty getPropertyForElement(QName name)
{
return (QNameProperty)eltProps.get(name);
}
/**
* Adds a new property
*/
public void addProperty(QNameProperty newProp)
{
if (newProp.isAttribute() ? attProps.containsKey(newProp.getQName()) : eltProps.containsKey(newProp.getQName()))
throw new IllegalArgumentException();
props.add(newProp);
if (newProp.isAttribute())
attProps.put(newProp.getQName(), newProp);
else
eltProps.put(newProp.getQName(), newProp);
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/JavaName.java
Index: JavaName.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) 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.binding.bts;
/**
* Represents a Java class name, and provides some utility methods
* for parsing out bits of the name.
*
* Examples:
*
* "int[]"
* "java.lang.String"
* "com.myco.MyClass$MyInnerClass$InnerInnerClass[][]"
*/
public final class JavaName
{
private final String className;
private final String arrayString;
/**
* Returns a JavaName object for a fully-qualified class name.
* The class-name should be dot-separated for packages and
* dollar-separated for inner classes.
*
* The names "int", "byte" etc are considered special.
* Arrays are dealt with as [][][] at the end.
*
* This is a static function to permit pooling in the future.
*/
public static JavaName forString(String className)
{
return new JavaName(className);
}
/**
* Do not use this constructor; use forClassName instead.
*/
private JavaName(String className)
{
if (className == null)
throw new IllegalArgumentException();
int arrayDepth = 0;
for (int i = className.length() - 2; i >= 0; i -= 2)
{
if (className.charAt(i) != '[' || className.charAt(i + 1) != ']')
break;
arrayDepth += 1;
}
this.className = className.substring(0, className.length() - 2 * arrayDepth);
this.arrayString = className.substring(className.length() - 2 * arrayDepth);
}
/**
* Returns the fully-qualified class name.
*/
public String toString()
{
return className + arrayString;
}
/**
* Returns the array depth, 0 for non-arrays, 1 for [], 2 for [][], etc.
*/
public int getArrayDepth()
{
return arrayString.length() / 2;
}
/**
* Returns the array item type (peeling off "n" array indexes)
*/
public JavaName getArrayItemType(int depth)
{
if (arrayString.length() < depth * 2)
return null;
return forString(className + arrayString.substring(0, arrayString.length() - 2 * depth));
}
/**
* Returns the dot-separated package name.
*/
public String getPackage()
{
int index = className.lastIndexOf('.');
if (index <= 0)
return "";
return className.substring(0, index);
}
/**
* True if this is an inner class name.
*/
public boolean isInnerClass()
{
return (className.lastIndexOf('$') >= 0);
}
/**
* Returns the JavaName of the containing class, or null if this
* is not an inner class name.
*/
public JavaName getContainingClass()
{
int index = className.lastIndexOf('$');
if (index < 0)
return null;
return JavaName.forString(className.substring(0, index));
}
/**
* Returns the short class name (i.e., no dots or dollars).
*/
public String getShortClassName()
{
int index = className.lastIndexOf('$');
int index2 = className.lastIndexOf('.');
if (index2 > index)
index = index2;
if (index < 0)
return className;
return className.substring(index + 1);
}
public boolean equals(Object o)
{
if (this == o) return true;
if (!(o instanceof JavaName)) return false;
final JavaName javaName = (JavaName) o;
if (!className.equals(javaName.className)) return false;
if (!arrayString.equals(javaName.arrayString)) return false;
return true;
}
public int hashCode()
{
return className.hashCode() + arrayString.length();
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/JaxbBean.java
Index: JaxbBean.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) 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.binding.bts;
import org.apache.xmlbeans.impl.binding.bts.BindingProperty;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
import org.apache.xmlbeans.impl.binding.bts.JavaName;
import javax.xml.namespace.QName;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Iterator;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
/**
* Represents a binding that can line up properties based on either
* name (like ByNameBean) or position (i.e., Schema Particle), as
* required by JAXB.
*/
public class JaxbBean extends BindingType
{
Map partProps = new LinkedHashMap(); // XmlName -> prop (particles)
Map eltProps = new LinkedHashMap(); // QName -> prop (elts)
Map attProps = new LinkedHashMap(); // QName -> prop (attrs)
public JaxbBean(JavaName jName, XmlName xName)
{
super(jName, xName, false);
}
public JaxbBean(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
super(node);
org.apache.xmlbeans.x2003.x09.bindingConfig.JaxbBean jbNode = (org.apache.xmlbeans.x2003.x09.bindingConfig.JaxbBean)node;
org.apache.xmlbeans.x2003.x09.bindingConfig.ParticleProperty[] ppropArray = jbNode.getParticlePropertyArray();
for (int i = 0; i < ppropArray.length; i++)
{
addProperty(BindingProperty.forNode(ppropArray[i]));
}
org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty[] qpropArray = jbNode.getQnamePropertyArray();
for (int i = 0; i < qpropArray.length; i++)
{
addProperty(BindingProperty.forNode(qpropArray[i]));
}
}
/**
* This function copies an instance back out to the relevant part of the XML file.
*
* Subclasses should override and call super.write first.
*/
protected org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
org.apache.xmlbeans.x2003.x09.bindingConfig.JaxbBean jbNode = (org.apache.xmlbeans.x2003.x09.bindingConfig.JaxbBean)super.write(node);
for (Iterator i = getProperties().iterator(); i.hasNext(); )
{
BindingProperty bProp = (BindingProperty)i.next();
if (bProp instanceof ParticleProperty)
{
org.apache.xmlbeans.x2003.x09.bindingConfig.ParticleProperty ppNode = jbNode.addNewParticleProperty();
bProp.write(ppNode);
}
else
{
org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty qpNode = jbNode.addNewQnameProperty();
bProp.write(qpNode);
}
}
return jbNode;
}
/**
* Returns an unmodifiable collection of QNameProperty objects.
*/
public Collection getProperties()
{
List result = new ArrayList();
result.addAll(partProps.values());
result.addAll(eltProps.values());
result.addAll(attProps.values());
return Collections.unmodifiableCollection(result);
}
/**
* Looks up a property by attribute name, null if no match.
*/
public QNameProperty getPropertyForAttribute(QName name)
{
return (QNameProperty)attProps.get(name);
}
/**
* Looks up a property by element name, null if no match.
*/
public QNameProperty getPropertyForElement(QName name)
{
return (QNameProperty)eltProps.get(name);
}
/**
* Adds a new property
*/
public void addProperty(BindingProperty newProp)
{
if (newProp instanceof ParticleProperty)
{
partProps.put(((ParticleProperty)newProp).getXmlName(), newProp);
}
else if (newProp instanceof QNameProperty)
{
QNameProperty qProp = (QNameProperty)newProp;
if (qProp.isAttribute())
attProps.put(qProp.getQName(), newProp);
else
eltProps.put(qProp.getQName(), newProp);
}
else
{
throw new IllegalArgumentException();
}
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/KindRegistry.java
Index: KindRegistry.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) 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.binding.bts;
import org.apache.xmlbeans.SchemaType;
import java.util.Map;
import java.util.HashMap;
/* package protected */
/**
* Note that this is NOT a generic binding registry for users' binding; this is
* a registry that is used internally just to manage binding between
* XBeans for BindingTypes and BindingType wrapper classes. The reason
* for this mechanism is that XMLBeans binding is NOT YET powerful enough
* to bind the various kinds of BindingTypes directly to schema yet.
*
* However, in the future, we hope to make it powerful enough to do so,
* so that most of the hand-coded binding betwen Java and XML can go away.
* This class, and all the mechanisms that use it, should go away too.
*/
class KindRegistry
{
private Map registryClassFromType = new HashMap();
private Map registryTypeFromClass = new HashMap();
synchronized void registerClassAndType(Class bindingTypeClass, SchemaType bindingTypeSchemaType)
{
registryClassFromType.put(bindingTypeSchemaType, bindingTypeClass);
registryTypeFromClass.put(bindingTypeClass, bindingTypeSchemaType);
}
synchronized Class classForType(SchemaType type)
{
return (Class)registryClassFromType.get(type);
}
synchronized SchemaType typeForClass(Class clazz)
{
return (SchemaType)registryTypeFromClass.get(clazz);
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/ParticleProperty.java
Index: ParticleProperty.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) 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.binding.bts;
import org.apache.xmlbeans.impl.binding.bts.BindingProperty;
/**
* A property lined up by Schema particle. Used by JaxbBean
*/
public class ParticleProperty extends BindingProperty
{
public ParticleProperty()
{
super();
}
public ParticleProperty(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty node)
{
super(node);
}
public XmlName getXmlName()
{
return this.tXml;
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/PathBindingLoader.java
Index: PathBindingLoader.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) 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.binding.bts;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
import org.apache.xmlbeans.impl.binding.bts.JavaName;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.IdentityHashMap;
import java.util.Collections;
import java.util.Collection;
import java.util.Arrays;
/**
* A binding loader impl with the ability to chain together a path
* of other loaders.
*/
public class PathBindingLoader implements BindingLoader
{
private final Collection loaderPath;
public static final PathBindingLoader EMPTY_LOADER = new PathBindingLoader(Collections.EMPTY_LIST);
public static BindingLoader forPath(BindingLoader[] path)
{
return forPath(Arrays.asList(path));
}
public static BindingLoader forPath(Collection path)
{
IdentityHashMap seen = new IdentityHashMap();
List flattened = new ArrayList(path.size());
for (Iterator i = path.iterator(); i.hasNext(); )
addToPath(flattened, seen, (BindingLoader)i.next());
if (flattened.size() == 0)
return EMPTY_LOADER;
if (flattened.size() == 1)
return (BindingLoader)flattened.get(0);
return new PathBindingLoader(flattened);
}
private static void addToPath(List path, IdentityHashMap seen, BindingLoader loader)
{
if (seen.containsKey(loader))
return;
if (loader instanceof PathBindingLoader)
for (Iterator j = ((PathBindingLoader)path).loaderPath.iterator(); j.hasNext(); )
addToPath(path, seen, (BindingLoader)j.next());
else
path.add(loader);
}
private PathBindingLoader(List path)
{
loaderPath = Collections.unmodifiableList(path);
}
public BindingType getBindingType(JavaName jName, XmlName xName)
{
BindingType result = null;
for (Iterator i = loaderPath.iterator(); i.hasNext(); )
{
result = ((BindingLoader)i.next()).getBindingType(jName, xName);
if (result != null)
return result;
}
return null;
}
public BindingType getBindingTypeForXmlPojo(XmlName xName)
{
BindingType result = null;
for (Iterator i = loaderPath.iterator(); i.hasNext(); )
{
result = ((BindingLoader)i.next()).getBindingTypeForXmlPojo(xName);
if (result != null)
return result;
}
return null;
}
public BindingType getBindingTypeForXmlObj(XmlName xName)
{
BindingType result = null;
for (Iterator i = loaderPath.iterator(); i.hasNext(); )
{
result = ((BindingLoader)i.next()).getBindingTypeForXmlObj(xName);
if (result != null)
return result;
}
return null;
}
public BindingType getBindingTypeForJava(JavaName jName)
{
BindingType result = null;
for (Iterator i = loaderPath.iterator(); i.hasNext(); )
{
result = ((BindingLoader)i.next()).getBindingTypeForJava(jName);
if (result != null)
return result;
}
return null;
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/QNameProperty.java
Index: QNameProperty.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) 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.binding.bts;
import org.apache.xmlbeans.impl.binding.bts.BindingProperty;
import javax.xml.namespace.QName;
/**
* A property that addresses an XML element or attribute by name
* rather than by position.
*/
public class QNameProperty extends BindingProperty
{
private QName theName;
private boolean isAttribute;
private boolean isMultiple;
private boolean isOptional;
private boolean isNillable;
public QNameProperty()
{
super();
}
public QNameProperty(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty node)
{
super(node);
org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty qpNode =
(org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty)node;
theName = qpNode.getQname();
isAttribute = qpNode.getAttribute();
isMultiple = qpNode.getMultiple();
isNillable = qpNode.getNillable();
isOptional = qpNode.getOptional();
}
/**
* This function copies an instance back out to the relevant part of the XML file.
*
* Subclasses should override and call super.write first.
*/
protected org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty node)
{
node = super.write(node);
org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty qpNode =
(org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty)node;
qpNode.setQname(theName);
if (isAttribute)
qpNode.setAttribute(true);
if (isMultiple)
qpNode.setMultiple(true);
if (isOptional)
qpNode.setOptional(true);
if (isNillable)
qpNode.setNillable(true);
return qpNode;
}
public QName getQName()
{
return theName;
}
public void setQName(QName theName)
{
this.theName = theName;
}
public boolean isAttribute()
{
return isAttribute;
}
public void setAttribute(boolean attribute)
{
isAttribute = attribute;
}
public boolean isMultiple()
{
return isMultiple;
}
public void setMultiple(boolean multiple)
{
isMultiple = multiple;
}
public boolean isOptional()
{
return isOptional;
}
public void setOptional(boolean optional)
{
isOptional = optional;
}
public boolean isNillable()
{
return isNillable;
}
public void setNillable(boolean nillable)
{
isNillable = nillable;
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/SimpleBindingType.java
Index: SimpleBindingType.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) 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.binding.bts;
import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
import org.apache.xmlbeans.impl.binding.bts.BindingType;
import org.apache.xmlbeans.impl.binding.bts.JavaName;
/**
* A binding of a simple user-defined type that operates by
* delegating to another well-known (e.g., builtin) binding.
*/
public class SimpleBindingType extends BindingType
{
public SimpleBindingType(JavaName jName, XmlName xName, boolean isXmlObj)
{
super(jName, xName, isXmlObj);
}
public SimpleBindingType(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
super(node);
org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType stNode = (org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType)node;
asIfXmlType = XmlName.forString(stNode.getAsXml());
}
protected org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
{
org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType stNode = (org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType)super.write(node);
stNode.setAsXml(asIfXmlType.toString());
return stNode;
}
private XmlName asIfXmlType;
// typically the "as if" type is the closest base builtin type.
public XmlName getAsIfXmlType()
{
return asIfXmlType;
}
public void setAsIfXmlType(XmlName asIfXmlType)
{
this.asIfXmlType = asIfXmlType;
}
// question: do we want an "as if Java type" as well?
public BindingType getAsIfBindingType(BindingLoader loader)
{
return loader.getBindingType(getJavaName(), asIfXmlType);
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/XmlName.java
Index: XmlName.java
===================================================================
/**
* XBeans implementation.
* Author: David Bau
* Date: Oct 1, 2003
*/
package org.apache.xmlbeans.impl.binding.bts;
import org.apache.xmlbeans.impl.common.XMLChar;
import javax.xml.namespace.QName;
/**
* An XmlName is a way of uniquely identifying any
* logical component in a schema.
*
* For a diagram of the kinds of components that can be referenced,
* see http://www.w3.org/TR/xmlschema-1/components.gif
*
* A signature looks like this:
*
* a-name1|t|e=name2|p.3|s|p.5|c|p.0|t|e=name3@my-namespace
*
* This reads as:
* The attribute declaration called "name1" (unqualified) inside
* the anonymous type of
* the element declaration called "name2" (qualified) which is
* the third particle of
* the sequence which is
* the fifth particle of
* the choice which is
* the zeroth particle of
* the anonymous type of
* the element named name3 (qualified) in
* the namespace my-namespace.
*
* Hyphens (-) introduce unqualified names
* Equals (=) introduce qualified names
* Dot (.) introduce numbers
* Anonymous components are just single-letters.
*
* There are these types of components
*
* n = Notations (named, global only)
* e = Element decls (named, global or inside t or p)
* Identity constraint defs
* k = key/unique/keyref (named, in elts only)
* g = Model group defs (named, global only)
* Model group compositors:
* l = All compositors (anon, inside p or g)
* s = Sequence compositors (anon, inside p or g)
* c = Choice compositors (anon, inside p or g)
* p = Particles (numbered, inside t or l or s or c)
* w = Wildcards (anon, inside p only)
* v = Attribute Uses (named, in type only, inside t)
* a = Attribute Declarations (named, global or inside t or v)
* r = Attribute group definitions (named, global only)
* t = Type definitions (name when global, or anon inside i, m, e, a, t)
*
* Not part of the spec, but we treat as components:
* d = document type definition (named, global only)
* b = attribute-container type definition (named, global only)
* m = union member definition (numbered, inside t only)
* y = soap array of dimension n (numbered, referencing global t or another y only)
*
* A canonical signature will shortcut the following:
*
* - global elements do not need to be explicitly nested inside their
* containing document types (e=name|d=name@namespace -> e=name@namespace)
* - global attributes do not need to be explicitly nested inside their
* containing attribute types (e=name|d=name@namespace -> e=name@namespace)
* - an element of a type, if its name is unique, may be referenced without the
* intervening particle path. (e.g., e=name2|p.3|s|p.5|c|p.0|t can be
* reduced to e=name2|t)
* - an attribute of a type may be referenced without explicitly putting it
* inside an attribute use (e.g., a-name1|v-name1|t -> a-name1|t)
*
* Notice SOAP arrays are included in the naming schema, as follows:
*
* A soap array type written like this:
* x:drg[,,,][,][,,,]
*
* Has the following signature:
* y.3|y.2|y.4|t=drg@foobar
*/
public class XmlName
{
private String namespace;
private String path;
public static final int NOTATION = 'n';
public static final int ELEMENT = 'e';
public static final int ID_CONSTRAINT = 'k';
public static final int MODEL_GROUP = 'g';
public static final int ALL = 'l';
public static final int SEQUENCE = 's';
public static final int CHOICE = 'c';
public static final int PARTICLE = 'p';
public static final int WILDCARD = 'w';
public static final int ATTRIBUTE_USE = 'v';
public static final int ATTRIBUTE = 'a';
public static final int ATTRIBUTE_GROUP = 'r';
public static final int TYPE = 't';
public static final int DOCUMENT_TYPE = 'd';
public static final int ATTRIBUTE_TYPE = 'b';
public static final int MEMBER = 'm';
public static final int SOAP_ARRAY = 'y';
/**
* This function is used to see if a path is valid or not.
*/
public boolean valid()
{
XmlName outerComponent = null;
int outerType = 0;
String localName = internalGetStringName();
boolean hasNumber = internalGetNumber() >= 0;
boolean hasName = (localName != null);
boolean isAnonymous = internalIsAnonymous();
boolean isQualified = internalIsQualified();
boolean isGlobal = !isNestedComponent();
if (!isGlobal)
{
outerComponent = getOuterComponent();
outerType = outerComponent.getComponentType();
}
boolean result;
if (localName != null && !XMLChar.isValidNCName(localName))
return false;
switch (getComponentType())
{
case NOTATION:
result = (isGlobal && hasName && isQualified);
case ELEMENT:
result = (hasName && (isGlobal && isQualified || outerType == TYPE || outerType == PARTICLE));
case ID_CONSTRAINT:
result = (hasName && outerType == ELEMENT);
case MODEL_GROUP:
result = (hasName && isGlobal);
case ALL:
case SEQUENCE:
case CHOICE:
result = (isAnonymous && (outerType == PARTICLE || outerType == MODEL_GROUP));
case PARTICLE:
result = (hasNumber && (outerType == SEQUENCE || outerType == CHOICE || outerType == ALL || outerType == TYPE));
case WILDCARD:
result = (isAnonymous && (outerType == PARTICLE || outerType == TYPE || outerType == ATTRIBUTE_GROUP));
case ATTRIBUTE_USE:
result = (hasName && (outerType == TYPE || outerType == ATTRIBUTE_GROUP));
case ATTRIBUTE:
result = (hasName && (isGlobal && isQualified || outerType == TYPE || outerType == ATTRIBUTE_USE));
case ATTRIBUTE_GROUP:
result = (hasName && isQualified && isGlobal);
case TYPE:
result = ((hasName && isQualified && isGlobal) || (isAnonymous && outerType == TYPE || outerType == ELEMENT || outerType == ATTRIBUTE || outerType == MEMBER));
case DOCUMENT_TYPE:
result = (hasName && isQualified && isGlobal);
case ATTRIBUTE_TYPE:
result = (hasName && isQualified && isGlobal);
case MEMBER:
result = (isAnonymous && outerType == TYPE);
case SOAP_ARRAY:
result = (hasNumber && (outerType == SOAP_ARRAY || outerType == TYPE && !outerComponent.isNestedComponent()));
default:
result = false;
}
if (!result)
return false;
if (isGlobal)
return true;
return outerComponent.valid();
}
/**
* Creates an XMLName based on the given String signature.
*
* This signature is described in the javadoc for this class.
*/
public static XmlName forString(String signature)
{
String path;
String namespace;
int atSign = signature.indexOf('@');
if (atSign < 0)
{
namespace = "";
path = signature;
}
else
{
namespace = signature.substring(atSign + 1);
path = signature.substring(0, atSign);
}
return forPathAndNamespace(path, namespace);
}
/**
* Creates an XMLName for a schema type with the given fully-qualified QName.
*/
public static XmlName forTypeNamed(QName name)
{
return forPathAndNamespace("t=" + name.getLocalPart(), name.getNamespaceURI());
}
/**
* Creates an XMLName for a global schema element with the given fully-qualified QName.
*/
public static XmlName forElementNamed(QName name)
{
return forPathAndNamespace("e=" + name.getLocalPart(), name.getNamespaceURI());
}
/**
* Creates an XMLName for a global schema attribute with the given fully-qualified QName.
*/
public static XmlName forAttributeNamed(QName name)
{
return forPathAndNamespace("a=" + name.getLocalPart(), name.getNamespaceURI());
}
private static XmlName forPathAndNamespace(String path, String namespace)
{
return new XmlName(path, namespace);
}
private XmlName(String path, String namespace)
{
if (path == null || namespace == null)
throw new IllegalArgumentException();
this.path = path;
this.namespace = namespace;
}
boolean isNestedComponent()
{
int index = path.indexOf('|');
return index >= 0;
}
XmlName getOuterComponent()
{
int index = path.indexOf('|');
if (index < 0)
return null;
return forPathAndNamespace(path.substring(index + 1), namespace);
}
public int getComponentType()
{
if (path.length() > 0)
return path.charAt(0);
return 0; // unknown type
}
/**
* Returns negative if there is no number
*/
private int internalGetNumber()
{
if (path.length() <= 1 || path.charAt(1) != '.')
return -1;
int index = path.indexOf('|');
if (index < 0)
index = path.length();
try
{
return Integer.parseInt(path.substring(2, index));
}
catch (Exception e)
{
return -1;
}
}
/**
* Returns the number locating this component within its parent,
* or throws an exception if there is none. Only union members (m)
* and particles (p) have numbers.
*/
public int getNumber()
{
int result = internalGetNumber();
if (result < 0)
throw new IllegalStateException("Path has no number");
return result;
}
private String internalGetStringName()
{
if (path.length() <= 1 || path.charAt(1) != '=' && path.charAt(1) != '-')
return null;
int index = path.indexOf('|');
if (index < 0)
index = path.length();
return path.substring(2, index);
}
private boolean internalIsQualified()
{
return (path.length() > 1 && path.charAt(1) == '=');
}
private boolean internalIsAnonymous()
{
return (path.length() <= 1 || path.charAt(1) == '|');
}
/**
* Returns the name locating this component within its parent, or
* returns null if there is none. Notice that if looking up elements
* by name in a type, you get the first element defintion when there
* are multiple ones. A full particle path can disambiguate.
*
* This name will be qualified in a namespace if appropriate, but,
* for example, local unqualified attributes will have a QName that
* is unqualified.
*
* Element, attributes, identity constraints, model/attribute groups,
* and notations have names.
*/
public QName getQName()
{
String localName = internalGetStringName();
if (localName == null)
return null;
if (internalIsQualified())
return new QName(namespace, localName);
else
return new QName(localName);
}
/**
* Returns the signature string.
*/
public String toString()
{
if (namespace.length() == 0)
return path;
return path + '@' + namespace;
}
public boolean equals(Object o)
{
if (this == o) return true;
if (!(o instanceof XmlName)) return false;
final XmlName xmlName = (XmlName) o;
if (!namespace.equals(xmlName.namespace)) return false;
if (!path.equals(xmlName.path)) return false;
return true;
}
public int hashCode()
{
int result;
result = namespace.hashCode();
result = 29 * result + path.hashCode();
return result;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org