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 2004/01/20 22:57:38 UTC
cvs commit: xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc JDExecutableMember.java JDParameter.java
pcal 2004/01/20 13:57:38
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
BindingTypeName.java XmlTypeName.java
v2/src/binding/org/apache/xmlbeans/impl/binding/compile
BindingCompiler.java Schema2Java.java
v2/src/jam/org/apache/xmlbeans/impl/jam JClass.java
v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc
JDExecutableMember.java JDParameter.java
Added: v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
DebugTylarWriter.java
Log:
fix schema2java bug with document element of simple type, jam tweaks, few other minor fixes
Revision Changes Path
1.4 +4 -2 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingTypeName.java
Index: BindingTypeName.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingTypeName.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BindingTypeName.java 4 Dec 2003 21:14:55 -0000 1.3
+++ BindingTypeName.java 20 Jan 2004 21:57:38 -0000 1.4
@@ -76,8 +76,10 @@
private BindingTypeName(JavaTypeName jName, XmlTypeName xName)
{
- this.jName = jName;
- this.xName = xName;
+ if (jName == null) throw new IllegalArgumentException("null jName");
+ if (xName == null) throw new IllegalArgumentException("null xName");
+ this.jName = jName;
+ this.xName = xName;
}
public JavaTypeName getJavaName()
1.2 +11 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/XmlTypeName.java
Index: XmlTypeName.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/XmlTypeName.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XmlTypeName.java 4 Dec 2003 21:14:55 -0000 1.1
+++ XmlTypeName.java 20 Jan 2004 21:57:38 -0000 1.2
@@ -223,6 +223,9 @@
*/
public static XmlTypeName forString(String signature)
{
+ if (signature == null) {
+ throw new IllegalArgumentException("null signature");
+ }
String path;
String namespace;
int atSign = signature.indexOf('@');
@@ -244,6 +247,7 @@
*/
public static XmlTypeName forTypeNamed(QName name)
{
+ if (name == null) throw new IllegalArgumentException("null qname");
return forPathAndNamespace(TYPE + "=" + name.getLocalPart(), name.getNamespaceURI());
}
@@ -252,6 +256,7 @@
*/
public static XmlTypeName forGlobalName(char kind, QName name)
{
+ if (name == null) throw new IllegalArgumentException("null qname");
return forPathAndNamespace(kind + "=" + name.getLocalPart(), name.getNamespaceURI());
}
@@ -260,6 +265,8 @@
*/
public static XmlTypeName forNestedName(char kind, String localName, boolean qualified, XmlTypeName outer)
{
+ if (localName == null) throw new IllegalArgumentException("null localName");
+ if (outer == null) throw new IllegalArgumentException("null outer");
return forPathAndNamespace(kind + (qualified ? "=" : "-") + localName + "|" + outer.path, outer.namespace);
}
@@ -268,6 +275,7 @@
*/
public static XmlTypeName forNestedNumber(char kind, int n, XmlTypeName outer)
{
+ if (outer == null) throw new IllegalArgumentException("null outer");
return forPathAndNamespace(kind + "." + n + "|" + outer.path, outer.namespace);
}
@@ -276,6 +284,7 @@
*/
public static XmlTypeName forNestedAnonymous(char kind, XmlTypeName outer)
{
+ if (outer == null) throw new IllegalArgumentException("null outer");
return forPathAndNamespace(kind + "|" + outer.path, outer.namespace);
}
@@ -284,6 +293,7 @@
*/
public static XmlTypeName forSchemaType(SchemaType sType)
{
+ if (sType == null) throw new IllegalArgumentException("null sType");
if (sType.getName() != null)
return forTypeNamed(sType.getName());
@@ -318,6 +328,7 @@
*/
public static XmlTypeName forSoapArrayType(SOAPArrayType sType)
{
+ if (sType == null) throw new IllegalArgumentException("null sType");
StringBuffer sb = new StringBuffer();
sb.append(SOAP_ARRAY + "." + sType.getDimensions().length);
int[] ranks = sType.getRanks();
1.10 +2 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompiler.java
Index: BindingCompiler.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompiler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- BindingCompiler.java 14 Jan 2004 07:19:15 -0000 1.9
+++ BindingCompiler.java 20 Jan 2004 21:57:38 -0000 1.10
@@ -126,6 +126,8 @@
/**
* Public method for beginning the binding compilation process with
* an arbitrary TylarWriter. Delegates to the subclass to do the real work.
+ * Note: the caller of this method is responsible for calling close() on
+ * the TylarWriter!
*/
public final void bind(TylarWriter writer) {
mIsCompilationStarted = true;
1.10 +77 -22 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java
Index: Schema2Java.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Schema2Java.java 14 Jan 2004 07:19:15 -0000 1.9
+++ Schema2Java.java 20 Jan 2004 21:57:38 -0000 1.10
@@ -60,6 +60,7 @@
import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
import org.apache.xmlbeans.impl.binding.tylar.TylarConstants;
import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylarImpl;
+import org.apache.xmlbeans.impl.binding.tylar.DebugTylarWriter;
import org.apache.xmlbeans.impl.binding.joust.Variable;
import org.apache.xmlbeans.impl.binding.joust.CompilingJavaOutputStream;
import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
@@ -67,6 +68,7 @@
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.soap.SOAPArrayType;
import org.apache.xmlbeans.soap.SchemaWSDLArrayType;
+import org.w3.x2001.xmlSchema.SchemaDocument;
import javax.xml.namespace.QName;
import java.util.ArrayList;
@@ -118,9 +120,12 @@
* If you use this, you absolutely have to call setInput later. This is
* here just as a convenience for Schema2JavaTask.
*/
- /*package*/ Schema2Java() {}
+ /*package*/
+ Schema2Java() {
+ }
- /*package*/ void setSchemaTypeSystem(SchemaTypeSystem s) {
+ /*package*/
+ void setSchemaTypeSystem(SchemaTypeSystem s) {
if (s == null) throw new IllegalArgumentException("null sts");
sts = s;
}
@@ -169,7 +174,7 @@
public void setKeepGeneratedJava(boolean b) {
assertCompilationStarted(false);
getDefaultJoust().setKeepGenerated(b);
- }
+ }
// ========================================================================
// BindingCompiler implementation
@@ -179,13 +184,12 @@
* the defaultJoust.
*/
protected ExplodedTylarImpl createDefaultExplodedTylarImpl(File tylarDestDir)
- throws IOException
- {
+ throws IOException {
CompilingJavaOutputStream joust = getDefaultJoust();
- joust.setSourceDir(new File(tylarDestDir,TylarConstants.SRC_ROOT));
+ joust.setSourceDir(new File(tylarDestDir, TylarConstants.SRC_ROOT));
joust.setCompilationDir(tylarDestDir);
mJoust = joust;
- return ExplodedTylarImpl.create(tylarDestDir,mJoust);
+ return ExplodedTylarImpl.create(tylarDestDir, mJoust);
}
/**
@@ -199,8 +203,8 @@
if ((mJoust = writer.getJavaOutputStream()) == null) {
//sanity check
throw new IllegalArgumentException("The specified TylarWriter does not " +
- "provide a JavaOutputStream, and so it cannot be used with "+
- "schema2java.");
+ "provide a JavaOutputStream, and so it cannot be used with " +
+ "schema2java.");
}
bind();
try {
@@ -267,8 +271,11 @@
* a schema type, and a category.
*/
private void createScratchArea() {
+ logVerbose("creating scratch area...");
for (Iterator i = allTypeIterator(); i.hasNext();) {
SchemaType sType = (SchemaType) i.next();
+ logVerbose("processing schema type "+sType);
+
XmlTypeName xmlName = XmlTypeName.forSchemaType(sType);
Scratch scratch;
@@ -299,7 +306,7 @@
scratchFromXmlName.put(xmlName, scratch);
scratchFromSchemaType.put(sType, scratch);
-
+ logVerbose("registered scratch "+scratch.getXmlName()+" for "+sType);
}
}
@@ -310,6 +317,8 @@
* process that occurs in dependency order.
*/
private void resolveJavaName(Scratch scratch) {
+ if (scratch == null) throw new IllegalArgumentException("null scratch");
+ logVerbose("Resolving " + scratch.getXmlName());
// already resolved (we recurse to do in dependency order)
if (scratch.getJavaName() != null)
return;
@@ -362,12 +371,25 @@
case Scratch.ELEMENT:
case Scratch.ATTRIBUTE:
{
+ logVerbose("processing element "+scratch.getXmlName());
SchemaType contentType = scratch.getSchemaType().getProperties()[0].getType();
- Scratch contentScratch = scratchForSchemaType(contentType);
- resolveJavaName(contentScratch);
- scratch.setJavaName(contentScratch.getJavaName());
- scratch.setAsIf(contentScratch.getXmlName());
- return;
+ logVerbose("content type is "+contentType.getName());
+ if (contentType.isPrimitiveType()) {
+ //REVIEW this is a quick bug fix for the case where an element
+ //is of a primitive type. I'm not completely sure it is the right
+ //thing to do. pcal
+ XmlTypeName xtn = XmlTypeName.forSchemaType(contentType);
+ scratch.setJavaName(mLoader.lookupPojoFor(xtn).getJavaName());
+ scratch.setAsIf(xtn);
+ return;
+ } else {
+ Scratch contentScratch = scratchForSchemaType(contentType);
+ logVerbose("content scratch is "+contentScratch);
+ resolveJavaName(contentScratch);
+ scratch.setJavaName(contentScratch.getJavaName());
+ scratch.setAsIf(contentScratch.getXmlName());
+ return;
+ }
}
default:
@@ -380,7 +402,7 @@
*/
private void createBindingType(Scratch scratch) {
assert(scratch.getBindingType() == null);
-
+ logVerbose("createBindingType for "+scratch);
BindingTypeName btName = BindingTypeName.forPair(scratch.getJavaName(), scratch.getXmlName());
switch (scratch.getCategory()) {
@@ -503,9 +525,9 @@
prop = new QNameProperty();
prop.setQName(props[i].getName());
prop.setAttribute(props[i].isAttribute());
- prop.setSetterName(MethodName.create("set"+propName,
+ prop.setSetterName(MethodName.create("set" + propName,
bType.getName().getJavaName()));
- prop.setGetterName(MethodName.create("get"+propName));
+ prop.setGetterName(MethodName.create("get" + propName));
prop.setCollectionClass(collection);
prop.setBindingType(bType);
prop.setNillable(props[i].hasNillable() != SchemaProperty.NEVER);
@@ -682,7 +704,7 @@
*/
private void resolveSimpleScratch(Scratch scratch) {
assert(scratch.getCategory() == Scratch.ATOMIC_TYPE);
-
+ logVerbose("resolveSimpleScratch "+scratch.getXmlName());
if (scratch.getJavaName() != null)
return;
@@ -867,6 +889,10 @@
public void setStructureResolved(boolean isStructureResolved) {
this.isStructureResolved = isStructureResolved;
}
+
+ public String toString() {
+ return getJavaName()+"<->"+getXmlName();
+ }
}
/**
@@ -889,6 +915,7 @@
allSeenTypes.addAll(Arrays.asList(sts.documentTypes()));
allSeenTypes.addAll(Arrays.asList(sts.attributeTypes()));
allSeenTypes.addAll(Arrays.asList(sts.globalTypes()));
+// allSeenTypes.addAll(Arrays.asList(XmlBeans.getBuiltinTypeSystem().globalTypes()));
index = 0;
}
@@ -942,6 +969,7 @@
public void remove() {
throw new UnsupportedOperationException();
}
+
}
// ========================================================================
@@ -1010,9 +1038,9 @@
baseJavaname = null;
}
// begin writing class
- mJoust.startFile(packageName,shortClassName);
+ mJoust.startFile(packageName, shortClassName);
mJoust.writeComment("Generated from schema type " + scratch.getXmlName());
- mJoust.startClass(Modifier.PUBLIC,baseJavaname, null);
+ mJoust.startClass(Modifier.PUBLIC, baseJavaname, null);
Collection props = scratch.getQNameProperties();
Map fieldNames = new HashMap();
Set seenFieldNames = new HashSet();
@@ -1074,5 +1102,32 @@
seenNames.add(fieldName);
return fieldName;
}
-}
+
+ // ========================================================================
+ // main method - for quick debugging
+
+ public static void main(String[] schemas) {
+ try {
+ File[] schemaFiles = new File[schemas.length];
+ for (int i = 0; i < schemas.length; i++) schemaFiles[i] = new File(schemas[i]);
+ XmlObject[] xsds = new XmlObject[schemas.length];
+ for (int i = 0; i < xsds.length; i++) {
+ xsds[i] = SchemaDocument.Factory.parse(new File(schemas[i]));
+ }
+ SchemaTypeSystem sts =
+ XmlBeans.compileXsd(xsds,
+ XmlBeans.getBuiltinTypeSystem(),
+ null);
+ Schema2Java s2j = new Schema2Java(sts);
+ s2j.setVerbose(true);
+ TylarWriter tw = new DebugTylarWriter();
+ s2j.bind(tw);
+ tw.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.err.flush();
+ System.out.flush();
+ }
+}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DebugTylarWriter.java
Index: DebugTylarWriter.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.tylar;
import org.apache.xmlbeans.impl.binding.bts.BindingFile;
import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
import org.apache.xmlbeans.impl.binding.joust.SourceJavaOutputStream;
import org.apache.xmlbeans.impl.binding.joust.WriterFactory;
import org.apache.xmlbeans.XmlOptions;
import org.w3.x2001.xmlSchema.SchemaDocument;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
/**
* Implementation of TylarWriter which simply dumps everything it gets to some
* Writer. This can be useful for quick debugging.
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class DebugTylarWriter implements TylarWriter, WriterFactory {
// ========================================================================
// Variables
private PrintWriter mOut;
private JavaOutputStream mJoust;
private XmlOptions mOptions;
// ========================================================================
// Constructors
public DebugTylarWriter() {
this(new PrintWriter(System.out,true));
}
public DebugTylarWriter(PrintWriter out) {
mJoust = new SourceJavaOutputStream(this);
mOut = out;
mOptions = new XmlOptions();
mOptions.setSavePrettyPrint();
}
// ========================================================================
// TylarWriter implementation
public void writeBindingFile(BindingFile bf) throws IOException {
bf.write().save(mOut,mOptions);
}
public void writeSchema(SchemaDocument xsd, String fp) throws IOException {
xsd.save(mOut,mOptions);
}
public JavaOutputStream getJavaOutputStream() {
return mJoust;
}
public void close() {
mOut.flush();
}
// ========================================================================
// WriterFactory implementation
public Writer createWriter(String packageName, String className)
throws IOException {
return mOut;
}
}
1.3 +13 -12 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JClass.java
Index: JClass.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JClass.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JClass.java 3 Dec 2003 22:46:15 -0000 1.2
+++ JClass.java 20 Jan 2004 21:57:38 -0000 1.3
@@ -197,11 +197,13 @@
/**
- * Returns a .
-
- * as detailed in section 8.3 of the Java Beans specification,
- * 'Design Patterns for Properties.' Note that according to this
- * pattern, public fields are never considered properties.
+ * Returns a representation of a java bean property as detailed in section
+ * 8.3 of the Java Beans specification, 'Design Patterns for Properties.'
+ * A JProperty can be thought of as a union of a getter method and
+ * corresponding setter method, although only one of these is required
+ * (read-only and write-only properties are returned). Note that
+ * public fields are never considered properties, as deetailed in
+ * the specification.
*/
public JProperty[] getProperties();
@@ -341,9 +343,7 @@
/**
- * <p>Returns the JClassLoader which loaded this class.</p> REVIEW
- * should the clasloader be the parent? should we ditch/reformulate
- * JPackage?
+ * <p>Returns the JClassLoader which loaded this class.</p>
*/
public JClassLoader getClassLoader();
@@ -353,9 +353,10 @@
public JClass forName(String name);
/**
- * Returns a list of classes that were imported by this class. This
- * includes packages imported via the '*' import notation as well as
- * the packages which contain explicitly imported classes.
+ * Returns the minmal set of JPackages which contain all of the clases
+ * imported by this class. This includes packages imported via the '*'
+ * import notation as well as the packages which contain explicitly
+ * imported classes.
*
* Note that this is an optional operation; if the source for the
* class is not available (i.e. this JClass is backed by a
@@ -382,4 +383,4 @@
*/
public boolean isUnresolved();
-}
+}
\ No newline at end of file
1.3 +2 -1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JDExecutableMember.java
Index: JDExecutableMember.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JDExecutableMember.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JDExecutableMember.java 3 Dec 2003 22:46:15 -0000 1.2
+++ JDExecutableMember.java 20 Jan 2004 21:57:38 -0000 1.3
@@ -138,6 +138,7 @@
// Package methods
// this is here for the benefit of JDParameter.getLocalAnnotations()
- /*package*/ ExecutableMemberDoc getMember() { return mMember; }
+ // as well as subclasses.
+ public ExecutableMemberDoc getMember() { return mMember; }
}
1.3 +3 -3 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JDParameter.java
Index: JDParameter.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JDParameter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JDParameter.java 3 Dec 2003 22:46:15 -0000 1.2
+++ JDParameter.java 20 Jan 2004 21:57:38 -0000 1.3
@@ -83,9 +83,9 @@
// ========================================================================
// Constructors
- public JDParameter(Parameter p,
- JDExecutableMember parent,
- JClassLoader loader) {
+ public JDParameter(Parameter p,
+ JDExecutableMember parent,
+ JClassLoader loader) {
mParameter = p;
mParent = parent;
mLoader = loader;
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org