Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does below configuration means(jaxb-fluent-api)?

I have below configuration in my POM file. Especially jaxb-fluent-api configuration.

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <configuration>
        <extension>true</extension>
        <args>
            <arg>-Xfluent-api</arg>
        </args>
        <schemaDirectory>src/main/resources</schemaDirectory>
        <plugins>
            <plugin>
                <groupId>net.java.dev.jaxb2-commons</groupId>
                <artifactId>jaxb-fluent-api</artifactId>
                <version>2.1.8</version>
            </plugin>
        </plugins>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Without configuring jaxb-fluent-api entities can be generated from xsd. here what are the benifits using jaxb-fluent-api?

Thanks!

like image 620
user1016403 Avatar asked Jun 25 '12 13:06

user1016403


1 Answers

The jaxb-fluent-api is an JAXB extension, allowing you to generate your code in a fluent api style. Now, fluent api is a way of designing your class methods, so they always return this instead of void.

There is a good example on the project wiki (I've shortened it a bit for brevity, visit the site for full example):

Normal JAXB-generated code must be used like this:

Project project = factory.createProject();

project.setModelVersion("4.0.0");
project.setGroupId("redmosquito")
project.setArtifactId("jaxb-fluent-api-ext")
project.setPackaging("jar")
project.setVersion("0.0.1")
project.setName("JAXB Fluent API Extensions");

With jaxb-fluent-api extension, you can code the above like this:

Project project = factory.createProject()
    .withModelVersion("4.0.0");
    .withGroupId("redmosquito")
    .withArtifactId("jaxb-fluent-api-ext")
    .withPackaging("jar")
    .withVersion("0.0.1")
    .withName("JAXB Fluent API Extensions");

That's basically what the fluent api is all about.

like image 53
npe Avatar answered Sep 19 '22 05:09

npe