You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by da...@apache.org on 2003/12/12 22:33:13 UTC
cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile Both2BindTask.java ExplodedTylarBuilder.java TypeMatcher.java
davidbau 2003/12/12 13:33:13
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/bts
BindingType.java
v2/src/binding/org/apache/xmlbeans/impl/binding/compile
Both2BindTask.java ExplodedTylarBuilder.java
TypeMatcher.java
Log:
Added a couple features to the Both2Binding task to make it more
configurable: schema sources can be separated, and the exact filename
of the output binding-config.xml can be specified. The pluggable
And the TypeMatcher can override the actual bound type corresponding
to the declared type of a property.
Code review: scott
DRT: passed
Revision Changes Path
1.9 +4 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingType.java
Index: BindingType.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingType.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BindingType.java 4 Dec 2003 21:14:55 -0000 1.8
+++ BindingType.java 12 Dec 2003 21:33:13 -0000 1.9
@@ -144,4 +144,8 @@
registerClassAndType(SimpleDocumentBinding.class, org.apache.xml.xmlbeans.bindingConfig.SimpleDocumentBinding.type);
}
+ public String toString()
+ {
+ return getClass().getName() + "[" + btName.getJavaName() + "; " + btName.getXmlName() + "]";
+ }
}
1.3 +71 -7 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2BindTask.java
Index: Both2BindTask.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2BindTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Both2BindTask.java 11 Dec 2003 19:32:54 -0000 1.2
+++ Both2BindTask.java 12 Dec 2003 21:33:13 -0000 1.3
@@ -59,6 +59,7 @@
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.xmlbeans.XmlException;
@@ -76,11 +77,14 @@
// Variables
private File mDestDir = null;
+ private File mDestFile = null;
private Path mSrc = null;
private Path mClasspath = null;
private List mXsdFiles = null;
private List mJavaFiles = null;
private String mTypeMatcherClass = null;
+ private List mSchemaFilesets = new ArrayList();
+ private File mSchema = null;
// =========================================================================
// Task attributes
@@ -89,9 +93,14 @@
{
mDestDir = dir;
}
+
+ public void setDestFile(File file)
+ {
+ mDestFile = file;
+ }
/**
- * Set the source directories to find the source XSD files.
+ * Set the source directories to find the source Java files.
*/
public void setSrcdir(Path srcDir)
{
@@ -104,6 +113,22 @@
}
/**
+ * Sets a single schema.
+ */
+ public void setSchema(File file)
+ {
+ mSchema = file;
+ }
+
+ /**
+ * Adds a fileset for source XSD files
+ */
+ public void addSchema(FileSet fileSet)
+ {
+ mSchemaFilesets.add(fileSet);
+ }
+
+ /**
* Sets the typematcher class name. Must be a fully-qualified
* class name for a class that implements the TypeMatcher interface.
*/
@@ -172,7 +197,21 @@
DirectoryScanner ds = this.getDirectoryScanner(srcDir);
String[] files = ds.getIncludedFiles();
- scanDir(srcDir, files);
+ scanJavaDir(srcDir, files);
+ }
+
+ // now scan XSD files
+ // single file
+ if (mSchema != null)
+ {
+ if (!mSchema.exists())
+ throw new BuildException("schema " + mSchema + " does not exist!", getLocation());
+ mXsdFiles.add(mSchema);
+ }
+
+ for (int i = 0; i < mSchemaFilesets.size(); i++)
+ {
+ scanSchemaFileset((FileSet)mSchemaFilesets.get(i));
}
compile();
@@ -184,16 +223,27 @@
mJavaFiles = new ArrayList();
}
- protected void scanDir(File srcDir, String[] files) {
+ protected void scanJavaDir(File srcDir, String[] files) {
for (int i = 0; i < files.length; i++)
{
- if (files[i].endsWith(".xsd"))
- mXsdFiles.add(new File(srcDir, files[i]));
if (files[i].endsWith(".java"))
mJavaFiles.add(new File(srcDir, files[i]));
}
}
+ protected void scanSchemaFileset(FileSet fs)
+ {
+ File fromDir = fs.getDir(getProject());
+ DirectoryScanner ds = fs.getDirectoryScanner(getProject());
+ String[] srcFiles = ds.getIncludedFiles();
+ for (int i = 0; i < srcFiles.length; i++)
+ {
+ if (srcFiles[i].endsWith(".xsd"))
+ mXsdFiles.add(new File(fromDir, srcFiles[i]));
+ }
+
+ }
+
protected File[] namesToFiles(String[] names)
{
File[] result = new File[names.length];
@@ -229,13 +279,17 @@
throw new BuildException(e);
}
- TylarBuilder tb = new ExplodedTylarBuilder(mDestDir);
+ File destDir = mDestDir;
+ if (destDir == null)
+ destDir = mDestFile.getParentFile();
+
+ TylarBuilder tb = new ExplodedTylarBuilder(destDir, mDestFile);
XmlOptions opts = null;
if (mTypeMatcherClass != null)
{
opts = new XmlOptions();
opts.put(Both2Bind.TYPE_MATCHER, mTypeMatcherClass);
- System.out.println("Got matcher class " + mTypeMatcherClass);
+ log("both2Bind using matcher class " + mTypeMatcherClass);
}
BindingFileResult result = Both2Bind.bind(input, opts);
@@ -260,6 +314,16 @@
if (mSrc.size() == 0) {
throw new BuildException("srcdir attribute must be set!",
getLocation());
+ }
+
+ if (mDestDir == null && mDestFile == null)
+ {
+ throw new BuildException("destDir or destFile attribute must be set!");
+ }
+
+ if (mDestDir != null && mDestFile != null)
+ {
+ throw new BuildException("Cannot set both destDir and destFile!", getLocation());
}
if (mDestDir != null && !mDestDir.isDirectory()) {
1.9 +13 -5 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/ExplodedTylarBuilder.java
Index: ExplodedTylarBuilder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/ExplodedTylarBuilder.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ExplodedTylarBuilder.java 12 Dec 2003 01:12:56 -0000 1.8
+++ ExplodedTylarBuilder.java 12 Dec 2003 21:33:13 -0000 1.9
@@ -86,22 +86,30 @@
// Variables
private File mDir;
+ private File mBindingFile;
private List mSchemas = new ArrayList();
private List mBindings = new ArrayList();
// =========================================================================
// Constructors
- public ExplodedTylarBuilder(File dir) {
- if (dir == null) throw new IllegalArgumentException("null dir");
- mDir = dir;
- }
+ public ExplodedTylarBuilder(File dir) {
+ this(dir, null);
+ }
+
+ public ExplodedTylarBuilder(File dir, File bindingFile) {
+ if (dir == null) throw new IllegalArgumentException("null dir");
+ mDir = dir;
+ mBindingFile = bindingFile;
+ }
// =========================================================================
// TylarBuilder implementation
protected void writeBindingFile(BindingFile bf) throws IOException {
- File file = new File(mDir, "binding-file.xml"); //FIXME naming
+ File file = mBindingFile;
+ if (file == null)
+ file = new File(mDir, "binding-config.xml"); //FIXME naming
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
1.3 +0 -1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcher.java
Index: TypeMatcher.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TypeMatcher.java 11 Dec 2003 19:32:54 -0000 1.2
+++ TypeMatcher.java 12 Dec 2003 21:33:13 -0000 1.3
@@ -58,7 +58,6 @@
import org.apache.xmlbeans.impl.jam.JClass;
import org.apache.xmlbeans.impl.jam.JProperty;
-import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.SchemaProperty;
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org