J2EE Metadata Talk
Just finished Simon's talk on JSR 175.
here are my notes
Simon Nash – member of JSR 175 team
(http://www.softwaresummit.com/2003/speakers/nash.htm)
Back ground and motivation
JSR 175 specification
1) Source syntax
2) Processing model
3) Runtime api
4) Class file format
5) Standard annotations
Background – java is imperative not declarative, java has declarations but only for core language constructs. The declaration of ‘the what’ limits the scope for tools to help the developer be more productive.
The annotations are beyond the bounds of the language, instead it fits into the language. Its not about making Java huge to handle every thing, its about making a way for you to extend stuff so that you can declare what in your java classes (i.e. this class is a web-service). The annotation are not part of the program logic but can affect the meaning of the program (i.e. the declaration that the class is a web service might causes WSDL to be generated at deployment time). An annotation will not change the way assignment works or the way that try/catch works.
Semantics of the annotations can be standard or user defined. (I’m assuming that at some point we will see how to use user defined annotations. Just said we’d be getting to that…)
Benefits – productivity, clarity, flexibility, correctness – all the same stuff you get from something like MDA or other model based code generation. I like this but its just not new. Now that its becoming part of the language though it seems that we might be at the cusp of general acceptance of meta-data based programming (i.e. MDA). If you build bad stuff with this it will be bad. Clearly you can build bad stuff with anything, this is no difference.
Q: will AOP make use of this, A: probably, seems a natural fit (the join points should be able to be specified with these annotations).
175 – simple meta-data in source code, attached to program syntactic elements, limited range of type, stored in the class file (available at runtime), can be read at runtime.
Cool example of declaring a web service for a class. Interesting thing to note is that the types of the attributes for annotations is only a limited set (most noteably not Object or any arbitrary subclass, only the types defined in the JSR to be able to be used).
Attributes can be defaulted.
An example of @WebService annotation for a class then adding an @Operation on one of the operations. The @Operation is not explicitly contained in the @WebService.
There are 4 meta-annotations @Target – what can the annotation end up on, @Retention – how far to carry the annotation forward, @Inherited – declares if the annotation should be inherited, @Documented – should this stuff show up in the java doc.
@Retention – runtime, class or source – class is default, runtime makes them available for reflection
Since source is the default retention it seems that the expectation is that post processing on class files will be the norm.
Annotations can be used anywhere that ‘public’ can be used. They are seen as modifiers.
You will be able to annotate your package with a package-info.java file.
Processing Model:
1) Source based
2) Class based
You can integrate your annotation processors with the java compiler? There was a slide about that but it appears that its not ready yet. The way they are thinking is making a plug-in architecture for the compiler. Today what you have to do is post process the class file or process the java code (i.e. you have to parse the java…)
JSR 175 extends the reflection API’s to get at annotations. There is a new thing called AnnotatedElement.
More annotations are changed or defined in JSR’s (181, 207, 224 others as well).