`
qtlkw
  • 浏览: 301583 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

通过jaxb产生java code

    博客分类:
  • 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>

	<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>
分享到:
评论

相关推荐

    JAXB(JAXB支持、源码、官方说明文档)

    java -jar JAXB2_20060607.jar On Windows, you can just double-click the jar file to execute. Release Notes Browse the release notes online, including what's new. Technical Support Please subscribe to...

    JAVA_API1.6文档(中文)

    javax.imageio.stream Java Image I/O API 的一个包,用来处理从文件和流中产生的低级别 I/O。 javax.management 提供 Java Management Extensions 的核心类。 javax.management.loading 提供实现高级动态加载的类...

    java7帮助文档

    This release contains Java API for XML Processing (JAXP) 1.4.5, supports Java Architecture for XML Binding (JAXB) 2.2.3, and supports Java API for XML Web Services (JAX-WS) 2.2.4. ...

    Java 1.6 API 中文 New

    javax.imageio.stream Java Image I/O API 的一个包,用来处理从文件和流中产生的低级别 I/O。 javax.management 提供 Java Management Extensions 的核心类。 javax.management.loading 提供实现高级动态加载的类。...

    Code-Samples:JavaJEE示例代码

    通常是Java EE 6示例企业应用程序。 该代码故意琐碎地专注于JEE 6产生Spring / Hibernate类型应用程序的技术能力。 组成项目如下: 带有客户端的EJB 3.0会话bean。 会话bean将其访问方法公开为SOAP Web服务。 具有...

    JavaAPI1.6中文chm文档 part1

    javax.imageio.stream Java Image I/O API 的一个包,用来处理从文件和流中产生的低级别 I/O。 javax.management 提供 Java Management Extensions 的核心类。 javax.management.loading 提供实现高级动态加载的类...

    java api最新7.0

    javax.imageio.stream Java Image I/O API 的一个包,用来处理从文件和流中产生的低级别 I/O。 javax.management 提供 Java Management Extensions 的核心类。 javax.management.loading 提供实现高级动态加载的类。...

    jaxb-format-plugin:JAXB(用于XML绑定的Java API)架构到源代码编译器(XJC)的插件,该代码生成代码以通过XPath表达式格式化生成的类的实例-Form source code

    用于JAXB(用于XML绑定的Java API)架构到源代码的编译器(XJC)的插件,该代码生成代码以通过任意帮助程序类格式化生成的类的实例。 动机 XJC当前有多个插件,可以在生成的JAXB类文件中生成“ toString()”方法。...

    jpaannotationsprocessor:JPA Annotation Processor 基于“Better JPA、Better JAXB 和 Better Annotations Processing with Java SE 6”(http

    JPA Annotation Processor 基于“Better JPA、Better JAXB 和 Better Annotations Processing with Java SE 6” ================================================== ============================ JPA ORM 注释...

    JavaAPI中文chm文档 part2

    javax.imageio.stream Java Image I/O API 的一个包,用来处理从文件和流中产生的低级别 I/O。 javax.management 提供 Java Management Extensions 的核心类。 javax.management.loading 提供实现高级动态加载的类...

    [Java参考文档]

    javax.imageio.stream Java Image I/O API 的一个包,用来处理从文件和流中产生的低级别 I/O。 javax.management 提供 Java Management Extensions 的核心类。 javax.management.loading 提供实现高级动态加载的类...

    [Java参考文档].JDK_API 1.6

    javax.imageio.stream Java Image I/O API 的一个包,用来处理从文件和流中产生的低级别 I/O。 javax.management 提供 Java Management Extensions 的核心类。 javax.management.loading 提供实现高级动态加载的类。...

    java8源码-small-frame-demo:小框架-demo

    xml-jaxb-test xml-xstream-test xml-fasterxml-test byte-code-op asm-demo byte-buddy-demo object-op-frame objenesis-test jol-demo 计算 java 对象大小 java-op-db connection-pool-test 连接池测试,包含高...

    Spring+Cloud+配置.pdf

    JAXB (Spring XML 序列化) SAX (Simple API for XML) XML Stream XStream Properties(JDK API 可处理) Key Value 配置模式 XML 配置模式 .ini(JDK Properties API 可处理) JSON(第三方) YAML(第三方...

    JDK_1_6 API

    javax.imageio.stream Java Image I/O API 的一个包,用来处理从文件和流中产生的低级别 I/O。 javax.management 提供 Java Management Extensions 的核心类。 javax.management.loading 提供实现高级动态加载的类...

    learning rabbitmq

    His areas of interest include a wide range of Java-related technologies (Servlets, JSP, JAXB, JAXP, JMS, JMX, JAX-RS, JAX-WS, Hibernate, Spring Framework, Liferay Portal, and Eclipse RCP), cloud ...

    JavaEE 5.0 Tutorial.pdf

    The Java EE 5Tutorial For Sun Java System Application Server 9.1 Contents Preface .........................................................................................................................

Global site tag (gtag.js) - Google Analytics