|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Artifact
An artifact is any type of file emitted by the code generator. Artifacts have an output directory and file name which are combined to form the final output location.
One of the main purposes of an artifact is to obtain the output file name and path using the same context properties that templates use. This allows consistent, centralized naming patterns.
The DefaultArtifact uses two keys by default to obtain the outputDirectory
and outputFileName, Keys.OUTPUT_DIRECTORY_TEMPLATE("outputDirectoryTemplate") and
Keys.FILE_NAME_TEMPLATE("fileNameTemplate") respectively. These names are built by recursively
applying values to replacement holders until a pure string is obtained.
Because the replacement
holders are scattered around the context tree, it can be confusing how a name is derived. Here
are two concrete examples of name derivation for the Address model instance applied to
the DAO template:
targetDirectory=/dev/myRevGen
srcDirectory=${targetDirectory}/src/main/java
outputDirectoryTemplate=${srcDirectory}
These values result in the base source directory for Java output:outputDirectoryTemplate=/dev/myRevGen/src/main/java.
basePackageName=org/revgen/example
relativePackageName=/sales
daoPackageNameTemplate=#{basePackageName}/dao#{relativePackageName}
daoNameTemplate=#{entityName}DAO"/>
fileNameTemplate=#{packageNameTemplate}/#{classNameTemplate}.java
These values result in the relative path and Java file name output:fileNameTemplate=org/revgen/example/sales/AddressDAO.java.
If you're paying attention you will have noticed
three missing properties. entityName is added to the context dynamiclly by calling
context.put("entityName", model.getName()). The remaining two values are set in the
DAO emitter context configuration because there are unique to the DAO template:
classNameTemplate=#{daoNameTemplate}
packageNameTemplate=#{daoPackageNameTemplate}
| Method Summary | |
|---|---|
File |
outputDirectory(Context context)
Given a context determine the base output directory for this artifact. |
File |
outputFileName(Context context)
Given a context determine the file name for this artifact. |
| Method Detail |
|---|
File outputDirectory(Context context)
outputDirectoryTemplate, outputTestDirectoryTemplate
and outputResourceDirectoryTemplate.
context - typically a composite of leaf, parent and emitter contexts.
File outputFileName(Context context)
context - typically a composite of leaf, parent and emitter contexts.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||