206 APPENDIX LICENSING, INSTALLATION, AND PARTICIPATION Figure A-6. The documentation license agreement Caution When I installed the javadoc, the install complete window would hide in the background and not come to the foreground. I had to hunt it out to click OK to end the installation process.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
APPENDIX LICENSING, INSTALLATION, AND PARTICIPATION 205 Once everything is done, you ll see a screen telling you that the installation is complete (shown in Figure A-5). You can then choose whether to see the README file or not. If you do, the README file is then displayed in a browser window. It has taken some time, but it now finally shows something relevant to Java 6. For the longest time, only Java 5 information was shown in the README. As is expected for prerelease software, some of the links sometimes didn t work (for example, the link to the installation instructions). I guess the links point to where things will be when Mustang is released the joys of prerelease software. Figure A-5. Installation complete In addition to getting the JDK, it is best to also get the javadocs. These come down in an installable JAR file. On the Binary Snapshot Releases web page (http://download.java. net/jdk6/binaries), just follow the first link on the second line, which reads Java Docs (XX MB JAR / HTML) (XX stands for the size of the JAR file). Downloading and unzipping/unjarring the documentation is surprisingly not what you do. Instead, after downloading the file, you run it with the java -jar jarfilename command, replacing jarfilename with the name of the downloaded JAR file. This requires you to accept another license agreement (shown in Figure A-6) before choosing an installation directory. Personally, I tend to enter the same directory as the JDK installation. The documentation will then go into a docs subdirectory. Once installed, you should then bookmark the top-level javadoc page. Installation takes some time.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
204 APPENDIX LICENSING, INSTALLATION, AND PARTICIPATION Figure A-3. The Custom Setup screen for Mustang installation Figure A-4. Installation progress status Note Installation of the public JRE will display even more screenshots and an additional license that requires acceptance.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services
202 APPENDIX LICENSING, INSTALLATION, AND PARTICIPATION Sun has been reluctant to release the core Java release as open source. While Apache Harmony (http://incubator.apache.org/harmony) incubates along as an open source J2SE 5.0 implementation, you can t get the source for the core system of Mustang unless you re in an unrestricted country and you agree to the Java Research License (JRL). Iran, North Korea, and Cuba: no. United States, Canada, France, and England: yes. (That is not a complete list in either case.) It appears that Sun doesn t require you to follow their Sun Community Source License (SCSL) for research related to java.net projects. The SCSL is Sun s attempt to open up source somewhat, but not totally. It is geared toward the commercial community and allows that community to offer proprietary modifications and extensions to a particular area, while maintaining compatibility through technology compatibility kits (TCKs). You can get a more complete overview of the license at www.sun.com/software/communitysource/overview.xml. On the other hand, the JRL is geared more toward internal non-production research and development uses. If or when the project turns into something that is distributed, either internally or externally, you then must sign something called the Java Distribution License, which requires its own level of compatibility requirements. While the SCSL does offer a research section, the JRL is geared more toward the research community and universities. For more information on it, see www.java.net/jrl.csp. Getting the Software While JSR 270 describes Mustang (see http://jcp.org/en/jsr/detail?id=270), access to the software comes from the previously mentioned snapshot area. Starting at https://mustang.dev.java.net and following the Latest Mustang binary snapshots link takes you to the weekly binary snapshot drops. You ll find versions for the Microsoft Windows platform, Windows AMD64, Solaris SPARC, Solaris x86, Solaris AMD64, Linux, and Linux AMD64. Macintosh users will need to wait for Apple to release a version. It is best to get the complete self-extracting JDK file for your platform; though if you re only interested in the Java Runtime Environment (JRE), it s available as a JAR file (a self-extracting DEBUG JAR file is also available). Downloading and running the file displays a splash screen (see Figure A-1). Then you get to agree to the prerelease software evaluation agreement (shown in Figure A-2).
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services
APPENDIX LICENSING, INSTALLATION, AND PARTICIPATION 203 Figure A-1. The splash screen for Mustang installation Figure A-2. The license agreement After accepting the terms of the agreement, you ll see the Custom Setup screen (shown in Figure A-3). By default, everything gets installed into C:Program FilesJava jdk1.6.0 (on a Windows platform). You can change this directory or choose not to install the demos, source code, or public JRE. You must install the development tools. Clicking Next starts the installation, after which you can monitor the progress (as shown in Figure A-4).
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services
200 CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES Now compile this with the -processor option to javac: > javac -processor Dump6Processor Dump6Processor.java javax.annotation.processing.SupportedSourceVersion(TOP_LEVEL) javax.annotation.processing.SupportedAnnotationTypes(TOP_LEVEL) warning: No annotation processors claimed present annotation types: [javax.annotation.processing.SupportedSourceVersion, javax.annotation.processing.SupportedAnnotationTypes] Note The javac command-line tool is getting more like java in Java SE 6.0 through the addition of command-line options. In fact, some are even nonstandard. Try out the -Xprint option with javac to get information similar to what you get from javap and -XprintRounds or -XprintProcessorInfo to monitor processing tasks. Options like -Xmaxerrs and -Xmaxwarns (which limit the maximum number of errors and warnings, respectively) are not new to Java SE 6.0. The processingOver() check in process() is necessary, as a processor could be called multiple times in one javac execution. More typically, a processor would actually do something with the annotation, such as generate a file. As far as generating the file, the old AnnotationProcessorEnvironment interface of the com.sun.mirror.apt package is now the new ProcessingEnvironment interface of the javax.annotation.processing package. In both cases, you get a Filer to hold the generated output. Writer out = env.getFiler().createTextFile( Filer.Location.SOURCE_TREE, package, path, charset) Summary Most people aren t going to create their own annotation processors. They re more apt to use annotations created by others, like for JDBC queries. If you only use them, you don t need to know anything in this chapter. If you need to process annotations, however, you need to know how the processing model has changed from J2SE 5.0 to Java SE 6.0. It s not that different just slightly with classes moving between packages and slightly different interfaces. Use them with care, and don t go overboard. Defining your own annotations really has not changed from J2SE 5.0. Appendix A wraps up the book with information about acquiring the weekly releases.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
Licensing, Installation, and Participation APPENDIX Just when is the right time to release software to the masses? With Mustang, the masses have had access since February 2005. With roughly weekly releases since then, one was able to monitor the progress of both the API development and the completion of the new feature sets for what would become known as Java SE 6. Note The information in this chapter is valid as of spring 2006. When Mustang moved into beta release, locations didn t move, but they are apt to move later, and it is unknown how much information will be left behind on the original java.net site after Java SE 6 is released. Snapshot Releases The home for early Mustang access has been the java.net portal. Powered by CollabNet and co-run by Sun and O Reilly, developers can visit https://mustang.dev.java.net and download the latest early access release of Mustang. With a separate download, you can also download the javadoc for the core classes. And, if you agree to the necessary licensing terms, you can also download the complete source snapshots for all of Mustang not just the java and javax packages, but the sun packages, too. With the last download, instructions are provided to compile the full system and build everything yourself. Licensing Terms First off, let me state that I am not a lawyer, and what I say cannot be construed as legal advice; this is just my understanding of Sun s licensing terms. As far as licensing goes,
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES 199 Beyond the annotations, all the processor does is loop through each annotation and print its name and nesting kind (level of declaration). More typically, if the annotation was something to be processed, you would use the accept() method on the TypeElement and visit it. Listing 10-7. Java SE 6.0 Annotation Processor import javax.annotation.processing.*; import javax.lang.model.*; import javax.lang.model.element.*; import java.util.*; // Source version @SupportedSourceVersion(SourceVersion.RELEASE_6) // Process all annotations @SupportedAnnotationTypes(”*”) // No options support // Empty set when not annotated with @SupportedOptions public class Dump6Processor extends AbstractProcessor { public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.processingOver()) { for (TypeElement element : annotations) { System.out.println(element.getQualifiedName() + “(” + element.getNestingKind() + “)”); } } return false; // No annotations claimed } } Again, compilation requires the tools.jar file, as follows: javac -cp c:jdk1.6.0libtools.jar Dump6Processor.java
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES 197 DumpProcessor(AnnotationProcessorEnvironment env) { this.env = env; } public void process() { for (TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations()) { typeDecl.accept(getDeclarationScanner(new DumpVisitor(), NO_OP)); } } private static class DumpVisitor extends SimpleDeclarationVisitor { public void visitMethodDeclaration(MethodDeclaration d) { System.out.println(”t” + d.getSimpleName()); } public void visitClassDeclaration(ClassDeclaration d) { System.out.println(d.getQualifiedName()); } public void visitInterfaceDeclaration(InterfaceDeclaration d) { System.out.println(d.getQualifiedName()); } } } } Defining the class is the easy part. Compiling it is just step one, and you can t just use javac alone (yet). As previously mentioned, you need to include tools.jar in your class- path to compile an annotation. javac -cp c:jdk1.6.0libtools.jar DumpFactory.java Note At least for now, you have to manually include tools.jar in your classpath to compile annotation processors. It is possible that by the time Java SE 6 ships, that could change. Running of the annotation is not done with the java command. This is where apt comes into play. But before you can use apt, you have to package up the factory and processor into a JAR file and install it, like other items that use the service API. Typically, this is done by creating a file in META-INF/services named com.sun.mirror.apt. AnnotationProcessorFactory to point to the processor just defined. However, to avoid this step, you can include extra command-line options to the apt command. And, for a little test, just run the processor on itself.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services
198 CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES > apt -cp c:jdk1.6.0libtools.jar;. -factory DumpFactory DumpFactory.java DumpFactory supportedAnnotationTypes supportedOptions getProcessorFor DumpFactory.DumpProcessor process DumpFactory.DumpProcessor.DumpVisitor visitMethodDeclaration visitClassDeclaration visitInterfaceDeclaration Those are the basics of processing annotations with JDK 5.0. Java SE 6.0 Processing Moving to the Java SE 6.0 world changes a few things. The primary difference is the moving of the annotation processing library into a more standard javax package and doing away with the factory. Secondly, the javac command-line tool now offers a -processor option to run a previously created processor. The removal of the factory is actually an interesting twist and makes total sense. All the factory did was return a single processor. So now the AbstractProcessor class forms the basis of all processors and really just is the processor unlike with 5.0, in which you had to create an extra class. Ignoring the imports and a few other things, your basic processor definition is shown here: public class Dump6Processor extends AbstractProcessor { public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) { return false; // No annotations claimed } } To demonstrate, Listing 10-7 creates a processor that lists the annotations in the classes specified. This is where new the annotations of the javax.annotation.processing package are used: SupportedSourceVersion, SupportedAnnotationTypes, and SupportedOptions. The source version is specified by one of the constants of the SourceVersion enumeration of the java.lang.model package. The SupportedAnnotationTypes annotation is just like the supportedAnnotationTypes() method of the JDK 5.0 processor factory, and the SupportedOptions annotation mirrors supportedOptions(). When not specified, it defaults to returning an empty set.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services