public class ComponentGenerator extends Object
ComponentMetadata as input and generates the corresponding Java class
that can interacts with the original webcomponent. The metadata can also be
set as a JSON format.generateClass(ComponentMetadata, String, String),
generateClass(File, File, String, String)| Constructor and Description |
|---|
ComponentGenerator() |
| Modifier and Type | Method and Description |
|---|---|
void |
build()
Generate the class according to the set values.
|
void |
generateClass(ComponentMetadata metadata,
File targetPath,
String basePackage,
String licenseNote)
Generates the Java class by using the
ComponentMetadata object. |
String |
generateClass(ComponentMetadata metadata,
String basePackage,
String licenseNote)
Generates and returns the Java class based on the
ComponentMetadata. |
void |
generateClass(File jsonFile,
File targetPath,
String basePackage,
String licenseNote)
Generates the Java class by reading the webcomponent metadata from a JSON
file.
|
String |
generateClass(File jsonFile,
String basePackage,
String licenseNote)
Generates and returns the Java class based on the JSON file provide.
|
protected ComponentMetadata |
toMetadata(File jsonFile)
Converts the JSON file to
ComponentMetadata. |
ComponentGenerator |
withAbstractClass(boolean abstractClass)
When set to
true, the generated class will be marked as
abstract. |
ComponentGenerator |
withBasePackage(String basePackage)
Set the base package that will be used.
|
ComponentGenerator |
withClassNamePrefix(String classNamePrefix)
Set a prefix for the name of all generated classes.
|
ComponentGenerator |
withFluentMethods(boolean fluentMethods)
Set whether the generator should use fluent Methods - methods that return
the own object so it's possible to use method chaining.
|
ComponentGenerator |
withFrontendDirectory(String frontendDirectory)
Set the import frontend base package.
|
ComponentGenerator |
withJsonFile(File jsonFile)
Set the input JSON file.
|
ComponentGenerator |
withLicenseNote(String licenseNote)
Set the license header notice for the file.
|
ComponentGenerator |
withProtectedMethods(boolean protectedMethods)
When set to
true, all generated methods will be protected. |
ComponentGenerator |
withTargetPath(File targetPath)
Set the target output directory.
|
protected ComponentMetadata toMetadata(File jsonFile)
ComponentMetadata.jsonFile - The input JSON file.ComponentGenerationException - If an error occurs when reading the file.public ComponentGenerator withFluentMethods(boolean fluentMethods)
fluentMethods - true to enable fluent setters, false
to disable them.public ComponentGenerator withJsonFile(File jsonFile)
jsonFile - The input JSON file.public ComponentGenerator withTargetPath(File targetPath)
targetPath - The output base directory for the generated Java file.public ComponentGenerator withBasePackage(String basePackage)
basePackage - The base package to be used for the generated Java class. The
final package of the class is basePackage plus the
ComponentMetadata.getBaseUrl().public ComponentGenerator withLicenseNote(String licenseNote)
licenseNote - A note to be added on top of the class as a comment. Usually
used for license headers.public ComponentGenerator withFrontendDirectory(String frontendDirectory)
frontendDirectory - frontend base packagepublic ComponentGenerator withProtectedMethods(boolean protectedMethods)
true, all generated methods will be protected.
Use this flag to create classes that will be extended afterwards. The
default is false.protectedMethods - true to make all methods protected,
false to allow public methods in the generated
code.public ComponentGenerator withAbstractClass(boolean abstractClass)
true, the generated class will be marked as
abstract.abstractClass - true to make the generated class abstract,
false to make it concrete.public ComponentGenerator withClassNamePrefix(String classNamePrefix)
classNamePrefix - the class name prefixpublic void build()
public void generateClass(File jsonFile, File targetPath, String basePackage, String licenseNote)
jsonFile - The input JSON file.targetPath - The output base directory for the generated Java file.basePackage - The base package to be used for the generated Java class. The
final package of the class is basePackage plus the
ComponentMetadata.getBaseUrl().licenseNote - A note to be added on top of the class as a comment. Usually
used for license headers.ComponentGenerationException - If an error occurs when generating the class.toMetadata(File),
generateClass(ComponentMetadata, File, String, String)public String generateClass(ComponentMetadata metadata, String basePackage, String licenseNote)
ComponentMetadata. Doesn't write anything to the disk.metadata - The webcomponent metadata.basePackage - The base package to be used for the generated Java class. The
final package of the class is basePackage plus the
ComponentMetadata.getBaseUrl().licenseNote - A note to be added on top of the class as a comment. Usually
used for license headers.ComponentGenerationException - If an error occurs when generating the class.public String generateClass(File jsonFile, String basePackage, String licenseNote)
jsonFile - The webcomponent JSON metadata.basePackage - The base package to be used for the generated Java class. The
final package of the class is basePackage plus the
ComponentMetadata.getBaseUrl().licenseNote - A note to be added on top of the class as a comment. Usually
used for license headers.ComponentGenerationException - If an error occurs when generating the class.generateClass(ComponentMetadata, String, String)public void generateClass(ComponentMetadata metadata, File targetPath, String basePackage, String licenseNote)
ComponentMetadata object.metadata - The webcomponent metadata.targetPath - The output base directory for the generated Java file.basePackage - The base package to be used for the generated Java class. The
final package of the class is basePackage plus the
ComponentMetadata.getBaseUrl().licenseNote - A note to be added on top of the class as a comment. Usually
used for license headers.ComponentGenerationException - If an error occurs when generating the class.Copyright © 2000–2019 Vaadin Ltd. All rights reserved.