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/07/01 02:07:13 UTC
cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile Java2Schema.java
pcal 2004/06/30 17:07:13
Modified: v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc
JavadocClassBuilder.java
v2/jam/src/org/apache/xmlbeans/impl/jam/internal/reflect
ReflectClassBuilder.java
v2/jam/src/org/apache/xmlbeans/impl/jam/provider
JamClassBuilder.java JamServiceFactoryImpl.java
v2/src/binding/org/apache/xmlbeans/impl/binding/compile
Java2Schema.java
Log:
jam: classbuilder cleanup, few more tweaks
Revision Changes Path
1.32 +106 -100 xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java
Index: JavadocClassBuilder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- JavadocClassBuilder.java 28 Jun 2004 23:04:44 -0000 1.31
+++ JavadocClassBuilder.java 1 Jul 2004 00:07:13 -0000 1.32
@@ -21,7 +21,6 @@
import org.apache.xmlbeans.impl.jam.internal.JamServiceContextImpl;
import org.apache.xmlbeans.impl.jam.provider.JamClassBuilder;
import org.apache.xmlbeans.impl.jam.provider.JamServiceContext;
-import org.apache.xmlbeans.impl.jam.provider.JamLogger;
import org.apache.xmlbeans.impl.jam.provider.JamClassPopulator;
import org.apache.xmlbeans.impl.jam.annotation.JavadocTagParser;
@@ -48,119 +47,29 @@
// Variables
private RootDoc mRootDoc = null;
- private JamServiceContext mServiceContext;
- private JamLogger mLogger;
private Javadoc15Delegate mDelegate = null;
private JavadocTagParser mTagParser = null;
-
private boolean mParseTags = true;//FIXME
-
-
// ========================================================================
// Constructors
- public JavadocClassBuilder(JamServiceContext ctx) {
- if (ctx == null) throw new IllegalArgumentException("null context");
- mServiceContext = ctx;
- mLogger = ctx.getLogger();
- mTagParser = ctx.getTagParser();
- String pct = ctx.getProperty(PARSETAGS_PROPERTY);
- if (pct != null) {
- mParseTags = Boolean.valueOf(pct).booleanValue();
- mLogger.verbose("mParseTags="+mParseTags,this);
- }
- try {
- // See if we can load a 1.5-specific class. If we can't, don't use
- // the Javadoc15Delegate.
- Class.forName("com.sun.javadoc.AnnotationDesc");
- } catch (ClassNotFoundException e) {
- issue14RuntimeWarning(e,mLogger);
- return;
- }
- // ok, if we could load that, let's new up the extractor delegate
- try {
- mDelegate = (Javadoc15Delegate)
- Class.forName(JAVA15_EXTRACTOR).newInstance();
- // if this fails for any reason, things are in a bad state
- } catch (ClassNotFoundException e) {
- issue14BuildWarning(e,mLogger);
- } catch (IllegalAccessException e) {
- issue14BuildWarning(e,mLogger);
- } catch (InstantiationException e) {
- issue14BuildWarning(e,mLogger);
- }
- }
+ public JavadocClassBuilder() {}
// ========================================================================
// JamClassBuilder implementation
public void init(ElementContext ctx) {
+ if (ctx == null) throw new IllegalArgumentException("null context");
super.init(ctx);
- if (mDelegate != null) mDelegate.init(ctx);
- mServiceContext.getLogger().verbose("init()",this);
- File[] files;
- try {
- files = mServiceContext.getSourceFiles();
- } catch(IOException ioe) {
- mLogger.error(ioe);
- return;
-
- }
- if (files == null || files.length == 0) {
- throw new IllegalArgumentException("No source files in context.");
- }
- String sourcePath = (mServiceContext.getInputSourcepath() == null) ? null :
- mServiceContext.getInputSourcepath().toString();
- String classPath = (mServiceContext.getInputClasspath() == null) ? null :
- mServiceContext.getInputClasspath().toString();
- if (mLogger.isVerbose(this)) {
- mLogger.verbose("sourcePath ="+sourcePath);
- mLogger.verbose("classPath ="+classPath);
- for(int i=0; i<files.length; i++) {
- mLogger.verbose("including '"+files[i]+"'");
- }
- }
- JavadocRunner jdr = new JavadocRunner();
- try {
- PrintWriter out = null;
- if (mLogger.isVerbose(this)) {
- out = new PrintWriter(System.out);
- }
- mRootDoc = jdr.run(files,
- out,
- sourcePath,
- classPath,
- getJavadocArgs(mServiceContext),
- mLogger);
- if (mRootDoc == null) {
- mLogger.error("Javadoc returned a null root");//FIXME error
- } else {
- if (mLogger.isVerbose(this)) {
- mLogger.verbose(" received "+mRootDoc.classes().length+
- " ClassDocs from javadoc: ");
- }
- ClassDoc[] classes = mRootDoc.classes();
- // go through and explicitly add all of the class names. we need to
- // do this in case they passed any 'unstructured' classes. to the
- // params. this could use a little TLC.
- for(int i=0; i<classes.length; i++) {
- if (classes[i].containingClass() != null) continue; // skip inners
- if (mLogger.isVerbose(this)) {
- mLogger.verbose("..."+classes[i].qualifiedName());
- }
- ((JamServiceContextImpl)mServiceContext).
- includeClass(getFdFor(classes[i]));
- }
- }
- } catch (FileNotFoundException e) {
- mLogger.error(e);
- } catch (IOException e) {
- mLogger.error(e);
- }
+ getLogger().verbose("init()",this);
+ initDelegate(ctx);
+ initJavadoc((JamServiceContext)ctx); //dirty cast because we're 'built in'
}
+
public MClass build(String packageName, String className) {
+ assertInitialized();
if (getLogger().isVerbose(this)) {
getLogger().verbose("trying to build '"+packageName+"' '"+className+"'");
}
@@ -208,6 +117,7 @@
public void populate(MClass dest) {
if (dest == null) throw new IllegalArgumentException("null dest");
+ assertInitialized();
ClassDoc src = (ClassDoc)dest.getArtifact();
if (src == null) throw new IllegalStateException("null artifact");
dest.setModifiers(src.modifierSpecifier());
@@ -247,6 +157,102 @@
}
}
+ // ========================================================================
+ // Private methods
+
+ private void initDelegate(ElementContext ctx) {
+ try {
+ // See if we can load a 1.5-specific class. If we can't, don't use
+ // the Javadoc15Delegate.
+ Class.forName("com.sun.javadoc.AnnotationDesc");
+ } catch (ClassNotFoundException e) {
+ issue14RuntimeWarning(e);
+ return;
+ }
+ // ok, if we could load that, let's new up the extractor delegate
+ try {
+ mDelegate = (Javadoc15Delegate)
+ Class.forName(JAVA15_EXTRACTOR).newInstance();
+ mDelegate.init(ctx);
+ // if this fails for any reason, things are in a bad state
+ } catch (ClassNotFoundException e) {
+ issue14BuildWarning(e);
+ } catch (IllegalAccessException e) {
+ issue14BuildWarning(e);
+ } catch (InstantiationException e) {
+ issue14BuildWarning(e);
+ }
+ }
+
+ private void initJavadoc(JamServiceContext serviceContext) {
+ // grab some useful stuff
+ mTagParser = serviceContext.getTagParser();
+ String pct = serviceContext.getProperty(PARSETAGS_PROPERTY);
+ if (pct != null) {
+ mParseTags = Boolean.valueOf(pct).booleanValue();
+ getLogger().verbose("mParseTags="+mParseTags,this);
+ }
+ // now go run javadoc on the appropriate files
+ File[] files;
+ try {
+ files = serviceContext.getSourceFiles();
+ } catch(IOException ioe) {
+ getLogger().error(ioe);
+ return;
+ }
+ if (files == null || files.length == 0) {
+ throw new IllegalArgumentException("No source files in context.");
+ }
+ String sourcePath = (serviceContext.getInputSourcepath() == null) ? null :
+ serviceContext.getInputSourcepath().toString();
+ String classPath = (serviceContext.getInputClasspath() == null) ? null :
+ serviceContext.getInputClasspath().toString();
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("sourcePath ="+sourcePath);
+ getLogger().verbose("classPath ="+classPath);
+ for(int i=0; i<files.length; i++) {
+ getLogger().verbose("including '"+files[i]+"'");
+ }
+ }
+ JavadocRunner jdr = new JavadocRunner();
+ try {
+ PrintWriter out = null;
+ if (getLogger().isVerbose(this)) {
+ out = new PrintWriter(System.out);
+ }
+ mRootDoc = jdr.run(files,
+ out,
+ sourcePath,
+ classPath,
+ getJavadocArgs(serviceContext),
+ getLogger());
+ if (mRootDoc == null) {
+ getLogger().error("Javadoc returned a null root");//FIXME error
+ } else {
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose(" received "+mRootDoc.classes().length+
+ " ClassDocs from javadoc: ");
+ }
+ ClassDoc[] classes = mRootDoc.classes();
+ // go through and explicitly add all of the class names. we need to
+ // do this in case they passed any 'unstructured' classes. to the
+ // params. this could use a little TLC.
+ for(int i=0; i<classes.length; i++) {
+ if (classes[i].containingClass() != null) continue; // skip inners
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("..."+classes[i].qualifiedName());
+ }
+ ((JamServiceContextImpl)serviceContext).
+ includeClass(getFdFor(classes[i]));
+ }
+ }
+ } catch (FileNotFoundException e) {
+ getLogger().error(e);
+ } catch (IOException e) {
+ getLogger().error(e);
+ }
+ }
+
private void populate(MField dest, FieldDoc src) {
dest.setArtifact(src);
dest.setSimpleName(src.name());
@@ -303,8 +309,8 @@
// mLogger.verbose("processing "+tags.length+" javadoc tags on "+dest);
//}
for(int i=0; i<tags.length; i++) {
- if (mLogger.isVerbose(this)) {
- mLogger.verbose("...'"+tags[i].name()+"' ' "+tags[i].text());
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("...'"+tags[i].name()+"' ' "+tags[i].text());
}
//note name() returns the '@', so we strip it here
mTagParser.parse(dest,tags[i]);
1.18 +37 -36 xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/reflect/ReflectClassBuilder.java
Index: ReflectClassBuilder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/reflect/ReflectClassBuilder.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ReflectClassBuilder.java 28 Jun 2004 23:15:09 -0000 1.17
+++ ReflectClassBuilder.java 1 Jul 2004 00:07:13 -0000 1.18
@@ -16,8 +16,6 @@
import org.apache.xmlbeans.impl.jam.mutable.*;
import org.apache.xmlbeans.impl.jam.provider.JamClassBuilder;
-import org.apache.xmlbeans.impl.jam.provider.JamServiceContext;
-import org.apache.xmlbeans.impl.jam.provider.JamLogger;
import org.apache.xmlbeans.impl.jam.provider.JamClassPopulator;
import org.apache.xmlbeans.impl.jam.internal.elements.ElementContext;
@@ -38,55 +36,29 @@
"org.apache.xmlbeans.impl.jam.internal.java15.Reflect15DelegateImpl";
// ========================================================================
- // Public static utilities
-
- public static JamClassBuilder getSystemClassBuilder(JamServiceContext ctx) {
- return new ReflectClassBuilder(ClassLoader.getSystemClassLoader(),ctx);
- }
-
- // ========================================================================
// Variables
private ClassLoader mLoader;
private Reflect15Delegate mDelegate = null;
- private JamLogger mLogger = null;
// ========================================================================
// Constructors
- public ReflectClassBuilder(ClassLoader rcl, JamServiceContext ctx) {
+ public ReflectClassBuilder(ClassLoader rcl) {
if (rcl == null) throw new IllegalArgumentException("null rcl");
- if (ctx == null) throw new IllegalArgumentException("null ctx");
- mLogger = ctx;
mLoader = rcl;
- try {
- // class for name this because it's 1.5 specific. if it fails, we
- // don't want to use the extractor
- Class.forName("java.lang.annotation.Annotation");
- } catch (ClassNotFoundException e) {
- issue14RuntimeWarning(e,mLogger);
- return;
- }
- // ok, if we could load that, let's new up the extractor delegate
- try {
- mDelegate = (Reflect15Delegate)
- Class.forName(JAVA15_DELEGATE).newInstance();
- mDelegate.init((ElementContext)ctx);
- // if this fails for any reason, things are in a bad state
- } catch (ClassNotFoundException e) {
- issue14BuildWarning(e,mLogger);
- } catch (IllegalAccessException e) {
- issue14BuildWarning(e,mLogger);
- } catch (InstantiationException e) {
- issue14BuildWarning(e,mLogger);
- }
}
// ========================================================================
// JamClassBuilder implementation
- public MClass build(String packageName, String className)
- {
+ public void init(ElementContext ctx) {
+ super.init(ctx);
+ initDelegate(ctx);
+ }
+
+ public MClass build(String packageName, String className) {
+ assertInitialized();
if (getLogger().isVerbose(this)) {
getLogger().verbose("trying to build '"+packageName+"' '"+className+"'");
}
@@ -109,6 +81,7 @@
// JamClassPopulator implementation
public void populate(MClass dest) {
+ assertInitialized();
Class src = (Class)dest.getArtifact();
dest.setModifiers(src.getModifiers());
dest.setIsInterface(src.isInterface());
@@ -160,6 +133,34 @@
inner.setArtifact(inners[i]);
populate(inner);
}
+ }
+ }
+
+
+ // ========================================================================
+ // Private methods
+
+ private void initDelegate(ElementContext ctx) {
+ try {
+ // class for name this because it's 1.5 specific. if it fails, we
+ // don't want to use the extractor
+ Class.forName("java.lang.annotation.Annotation");
+ } catch (ClassNotFoundException e) {
+ issue14RuntimeWarning(e);
+ return;
+ }
+ // ok, if we could load that, let's new up the extractor delegate
+ try {
+ mDelegate = (Reflect15Delegate)
+ Class.forName(JAVA15_DELEGATE).newInstance();
+ mDelegate.init((ElementContext)ctx);
+ // if this fails for any reason, things are in a bad state
+ } catch (ClassNotFoundException e) {
+ issue14BuildWarning(e);
+ } catch (IllegalAccessException e) {
+ issue14BuildWarning(e);
+ } catch (InstantiationException e) {
+ issue14BuildWarning(e);
}
}
1.14 +60 -36 xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/provider/JamClassBuilder.java
Index: JamClassBuilder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/provider/JamClassBuilder.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JamClassBuilder.java 28 Jun 2004 23:50:00 -0000 1.13
+++ JamClassBuilder.java 1 Jul 2004 00:07:13 -0000 1.14
@@ -37,6 +37,13 @@
// ========================================================================
// Public methods
+ /**
+ * This method is called by JAM to initialize this class builder. Extending
+ * classes can override this to perform additional initialization work
+ * (just remember to call super.init()!).
+ *
+ * @param ctx
+ */
public void init(ElementContext ctx) {
if (mContext != null) {
throw new IllegalStateException("init called more than once");
@@ -45,6 +52,28 @@
mContext = ctx;
}
+
+ // ========================================================================
+ // Abstract methods
+
+ /**
+ * <p>This is called by JAM when it attempts to load a class. If the
+ * builder has access to an artifact (typically a java source or classfile)
+ * that represents the given type, it should call createClassToBuild() to get
+ * a new instance of MClass and then return it. No caching should be
+ * performed - if an MClass is going to be returned, it should be a new
+ * instance returned by createClassToBuild()</p>
+ *
+ * <p>If no artififact is available, the builder should just return null,
+ * signalling that other JamClassBuilders should attempt to build the
+ * class.</p>
+ *
+ * @param packageName
+ * @param className
+ * @return
+ */
+ public abstract MClass build(String packageName, String className);
+
// ========================================================================
// Protected methods
@@ -70,6 +99,7 @@
if (packageName == null) throw new IllegalArgumentException("null pkg");
if (className == null) throw new IllegalArgumentException("null class");
if (pop == null) throw new IllegalArgumentException("null pop");
+ assertInitialized();
className = className.replace('.','$');
ClassImpl out = new ClassImpl(packageName,className,mContext,importSpecs,pop);
return out;
@@ -95,58 +125,52 @@
if (mContext == null) throw new IllegalStateException("init not called");
if (packageName == null) throw new IllegalArgumentException("null pkg");
if (className == null) throw new IllegalArgumentException("null class");
+ assertInitialized();
className = className.replace('.','$');
ClassImpl out = new ClassImpl(packageName,className,mContext,importSpecs);
return out;
}
- protected JamLogger getLogger() {
- if (mContext == null) throw new IllegalStateException("init not called");
- return mContext;
- }
+ protected JamLogger getLogger() { return mContext; }
- // ========================================================================
- // Abstract methods
-
- /**
- * <p>This is called by JAM when it attempts to load a class. If the
- * builder has access to an artifact (typically a java source or classfile)
- * that represents the given type, it should call createClassToBuild() to get
- * a new instance of MClass and then return it. No caching should be
- * performed - if an MClass is going to be returned, it should be a new
- * instance returned by createClassToBuild()</p>
- *
- * <p>If no artififact is available, the builder should just return null,
- * signalling that other JamClassBuilders should attempt to build the
- * class.</p>
- *
- * @param packageName
- * @param className
- * @return
- */
- public abstract MClass build(String packageName, String className);
- // ========================================================================
- // Protected methods
+ /**
+ * Asserts that init() has been called on this class builder.
+ */
+ protected final void assertInitialized() {
+ if (mContext == null) {
+ throw new IllegalStateException(this+" not yet initialized.");
+ }
+ }
- protected void issue14BuildWarning(Throwable t, JamLogger logger) {
- if (!mWarningAlreadyIssued && logger != null) {
- logger.warning("This build of JAM was produced under JDK 1.4." +
- "Even though you are running under JDK 1.5, "+
+ /**
+ * Displays a warning indicating that the current build of JAM was
+ * done under 1.4 (or earlier), which precludes the use of 1.5-specific
+ * features.
+ */
+ protected void issue14BuildWarning(Throwable t) {
+ assertInitialized();
+ if (!mWarningAlreadyIssued && mContext != null) {
+ mContext.warning("This build of JAM was not with JDK 1.5." +
+ "Even though you are now running under JDK 1.5, "+
"JSR175-style annotations will not be available");
- if (logger.isVerbose(this)) logger.verbose(t);
+ if (mContext.isVerbose(this)) mContext.verbose(t);
mWarningAlreadyIssued = true;
}
}
- protected void issue14RuntimeWarning(Throwable t, JamLogger logger) {
- if (!mWarningAlreadyIssued && logger != null) {
- logger.warning("You are running under a pre-1.5 JDK. JSR175-style "+
+ /**
+ * Displays a warning indicating that JAM is running under 1.4 (or earlier),
+ * which precludes the use of 1.5-specific features.
+ */
+ protected void issue14RuntimeWarning(Throwable t) {
+ assertInitialized();
+ if (!mWarningAlreadyIssued && mContext != null) {
+ mContext.warning("You are running under a pre-1.5 JDK. JSR175-style "+
"source annotations will not be available");
- if (logger.isVerbose(this)) logger.verbose(t);
+ if (mContext.isVerbose(this)) mContext.verbose(t);
mWarningAlreadyIssued = true;
}
}
-
}
1.10 +3 -4 xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/provider/JamServiceFactoryImpl.java
Index: JamServiceFactoryImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/provider/JamServiceFactoryImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- JamServiceFactoryImpl.java 15 Apr 2004 01:50:06 -0000 1.9
+++ JamServiceFactoryImpl.java 1 Jul 2004 00:07:13 -0000 1.10
@@ -169,7 +169,7 @@
if (log.isVerbose(this)) {
log.verbose("added classbuilder for classloader "+cls[i].getClass());
}
- builders.add(new ReflectClassBuilder(cls[i],ctx));
+ builders.add(new ReflectClassBuilder(cls[i]));
}
JamClassBuilder[] barray = new JamClassBuilder[builders.size()];
builders.toArray(barray);
@@ -177,7 +177,6 @@
out.init((ElementContext)ctx);
if (log.isVerbose(this)) {
log.verbose("returning a composite of "+barray.length+" class builders.");
-
JClass c = out.build("java.lang","Object");
c = out.build("javax.ejb","SessionBean");
}
@@ -202,7 +201,7 @@
return null;
}
if(ctx.getProperty(USE_NEW_PARSER) == null) {
- return new JavadocClassBuilder(ctx);
+ return new JavadocClassBuilder();
} else {
return new ParserClassBuilder(ctx);
}
@@ -225,7 +224,7 @@
} else {
URL[] urls = cp.toUrlPath();
ClassLoader cl = new URLClassLoader(urls);
- return new ReflectClassBuilder(cl,jp);
+ return new ReflectClassBuilder(cl);
}
}
1.57 +2 -3 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.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- Java2Schema.java 30 Jun 2004 17:36:06 -0000 1.56
+++ Java2Schema.java 1 Jul 2004 00:07:13 -0000 1.57
@@ -109,7 +109,6 @@
if (classesToBind == null) {
throw new IllegalArgumentException("null classes");
}
-/*
for(int i=0; i<classesToBind.length; i++) {
if (classesToBind[i].isUnresolvedType()) {
throw new IllegalArgumentException
@@ -119,9 +118,9 @@
}
}
if (classesToBind.length == 0) {
- throw new IllegalArgumentException("No input classes found.");
+ System.out.println("WARNING! No input classes found!!");
+ //throw new IllegalArgumentException("No input classes found.");
}
- */
mClasses = classesToBind;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org