Download and installation.You can download Attrib4j here. . After unzipping the distribution, there will be doc, lib, and src directories.
To use the custom ant task, copy attrib4j.jar and bcel.jar to the lib directory of your Ant installation, $ANT_HOME/lib. Running the examples with AntNow that you have installed Attrib4j, you can run the example programs. To run the examples you should have a copy of the Ant build software (version 1.5.1) installed. A build.xml file is provided for you to quickly compile and run the example. Change to the src/examples directory and run the example by typing 'ant runexample'. The example source code, TransactionExample and InheritedTxExample are located in the directory src/examples/attrib4j/examples. Custom attributes are located in the directory src/examples/attrib4j/examples/attributes. The TransactionExample uses the custom attribute TransactionAttribute. This is a simple custom attribute that takes a single String argument in the constructor. The idea behind this custom attribute is to provide instructions for an application or J2EE container on how this method will participate in transactions. The javadoc tags that refer to this custom attribute are placed at the class level and also at the method level on the method doDatabaseWork. The syntax used to specify the attribute is '@attrib4j.examples.attributes.Transaction("Never")'. Notice how it is not necessary to specify the full classname, attrib4j.examples.attributes.TransactionAttribute. That is because the Attrib4j doclet will automatically append the word 'Attribute' if the class specified can not be found. It is also possible to not specify the fully qualified name (FQN) of the attribute class by passing to the attribute compiler a comma delimeted list of package names where attributes are located. The option name to pass this information is 'attributepackages' and is also exposed in the Ant task. Using this option, the attribute can be specified by typing '@Transaction("Never"); The InheritedTxExample shows how attrib4j supports the inheritance of attributes. The class InheritedTxExample has a method deposit which is also specified in the superclass, AbstractDeposit, which extends the interface DepositTransaction. In each level of the inheritance hierarchy the method deposit has added to it an attribute. In the future there will be more control over inheritance of attribute similar to how it is done in .Net. Run the example by typing 'ant runexample'. It should produce the following output similar to the following. The last lines of the output, runexample:, is where the TransactionExample is run. Buildfile: build.xml prepare: example-attributes: compile: attributeCompile: [attrib4jCompiler] ************************************* [attrib4jCompiler] *Compiling Attributes using Javadoc * [attrib4jCompiler] ************************************* [attrib4jCompiler] Javadoc execution [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\ExampleClass.java... [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\attributes\DebugAttribute.java... [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\attributes\PersistentAttribute.java... [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\attributes\TraceAttribute.java... [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\attributes\TransactionAttribute.java... [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\TransactionExample.java... [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\DepositTransaction.java... [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\AbstractDeposit.java... [attrib4jCompiler] Loading source file C:\mark\opensource\attrib4j\src\examples\ attrib4j\examples\InheritanceTxExample.java... [attrib4jCompiler] Constructing Javadoc information... [attrib4jCompiler] AttributeDoclet:INFO:Found class attribute name = Debug(true) , text = [attrib4jCompiler] AttributeDoclet:INFO:Found class attribute name = attrib4j.ex amples.attributes.Trace("Test",1), text = [attrib4jCompiler] AttributeDoclet:INFO:Found method level attribute name = attr ib4j.examples.attributes.Debug(false), text = [attrib4jCompiler] AttributeDoclet:INFO:Found method level attribute name = attr ib4j.examples.attributes.Debug(true), text = [attrib4jCompiler] AttributeDoclet:INFO:Found class attribute name = Transaction ("Never"), text = [attrib4jCompiler] AttributeDoclet:INFO:Found method level attribute name = attr ib4j.examples.attributes.Transaction("Required"), text = [attrib4jCompiler] AttributeDoclet:INFO:Found method level attribute name = Tran saction("Required"), text = [attrib4jCompiler] AttributeDoclet:INFO:Found method level attribute name = Trac e(1), text = [attrib4jCompiler] AttributeDoclet:INFO:Found method level attribute name = attr ib4j.examples.attributes.Debug(true), text = runexample: [java] Running TransationExamaple [java] Working inside attribute demarcated transaction. [java] Found class level custom TransactionAttribute. Value = Never [java] Found method level custom TransactionAttribute. Value = Required [java] Running InheritanceTxExamaple [java] Working inside attribute demarcated transaction. [java] Found 3 attributes on method deposit(int,long) [java] Debug attribute on deposit(int,long) is true [java] Transaction attribute on deposit(int,long) is Required [java] Trace attribute on deposit(int, long) is 1 BUILD SUCCESSFUL If you see output similar to what is listed above, congratulations! |