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 pc...@apache.org on 2003/10/22 21:03:09 UTC
cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile Java2Schema.java
pcal 2003/10/22 12:03:09
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
BindingFile.java BindingType.java
v2/src/binding/org/apache/xmlbeans/impl/binding/compile
Java2Schema.java
Log:
binding: few tweaks for java2schema
Revision Changes Path
1.5 +4 -1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingFile.java
Index: BindingFile.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingFile.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BindingFile.java 22 Oct 2003 02:32:43 -0000 1.4
+++ BindingFile.java 22 Oct 2003 19:03:09 -0000 1.5
@@ -65,6 +65,8 @@
import java.util.Collections;
import java.io.IOException;
+import com.sun.tools.javac.v8.util.Pair;
+
/**
* Represents a BindingLoader whose contents are loaded from a
@@ -172,7 +174,8 @@
{
Map.Entry entry = (Map.Entry)i.next();
JavaName jName = (JavaName)entry.getKey();
- XmlName xName = (XmlName)entry.getValue();
+ NamePair pair = (NamePair)entry.getValue();
+ XmlName xName = pair.getXmlName();
org.apache.xmlbeans.x2003.x09.bindingConfig.Mapping mNode = jtabNode.addNewMapping();
mNode.setJavatype(jName.toString());
mNode.setXmlcomponent(xName.toString());
1.2 +20 -20 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BindingType.java 10 Oct 2003 20:09:27 -0000 1.1
+++ BindingType.java 22 Oct 2003 19:03:09 -0000 1.2
@@ -61,42 +61,42 @@
/**
* 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()));
@@ -105,27 +105,27 @@
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
@@ -138,12 +138,12 @@
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))
@@ -152,7 +152,7 @@
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);
1.2 +36 -19 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java
Index: Java2Schema.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Java2Schema.java 22 Oct 2003 02:32:43 -0000 1.1
+++ Java2Schema.java 22 Oct 2003 19:03:09 -0000 1.2
@@ -60,9 +60,6 @@
import org.apache.xmlbeans.impl.jam.JClass;
import org.apache.xmlbeans.impl.jam.JProperty;
import org.apache.xmlbeans.impl.jam.JElement;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.XmlBeans;
import org.w3.x2001.xmlSchema.*;
import javax.xml.namespace.QName;
@@ -81,12 +78,15 @@
private static final String JAVA_PACKAGE_PREFIX = "java.";
private static final String TAG_CT = "xsdgen:complexType";
- private static final String TAG_CT_TYPENAME = TAG_CT+"@typeName";
- private static final String TAG_CT_TARGETNS = TAG_CT+"@targetNamespace";
- private static final String TAG_CT_ROOT = TAG_CT+"@rootElement";
+ private static final String TAG_CT_TYPENAME = TAG_CT+".typeName";
+ private static final String TAG_CT_TARGETNS = TAG_CT+".targetNamespace";
+ private static final String TAG_CT_ROOT = TAG_CT+".rootElement";
private static final String TAG_EL = "xsdgen:element";
- private static final String TAG_EL_NAME = TAG_EL+"@name";
+ private static final String TAG_EL_NAME = TAG_EL+".name";
+
+ private static final String TAG_AT = "xsdgen:attribute";
+ private static final String TAG_AT_NAME = TAG_AT+".name";
// =========================================================================
// Variables
@@ -138,40 +138,57 @@
// create the schema type
TopLevelComplexType xsdType = mSchema.addNewComplexType();
String tns = getTargetNamespace(clazz);
- QName qname = new QName(tns,clazz.getSimpleName());
+ String xsdName = getAnnotation(clazz,TAG_CT_TYPENAME,clazz.getSimpleName());
+ QName qname = new QName(tns,xsdName);
+ xsdType.setName(xsdName);
// create a binding type
ByNameBean bindType = new ByNameBean(getJavaName(clazz),
XmlName.forTypeNamed(qname),
isXmlObj(clazz));
mBindingFile.addBindingType(bindType,true,true);
// run through the class' properties to populate the binding and xsdtypes
+ //FIXME this is going to have to change to take inheritance into account
JProperty props[] = clazz.getProperties();
Group xsdSequence = null;
for(int i=0; i<props.length; i++) {
if (props[i].getGetter() == null || props[i].getSetter() == null) {
continue; // we can only deal with read-write props
}
- String propName = getAnnotation(props[i],TAG_EL_NAME,props[i].getSimpleName());
+ boolean isAttribute = false;
+ String propName = getAnnotation(props[i],TAG_AT_NAME,null);
+ if (propName != null) {
+ isAttribute = true;
+ } else {
+ propName = getAnnotation(props[i],TAG_EL_NAME,props[i].getSimpleName());
+ }
BindingType propType = getBindingTypeFor(props[i].getType());
QNameProperty qprop = new QNameProperty();
qprop.setBindingType(propType);
- qprop.setQName(new QName(propName));
+ qprop.setQName(new QName(tns,propName));
qprop.setGetterName(props[i].getGetter().getSimpleName());
qprop.setSetterName(props[i].getSetter().getSimpleName());
bindType.addProperty(qprop);
// also populate the schema type
- if (xsdSequence == null) xsdSequence = xsdType.addNewSequence();
- LocalElement xsdElement = xsdSequence.addNewElement();
- xsdElement.setName(propName);
- xsdElement.setType(getBuiltinTypeNameFor(props[i].getType()));
+ if (!isAttribute) {
+ if (xsdSequence == null) xsdSequence = xsdType.addNewSequence();
+ LocalElement xsdElement = xsdSequence.addNewElement();
+ xsdElement.setName(propName);
+ xsdElement.setType(getBuiltinTypeNameFor(props[i].getType()));
+ } else {
+ Attribute xsdAtt = xsdType.addNewAttribute();
+ qprop.setAttribute(true);
+ xsdAtt.setName(propName);
+ xsdAtt.setType(getBuiltinTypeNameFor(props[i].getType()));
+ }
}
-
// check to see if they want to create a root elements from this type
JAnnotation[] anns = clazz.getAnnotations(TAG_CT_ROOT);
- if (anns.length != 0) {
- for(int i=0; i<anns.length; i++) {
-
- }
+ for(int i=0; i<anns.length; i++) {
+ TopLevelElement root = mSchema.addNewElement();
+ root.setName(anns[i].getStringValue());
+ root.setType(qname);
+ // FIXME still not entirely clear to me what we should do about
+ // the binding file here
}
return bindType;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org