You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2004/09/03 02:44:02 UTC
cvs commit: ws-jaxme/src/documentation/content/xdocs site.xml
jochen 2004/09/02 17:44:02
Modified: src/documentation/content/xdocs/js book.xml
src/js/org/apache/ws/jaxme/js/util JavaParser.java
src/documentation/content/xdocs site.xml
Added: src/documentation/content/xdocs/js jparser.xml
Log:
Added docs for the Java parser.
Revision Changes Path
1.3 +1 -0 ws-jaxme/src/documentation/content/xdocs/js/book.xml
Index: book.xml
===================================================================
RCS file: /home/cvs/ws-jaxme/src/documentation/content/xdocs/js/book.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- book.xml 23 Jul 2004 07:18:04 -0000 1.2
+++ book.xml 3 Sep 2004 00:44:02 -0000 1.3
@@ -33,6 +33,7 @@
<menu-item label="Placeholders" href="placeholders.html"/>
<menu-item label="Optimizations" href="optimizations.html"/>
<menu-item label="Writing SQL" href="sql.html"/>
+ <menu-item label="Java Source Reflection" href="jparser.html"/>
</menu>
<menu label="Patterns">
1.1 ws-jaxme/src/documentation/content/xdocs/js/jparser.xml
Index: jparser.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.2//EN" "document-v12.dtd">
<document>
<header><title>Java Source Reflection</title></header>
<body>
<section><title>Why Source Reflection?</title>
<p>Java Source Generation is frequently based on reflection. For example,
the <link href="patterns/proxy.html">Proxy Generator</link> works
roughly like this: Class A is inspected using Java Reflection.
A new class B is created. For any public method in A, a method
in B is created, that invokes A.</p>
<p>This approach has a subtle inconvenience: To use Java reflection,
the class A must have already been compiled. As a consequence, the
use of generated sources typically happens in three stages:</p>
<ol>
<li>Compiling a part of the sources</li>
<li>Invoking the source generator</li>
<li>Compiling the remaining sources</li>
</ol>
<p>This can become rather nasty. In particular, you cannot reference
the second part of the sources from the first part. The build
scripts tend to be overly complex and difficult to maintain.</p>
<p>Java Source Reflection is a true simplification of the above
process: Required informations are gathered from the Java
source files, and not from the compiled classes.</p>
</section>
<section><title>How it works</title>
<p>Java Source Reflection is implemented by the class
<link href="../apidocs/org/apache/ws/jaxme/js/util/JavaParser.html">
JavaParser</link>. This class takes as input a Java source file and
converts it into an instance of
<link href="../apidocs/org/apache/ws/jaxme/js/JavaSource.html">
JavaSource</link>. The Java parser is internally based on an
<link href="ext:antlr">AntLR parser</link>. (AntLR is a public
domain parser generator.)</p>
<p>The created
<link href="../apidocs/org/apache/ws/jaxme/js/JavaSource.html">
JavaSource</link> instance contains instances of
<link href="../apidocs/org/apache/ws/jaxme/js/JavaMethod.html">
JavaMethod</link>,
<link href="../apidocs/org/apache/ws/jaxme/js/JavaField.html">
JavaField</link>,
<link href="../apidocs/org/apache/ws/jaxme/js/JavaInnerClass.html">
JavaInnerClass</link>, and so on. Obviously, these can be used to
replace classical Java reflection.</p>
</section>
<section><title>Using the JavaParser</title>
<p>To use the Java parser, your classpath must obviously contain
the file jaxmejs.jar. However, because the actual parser is
generated by <link href="ext:antlr">AntLR</link>, you need the
file antlr.jar as well. Both files come to you as part of the
JaxMe distribution. Besides, a current version of antlr.jar
(2.7.4, as of this writing) can always be obtained from
<link href="ext:antlr">www.antlr.org</link>. However, if you
replace the AntLR parser, then you should probably use the
JaxMe source distribution, and rebuild the binaries, thus
creating a new parser.</p>
<p>The following sample uses Java source reflection to print
all public non-static methods of a certain Java class:</p>
<source>
import org.apache.ws.jaxme.js.*;
public void printPublicInstanceMethods(File pFile) {
JavaSourceFactory jsf = new JavaSourceFactory();
JavaParser jp = new JavaParser(jsf);
jp.parse(pFile);
for (Iterator iter = jsf.getJavaSources(); iter.hasNext(); ) {
JavaSource js = (JavaSource) iter.next();
System.out.println("Public instance methods of class: " + js.getQName());
JavaMethod[] methods = js.getMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getProtection().equals(JavaSource.PUBLIC) &&
!methods[i].isPublic()) {
System.out.println(" " + methods[i].getName());
}
}
System.out.println(js.getQName());
}
}
</source>
</section>
</body>
</document>
1.3 +0 -14 ws-jaxme/src/js/org/apache/ws/jaxme/js/util/JavaParser.java
Index: JavaParser.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/util/JavaParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaParser.java 29 Aug 2004 02:54:23 -0000 1.2
+++ JavaParser.java 3 Sep 2004 00:44:02 -0000 1.3
@@ -427,18 +427,4 @@
break;
}
}
-
- /** <p>Parses the files given by its arguments.</p>
- */
- public static void main(String[] pArgs) throws Exception {
- JavaSourceFactory jsf = new JavaSourceFactory();
- JavaParser jp = new JavaParser(jsf);
- for (int i = 0; i < pArgs.length; i++) {
- jp.parse(new File(pArgs[i]));
- }
- for (Iterator iter = jsf.getJavaSources(); iter.hasNext(); ) {
- JavaSource js = (JavaSource) iter.next();
- System.out.println(js.getQName());
- }
- }
}
1.20 +3 -0 ws-jaxme/src/documentation/content/xdocs/site.xml
Index: site.xml
===================================================================
RCS file: /home/cvs/ws-jaxme/src/documentation/content/xdocs/site.xml,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- site.xml 20 Aug 2004 23:51:09 -0000 1.19
+++ site.xml 3 Sep 2004 00:44:02 -0000 1.20
@@ -145,6 +145,9 @@
<sag href=""/>
<tamino href="tamino/"/>
</www.softwareag.com>
+ <www.antlr.org href="http://www.antlr.org/">
+ <antlr href=""/>
+ </www.antlr.org>
<www.thecortex.net href="http://www.thecortex.net/">
<clover href="clover/"/>
<cloverkey href="clover/dl.jsp?key=0e65b4c0eea09ff233b124771"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org