:toc:
toc::[]
= Java Plug-in
The CobiGen Java Plug-in comes with a new input reader for java artifacts, new java related trigger and matchers, as well as a merging mechanism for Java sources.
== Trigger extension
The Java Plug-in provides a new trigger for Java related inputs. It accepts different representations as inputs (see xref:java-input-reader[Java input reader]) and provides additional matching and variable assignment mechanisms. The configuration in the `context.xml` for this trigger looks like this:
* type 'java'
+
.Example of a java trigger definition
[source,xml]
----
...
----
+
This trigger type enables Java elements as inputs.
=== Matcher types
With the trigger you might define matchers, which restrict the input upon specific aspects:
* type `fqn` -> full qualified name matching
+
.Example of a java trigger definition with a full qualified name matcher
[source,xml]
----
...
----
+
This trigger will be enabled if the full qualified name (`fqn`) of the declaring input class matches the given regular expression (`value`).
* type 'package' -> package name of the input
+
.Example of a java trigger definition with a package name matcher
[source,xml]
----
...
----
+
This trigger will be enabled if the package name (`package`) of the declaring input class matches the given regular expression (`value`).
* type 'expression'
+
.Example of a java trigger definition with a package name matcher
[source,xml]
----
...
----
+
This trigger will be enabled if the expression evaluates to true. Valid expressions are
* `instanceof fqn`: checks an 'is a' relation of the input type
* `isAbstract`: checks, whether the input type is declared abstract
=== Container Matcher types
Additionally, the java plugin provides the ability to match packages (containers) as follows:
* type 'package'
+
.Example of a java trigger definition with a container matcher for packages
[source,xml]
----
----
+
The container matcher matches packages provided by the type `com.capgemini.cobigen.javaplugin.inputreader.to.PackageFolder` with a regular expression stated in the `value` attribute. (See link:cobigen-core_configuration#containermatcher-node[`containerMatcher` semantics] to get more information about `containerMatchers` itself.)
=== Variable Assignment types
Furthermore, it provides the ability to extract information from each input for further processing in the templates. The values assigned by variable assignments will be made available in template and the `destinationPath` of `context.xml` through the namespace `variables.`. The Java Plug-in currently provides two different mechanisms:
* type 'regex' -> regular expression group
+
[source,xml]
----
----
This variable assignment assigns the value of the given regular expression group number to the given `key`.
* type 'constant' -> constant parameter
+
[source,xml]
----
----
This variable assignment assigns the `value` to the `key` as a constant.
=== Java input reader
The CobiGen Java Plug-in implements an input reader for parsed java sources as well as for java `Class>` objects (loaded by reflection). So API user can pass `Class>` objects as well as `JavaClass` objects for generation. The latter depends on https://github.com/paul-hammant/qdox[QDox], which will be used for parsing and merging java sources. For getting the right parsed java inputs you can easily use the `JavaParserUtil`, which provides static functionality to parse java files and get the appropriate `JavaClass` object.
Furthermore, due to restrictions on both inputs according to model building (see below), it is also possible to provide an array of length two as an input, which contains the `Class>` as well as the `JavaClass` object of the same class.
==== Template object model
No matter whether you use reflection objects or parsed java classes as input, you will get the following object model for template creation:
* *`classObject`* ('Class' :: Class object of the Java input)
* *POJO*
** *name* ('String' :: Simple name of the input class)
** *package* ('String' :: Package name of the input class)
** *`canonicalName`* ('String' :: Full qualified name of the input class)
** *annotations* ('Map' :: Annotations, which will be represented by a mapping of the full qualified type of an annotation to its value. To gain template compatibility, the key will be stored with '_' instead of '.' in the full qualified annotation type. Furthermore, the annotation might be recursively defined and thus be accessed using the same type of mapping. Example `${pojo.annotations.javax_persistence_Id}`)
** *JavaDoc* ('Map') :: A generic way of addressing all available JavaDoc doclets and comments. The only fixed variable is `comment` (see below). All other provided variables depend on the doclets found while parsing. The value of a doclet can be accessed by the doclets name (e.g. `${...JavaDoc.author}`). In case of doclet tags that can be declared multiple times (currently `@param` and `@throws`), you will get a map, which you access in a specific way (see below).
*** *comment* ('String' :: JavaDoc comment, which does not include any doclets)
*** *params* ('Map :: JavaDoc parameter info. If the comment follows proper conventions, the key will be the name of the parameter and the value being its description. You can also access the parameters by their number, as in `arg0`, `arg1` etc, following the order of declaration in the signature, not in order of JavaDoc)
*** *throws* ('Map :: JavaDoc exception info. If the comment follows proper conventions, the key will be the name of the thrown exception and the value being its description)
** *`extendedType`* ('Map' :: The supertype, represented by a set of mappings _(since `cobigen-javaplugin v1.1.0`)_
*** *name* ('String' :: Simple name of the supertype)
*** *`canonicalName`* ('String' :: Full qualified name of the supertype)
*** *package* ('String' :: Package name of the supertype)
** `*implementedTypes*` ('List