All Projects → sabomichal → Immutable Xjc

sabomichal / Immutable Xjc

Licence: mit
immutable-xjc is a JAXB 2.0 XJC plugin for making schema derived classes immutable with optional builder pattern generator.

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Immutable Xjc

Ewig
The eternal text editor — Didactic Ersatz Emacs to show immutable data-structures and the single-atom architecture
Stars: ✭ 422 (+640.35%)
Mutual labels:  immutable
React Tetris
Use React, Redux, Immutable to code Tetris. 🎮
Stars: ✭ 6,770 (+11777.19%)
Mutual labels:  immutable
Mori Ext
Function bind syntax wrappers for mori
Stars: ✭ 15 (-73.68%)
Mutual labels:  immutable
Easy Peasy
Vegetarian friendly state for React
Stars: ✭ 4,525 (+7838.6%)
Mutual labels:  immutable
Js Ipfs
IPFS implementation in JavaScript
Stars: ✭ 6,129 (+10652.63%)
Mutual labels:  immutable
Immutable
Missing non-mutating functions in Swift
Stars: ✭ 16 (-71.93%)
Mutual labels:  immutable
Immutable
Immutable collections for Go
Stars: ✭ 392 (+587.72%)
Mutual labels:  immutable
Raspbernetes
Raspberry Pi Kubernetes Cluster
Stars: ✭ 53 (-7.02%)
Mutual labels:  immutable
Rust Ipfs
The InterPlanetary File System (IPFS), implemented in Rust.
Stars: ✭ 739 (+1196.49%)
Mutual labels:  immutable
Partial.lenses
Partial lenses is a comprehensive, high-performance optics library for JavaScript
Stars: ✭ 846 (+1384.21%)
Mutual labels:  immutable
Koazee
A StreamLike, Immutable, Lazy Loading and smart Golang Library to deal with slices.
Stars: ✭ 446 (+682.46%)
Mutual labels:  immutable
Pepperoni App Kit
Pepperoni - React Native App Starter Kit for Android and iOS
Stars: ✭ 4,657 (+8070.18%)
Mutual labels:  immutable
Phpfn
Functional PHP Toolstet: Centralized monorepository for all libraries
Stars: ✭ 19 (-66.67%)
Mutual labels:  immutable
Dinero.js
Create, calculate, and format money in JavaScript and TypeScript.
Stars: ✭ 5,286 (+9173.68%)
Mutual labels:  immutable
Immutable Tuple
Immutable finite list objects with constant-time equality testing (===) and no memory leaks.
Stars: ✭ 29 (-49.12%)
Mutual labels:  immutable
Mail
Library to send e-mails over different transports and protocols (like SMTP and IMAP) using immutable messages and streams. Also includes SMTP server.
Stars: ✭ 399 (+600%)
Mutual labels:  immutable
Immutables
A high-performance immutable mapping type for Python.
Stars: ✭ 823 (+1343.86%)
Mutual labels:  immutable
Immutable Array Prototype
A collection of Immutable Array prototype methods(Per method packages).
Stars: ✭ 56 (-1.75%)
Mutual labels:  immutable
Utility
Assign/Partial/ReadOnly/Proxy
Stars: ✭ 31 (-45.61%)
Mutual labels:  immutable
Gridiron
Feature-Packed React Grid Framework
Stars: ✭ 8 (-85.96%)
Mutual labels:  immutable

Maven Central Java CI with Maven

immutable-xjc

IMMUTABLE-XJC is a JAXB 2.x XJC plugin for making schema derived classes immutable:

  • removes all setter methods
  • marks class final
  • creates a public constructor with all fields as parameters
  • creates a protected no-arg constructor
  • marks all fields within a class as final
  • wraps all collection like parameters with Collections.unmodifiable or Collections.empty if null (unless -imm-leavecollections option is used)
  • optionally creates builder pattern utility classes

Note: Derived classes can be further made serializable using these xjc customizations.

Release notes

1.6

  • added an option to set default values in no-arg constructors
  • added an option to generate builder classes that follow the same inheritance hierarchy as their subject classes
  • added an option to generate simple builder names
  • dropped support for java 6

1.5

  • added an option to leave collections mutable
  • added an option to generate public constructors only up to n arguments when builder is used

1.4

  • added an option to generate non-public constructors
  • added an option to generate additional withAIfNotNull(A a) builder methods

1.3

  • builder class copy constructor added

1.2

  • builder class now contains initialised collection fields
  • added generated 'add' methods to incrementally build up the builder collection fields

JAXB version

Plugin is built against JAXB 2.3.3

Java version

Target Java versions is 1.8, JAXB dependencies are set to be able to built with JDK 11+.

XJC options provided by the plugin

The plugin provides an '-immutable' option which is enabled by adding its jar file to the XJC classpath. When enabled, additional options can be used to control the behavior of the plugin. See the examples for further information.

-immutable

The '-immutable' option enables the plugin making the XJC generated classes immutable.

-imm-builder

The '-imm-builder' option can be used to generate builder like pattern utils for each schema derived class.

-imm-simplebuildername

The '-imm-simplebuildername' option can be used to generate builders which follow a simpler naming scheme, using Foo.builder() and Foo.Builder instead of Foo.fooBuilder() and Foo.FooBuilder.

-imm-inheritbuilder

The '-imm-inheritbuilder' option can be used to generate builder classes that follow the same inheritance hierarchy as their subject classes.

