通过jaxb产生java code

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>xxxxx</name>
<groupId>xxxxx</groupId>
<artifactId>xxxxx</artifactId>
<version>0.1</version>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<configuration>
<filters>
<filter>-org.fpml.reporting.*</filter>
</filters>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>xml_reporting-xjc</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/xsd/</schemaDirectory>
<packageName>org.fpml.reporting</packageName>
<staleFile>${project.build.directory}/jaxb2/.reportingXjcStaleFlag</staleFile>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>${project.basedir}/target/generated/java</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

</project>


下面的例子是定义extension xsd,并产生相应的java.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>xxxxx</groupId>
<artifactId>xxxxx</artifactId>
<version>xxxxx</version>

<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<id>xjc-extension</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<extension>true</extension>
<args>
<arg>-npa</arg>
</args>
<bindingDirectory>src/main/resources/xsd/</bindingDirectory>
<bindingIncludes>
<include>bindings.xml</include>
</bindingIncludes>
<schemaDirectory>src/main/resources/xsd/extension</schemaDirectory>
<schemaIncludes>
<include>extensions.xsd</include>
</schemaIncludes>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<createChecksum>true</createChecksum>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>


Binding file定义:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1">
<bindings schemaLocation="Standard/fpml-main-5-7.xsd">
<schemaBindings>
<package name="org.fpml.reporting"/>
</schemaBindings>
</bindings>

<bindings schemaLocation="Extension/extensions.xsd">
<schemaBindings>
<package name="xxxxx.extension"/>
</schemaBindings>
</bindings>
</bindings>


Extension file定义:
<schema targetNamespace="http://www.statestreet.com/FpML-Extension"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault = "unqualified">
<xsd:include schemaLocation="fpml-reporting-position-ext.xsd"/>
</schema>


fpml-reporting-position-ext.xsd定义:
<schema targetNamespace="http://www.statestreet.com/FpML-Extension"
xmlns:ext="http://www.statestreet.com/FpML-Extension" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:fpml="http://www.fpml.org/FpML-5/reporting" elementFormDefault="qualified">
<import namespace="http://www.fpml.org/FpML-5/reporting"
schemaLocation="../standard/fpml-main-5-7.xsd" />

<simpleType name="statusEnum">
<restriction base="normalizedString">
<enumeration value="booked" />
<enumeration value="unbooked" />
</restriction>
</simpleType>

<complexType name="Position">
<complexContent>
<extension base="fpml:ReportedPosition">
<sequence>
<element name="status" type="ext:statusEnum" minOccurs="0" />
<element name="constituent" type="ext:PositionConstituent"
minOccurs="0" />
</sequence>
</extension>
</complexContent>
</complexType>

<complexType name="FxSingleLeg">
<complexContent>
<extension base="fpml:FxSingleLeg">
<sequence>
<element minOccurs="0" name="exchangedCurrency1" type="ext:Payment" />
<element minOccurs="0" name="exchangedCurrency2" type="ext:Payment" />
</sequence>
</extension>
</complexContent>
</complexType>

<complexType name="Payment">
<complexContent>
<extension base="fpml:Payment">
<sequence>
<element minOccurs="0" name="paymentAmount" type="fpml:Money" />
</sequence>
</extension>
</complexContent>
</complexType>

<complexType name="NettedBenchmarkFX">
<sequence>
<element name="agreementId" type="normalizedString"
minOccurs="0" />
<element name="pricingSite" type="normalizedString"
minOccurs="0" />
<element name="fxSingleLeg" type="ext:FxSingleLeg" minOccurs="0" />
</sequence>
</complexType>

<complexType name="PositionConstituent">
<complexContent>
<extension base="fpml:PositionConstituent">
<sequence>
<element name="nettedBenchmarkFX" type="ext:NettedBenchmarkFX"
minOccurs="0" />
</sequence>
</extension>
</complexContent>
</complexType>

</schema>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值