Child pages
  • cxf-xjc-dv
Skip to end of metadata
Go to start of metadata

CXF XJC Default Value Plugin

The CXF XJC Default Value Plugin provides and XJC plugin that updates the generated beans to return the default value defined in the schema for fields that are unset in the instance.

For example, if the schema contains:

<xs:complexType name="pageColor">
  	<xs:sequence>
	    <xs:element name="background" type="xs:string" default="red"/>
	    <xs:element name="foreground" type="xs:string" default="blue"/>
   </xs:sequence>
</xs:complexType>

it would generate getter methods like:

    public String getBackground() {
        if (null == background) {
            return "red";
        }
        return background;
    }

    public String getForeground() {
        if (null == foreground) {
            return "blue";
        }
        return foreground;
    }

Normally, XJC would just generate code like:

    public String getBackground() {
        return background;
    }

    public String getForeground() {
        return foreground;
    }

so code that works with the beans need to take the possible null return into account.

To use with Maven

           <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-xjc-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>xsdtojava</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <xsdOptions>
                        <xsdOption>
                            <extension>true</extension>
                            <xsd>${basedir}/src/main/resources/schemas/configuration/foo.xsd</xsd>
                            <extensionArgs>
                                <arg>-Xdv</arg>
                            </extensionArgs>
                        </xsdOption>
                    </xsdOptions>
                    <extensions>
                        <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0</extension>
                    </extensions>
                </configuration>
            </plugin>

  • No labels

0 Comments