-imm-cc

The '-imm-cc' option can only be used together with '-imm-builder' option and it is used to generate builder class copy construstructor, initialising builder with object of given class.

-imm-ifnotnull

The '-imm-ifnotnull' option can only be used together with '-imm-builder' option and it is used to add an additional withAIfNotNull(A a) method for all non-primitive fields A in the generated builders.

-imm-nopubconstructor

The '-imm-nopubconstructor' option is used to make the constructors of the generated classes non-public.

-imm-pubconstructormaxargs

The '-imm-pubconstructormaxargs=n' option is used to generate public constructors with up to n arguments, when -imm-builder is used

-imm-skipcollections

The '-imm-skipcollections' option is used to leave collections mutable

-imm-constructordefaults

The '-imm-constructordefaults' option is used to set default values for xs:element's and xs:attribute's in no-argument constructor. Default values must be strings or numbers, otherwise ignored.

-imm-optionalgetter

The '-imm-optionalgetter' option is used to wrap the return value of getters for non-required (@XmlAttribute|Element(required = false)) values with java.util.Optional<OriginalRetunType>.

Usage

JAXB-RI CLI

To use the JAXB-RI XJC command line interface simply add the corresponding java archives to the classpath and execute the XJC main class 'com.sun.tools.xjc.XJCFacade'. The following example demonstrates a working command line for use with JDK 11+ (assuming the needed dependencies are found in the current working directory).

java.exe -Dcom.sun.tools.xjc.XJCFacade.nohack=true\ 
         -classpath codemodel-2.3.2.jar:\
                    jaxb-api-2.3.2.jar:\
                    jaxb-runtime-2.3.2.jar:\
                    jaxb-xjc-2.3.2.jar:\
                    javax.activation-api-1.2.0.jar:\
                    javax.activation-1.2.0.jar:\
                    rngom-2.3.2.jar:\
                    istack-commons-tools-3.0.7.jar:\
                    istack-commons-runtime-3.0.7.jar:\
                    relaxng-datatype-2.3.2.jar:\
                    txw2-2.3.1.jar:\
                    xsom-2.3.1.jar com.sun.tools.xjc.XJCFacade -immutable <schema files>

Maven

Maven users simply add the IMMUTABLE-XJC plugin as a dependency to a JAXB plugin of choice. The following example demonstrates the use of the IMMUTABLE-XJC plugin with the mojo maven-jaxb2-plugin.

<plugin>
     <groupId>org.jvnet.jaxb2.maven2</groupId>
     <artifactId>maven-jaxb2-plugin</artifactId>
     <version>0.14.0</version>
     <dependencies>
         <dependency>
             <groupId>com.github.sabomichal</groupId>
             <artifactId>immutable-xjc-plugin</artifactId>
             <version>1.6.2</version>
         </dependency>
     </dependencies>
     <executions>
         <execution>
             <phase>generate-sources</phase>
             <goals>
                 <goal>generate</goal>
             </goals>
             <configuration>
                 <specVersion>2.3.1</specVersion>
                 <args>
                     <arg>-immutable</arg>
                     <arg>-imm-builder</arg>
                 </args>
             </configuration>
         </execution>
     </executions>
 </plugin>

IMMUTABLE-XJC can be used also in contract-first webservice client scenarios with wsimport. The following example demonstrates the usage of the plugin with jaxws-maven-plugin mojo.

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.github.sabomichal</groupId>
            <artifactId>immutable-xjc-plugin</artifactId>
            <version>1.6.2</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <wsdlFiles>
                    <wsdlFile>example.wsdl</wsdlFile>
                </wsdlFiles>
                <args>
                    <arg>-B-immutable -B-imm-builder</arg>
                </args>
            </configuration>
        </execution>
    </executions>
</plugin>

Next two examples demonstrates the usage of the plugin with CXF cxf-codegen-plugin and cxf-xjc-plugin mojo.

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.github.sabomichal</groupId>
            <artifactId>immutable-xjc-plugin</artifactId>
            <version>1.6.2</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
            <configuration>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/wsdl/example.wsdl</wsdl>
                        <extraargs>
                            <extraarg>-xjc-immutable</extraarg>
                            <extraarg>-xjc-imm-builder</extraarg>
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-xjc-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.github.sabomichal</groupId>
            <artifactId>immutable-xjc-plugin</artifactId>
            <version>1.6.2</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>xsd2java</goal>
            </goals>
            <configuration>
                <xsdOptions>
                    <xsdOption>
                        <xsd>${basedir}/wsdl/example.xsd</xsd>
                        <extensionArgs>
                            <arg>-immutable</arg>
                            <arg>-imm-builder</arg>
                        </extensionArgs>
                    </xsdOption>
                </xsdOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

Gradle

The following example demonstrates the use of the IMMUTABLE-XJC plugin with the Gradle plugin wsdl2java.

plugins {
    id "no.nils.wsdl2java" version "0.12"
}

dependencies {
    wsdl2java 'com.github.sabomichal:immutable-xjc-plugin:1.6.2'
}

wsdl2java {
    wsdlsToGenerate = [
            ['-xjc-immutable', '-xjc-imm-builder', 'src/main/resources/wsdl/example.wsdl']
        ]
    wsdlDir = file("$projectDir/src/main/resources/wsdl")
    cxfVersion = "3.3.5"
    cxfPluginVersion = "3.3.1"
}

If you like it, give it a star, if you don't, write an issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].