IntroductionUntil JDK1.5 there will not be any built-in JDK support for compiling attributes into java .class files. The developer thus needs to associate metadata with the java classes via some other mechanism. The easiest mechanism is to post-process the java source files and extract the JavaDocs as metadata. MetaClass has a custom Ant task to do this for the developer. The JavaDoc FormatThe MetaClass Attributes compiler accepts javadocs in standard format. As discussed in the Attribute Model document, attributes in MetaClass can either have parameters or string content. For the MetaClass compiler to recognize a javadoc tag as an attribute with parameters then the JavaDoc tag must be formatted according to the following rules.
If a JavaDoc tag does not satisfy the above rules then it is treated like an Attribute that contains text content. The following are all JavaDoc tags that produce attributes with parameters. /** * @phoenix:entry key="mBeanServer" type="javax.management.MBeanServer" * @shuriken_component ref.id="1234" * @dna.service type="MyService" * @dna.service type="MyService" * doc:displayString="Service Required to do Magic" */ The following JavaDoc tags that produce attributes with value as they dont match the pattern. /** * @phoenix:entry key="Missing ending talky mark * * Next tag has space between key and '=' sign * @shuriken_component ref.id ="1234" * * @param myParam MyParameter used for X */ Ant TaskTo use the ant task the user has to make sure that the metaclass and qdox jars are present and included when defining the Ant task. The following gives an example usage of the generator class. The task will scan all the source files in the directory src/java and generate binary descriptors for each source file in target/classes <!-- define the custom task --> <taskdef name="metaclassGen" classname="org.realityforge.metaclass.tools.tasks.GenerateClassDescriptorsTask"> <classpath> <pathelement location="spice-metaclass-1.0.jar"/> <pathelement location="qdox-1.1.jar"/> </classpath> </taskdef> <metaclassGen destDir="target/classes" namespaceTagsOnly="false"> <fileset dir="src/java"/> </metaclassGen> |