utilized jaxb to generate pojos automatically

21
Utilized JAXB to generate POJOs automatically -- Green Integration Part II Albert Guo [email protected]

Upload: guo-albert

Post on 29-Jun-2015

7.839 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Utilized JAXB to generate POJOs automatically

Utilized JAXB to generate POJOs automatically -- Green Integration Part II Albert Guo

[email protected]

Page 2: Utilized JAXB to generate POJOs automatically

Agenda

Scenario

JAXB (Java Architecture for XML Binding)

Implementation steps in Green Integration

JAXB Usage

JAXB Limitations

Summary

Appendix

2

Page 3: Utilized JAXB to generate POJOs automatically

Scenario

Page 4: Utilized JAXB to generate POJOs automatically

4

System Architecture

CIS

Green

Windchill

Project Management

Document Management

Change Management

Pro/EWildfire

Pro/E

Wo

rk Sp

ace

Pro/E

PDMLink

Supplier Management

GSM

Product Management

(Part /BOM)

Interface

Ta

ble

SAPERP

ProjectLinkO

DB

C

xml

Page 5: Utilized JAXB to generate POJOs automatically

5

Where to launch

Export BOM to GSMxml

Page 6: Utilized JAXB to generate POJOs automatically

6

XML content example

If the part has child, this part will be enclosed by <ProductStructure>.If the part does not have child, then this part will be enclosed by <Line>

If the part has child, this part will be enclosed by <ProductStructure>.If the part does not have child, then this part will be enclosed by <Line>

Page 7: Utilized JAXB to generate POJOs automatically

JAXB (Java Architecture for XML Binding)

Page 8: Utilized JAXB to generate POJOs automatically

What is JAXB

JAXB (Java Architecture for XML Binding) is part of the Java Web Services Developer pack.

This integrated toolkit contains all of J2EE's XML technologies, including SAX, DOM, web services, and others.

Official site: https://jaxb.dev.java.net/

Download: http://java.sun.com/webservices/downloads/index.jsp

Installation instructions: http://java.sun.com/webservices/downloads/install-windows.html

8

Page 9: Utilized JAXB to generate POJOs automatically

9

Architecture

JAXB

We’ll focus on JAXB instead of Xstream in this material. If you’re interested in Xstream, please refer to Utilized XStrem in Green Integration .

We’ll focus on JAXB instead of Xstream in this material. If you’re interested in Xstream, please refer to Utilized XStrem in Green Integration .

XML Spy can do the same thing, but it’s not free solution.XML Spy can do the same thing, but it’s not free solution.

Page 10: Utilized JAXB to generate POJOs automatically

Implementation steps in Green Integration

Page 11: Utilized JAXB to generate POJOs automatically

Implementation steps in Green Integration

11

Applied JAXB to generate POJOs automaticallyApplied JAXB to generate POJOs automatically

We can focus on retrieving data and setting them into POJOs.

We can focus on retrieving data and setting them into POJOs.

Applied XStream to generate XML file by easy way.Applied XStream to generate XML file by easy way.

Applied Commons IO to write xml content into fileApplied Commons IO to write xml content into file

Logging serviceLogging service

Utility classes

Utility classes

Commons LangCommons Lang

Page 12: Utilized JAXB to generate POJOs automatically

JAXB Usage

Page 13: Utilized JAXB to generate POJOs automatically

JAXB Usage -- commands

xjc.bat -p [package name] [xsd location] -d [code gen destination]xjc.bat -p [package name] [xsd location] -d [code gen destination]

13

Page 14: Utilized JAXB to generate POJOs automatically

JAXB Usage

We can use JAXB to generate these POJOs based on xsd file automaticallyWe can use JAXB to generate these POJOs based on xsd file automatically

14

Page 15: Utilized JAXB to generate POJOs automatically

JAXB Limitations

Page 16: Utilized JAXB to generate POJOs automatically

JAXB Limitations

① JAXB only support JDK 1.5 or later.

② These POJOs which generated by JAXB will have many annotations in its content. Therefore, if your JDK is 1.4 or before, you need to remove these annotations part and remove its related import statement (javax.xml.bind.annotation.*).

16

Page 17: Utilized JAXB to generate POJOs automatically

Summary

17

Page 18: Utilized JAXB to generate POJOs automatically

Summary

18

Logging serviceLogging service

Page 19: Utilized JAXB to generate POJOs automatically

Appendix

19

Page 20: Utilized JAXB to generate POJOs automatically

Appendix

• JAXB

– JAXB is one of the APIs in the Java EE platform, and is part of the Java Web Services Development Pack (JWSDP). It is also one of the foundations for WSIT. JAXB is part of SE version 1.6.

– JAXB 1.0 was developed under the Java Community Process as JSR 31. As of 2006, JAXB 2.0 is being developed under JSR 222. Reference implementations for these specifications are available under the CDDL open source license at java.net.

• Xstream

– a simple Java library to serialize objects to XML and back again.

– a Danish IT-company offering streaming media business solutions (spelled Xstream)

– a simple functional transformation language for XML documents derived from Caml, for which a compiler is provided under CeCILL free software licence.

20

Page 21: Utilized JAXB to generate POJOs automatically

Appendix

• Commons IO

– Commons IO is a library of utilities to assist with developing IO functionality.

– There are three main areas included:

• Utility classes - with static methods to perform common tasks

• Filters - various implementations of file filters

• Streams - useful stream, reader and writer implementations

• Commons Lang

– The Lang Component provides a host of helper utilities for the java.lang API, notably String manipulation methods, basic numerical methods, object reflection, creation and serialization, and System properties. Additionally it contains an inheritable enum type, an exception structure that supports multiple types of nested-Exceptions, basic enhancements to java.util.Date and a series of utlities dedicated to help with building methods, such as hashCode, toString and equals.

• Log4j

– log4j is a Java-based logging utility. It was originally written by Ceki Gülcü and is now a project of the Apache Software Foundation. It is used primarily as a debugging tool.

21