JAXB Overview - PowerPoint PPT Presentation

About This Presentation
Title:

JAXB Overview

Description:

compile. marshal. unmarshal. 8/28/09. JAXB Overview. 4. JAXB: Java Architecture for XML Binding ... XML names Java names. Schema atomic types predefined Java types ... – PowerPoint PPT presentation

Number of Views:125
Avg rating:3.0/5.0
Slides: 16
Provided by: avayalabs
Category:
Tags: jaxb | compile | overview

less

Transcript and Presenter's Notes

Title: JAXB Overview


1
JAXB Overview
  • Vladimir Gapeyev

2
XML data binding
Java
XML
ObjectFactory f new ObjectFactory() Book
b f.createBook() b.setTitle(Compilers) List
a b.getAuthor() a.add(Aho) a.add(Sethi)
a.add(Ullman) b.setPages(796)
ltbookgt lttitlegtCompilerslt/titlegt
ltauthorgtAholt/authorgt ltauthorgtSethilt/authorgt
ltauthorgtUllmanlt/authorgt ltpagesgt796lt/pagesgt lt/boo
kgt
3
Schema-based XML data binding
compile
Schema
Classes
instance of
conforms
unmarshal
Objects
Documents
marshal
4
JAXB Java Architecture for XML Binding
  • Specification
  • Subset of XML Schema
  • Default bindings
  • XML names ? Java names
  • Schema atomic types ? predefined Java types
  • Schema structured types ? Java interfaces
  • javax.xml.bind framework interfaces
  • Language for binding customization
  • Reference implementation
  • Schema-to-Java compliler
  • Generates classes as well

5
Mapping for atomic types
xsstring ? java.lang.string
xsdecimal ? java.math.BigDecimal
xsint ? int
xsQName ? javax.xml.namespace.QName
xsdate ? java.util.Calendar
Etc
6
Elements with simple content
interface Zip extends javax.xml.bind.Element
int getValue() void setValue(int)
ltxselement namezip typexsint /gt
7
Elements with sequence and repetition
ltxselement namebook gt ltxsComplexTypegt
ltxssequencegt ltxselement nametitle
typexsstring/gt ltxselement nameauthor
typexsstring maxOccursunbounded/gt
ltxselement namepages typexsint/gt
lt/xssequencegt lt/xsComplexTypegt lt/xselementgt
interface Book extends BookType,
javax.xml.bind.Element interface BookType
String getTitile() void setTitle(String x)
List getAuthor() int getPages() void
setPages(int x)
8
Elements with choice
ltxscomplexType namevolumegt
ltxschoicegt ltxselement
refbook/gt ltxselement
refjournal/gt lt/xschoicegt lt/xscomplexTypegt
interface Volume BookType getBook() void
setBook(BookType) JournalType getJournal()
void setJournal(JournalType)
9
Customization isSet() method
ltxsannotationgtltxsappinfogt ltjxbglobalBindings
generateIsSetMethodtrue"/gt lt/xsappinfogtlt/xsan
notationgt
ltxscomplexType namevolumegt
ltxschoicegt ltxselement
refbook/gt ltxselement
refjournal/gt lt/xschoicegt lt/xscomplexTypegt
interface Volume BookType getBook() void
setBook(BookType) boolean isSetBook()
JournalType getJournal() void
setJournal(JournalType) boolean
isSetJournal()
10
No roundtripping
interface T getA() setA() getB()
setB()
type t (element a, element b) (element
b, element a)
Type t members lta/gtltb/gt and ltb/gtlta/gt
unmarshal marshal / identity unmarshal
marshal unmarshal unmarshal
11
General content style
ltxscomplexType nametgt ltxschoice
maxOccursunboundedgt ltelement refbook/gt
ltelement refjournal/gt lt/xschoicegt lt/xscomple
xTypegt
interface T List getBookOrJournal()
  • Plus a constraint
  • The only list members are
  • Book objects
  • Journal objects

12
Model groups, by default
ltxsgroup name"bookName"gt ltxssequencegt
ltxselement name"title" type"xsstring"/gt
ltxselement name"author"
type"xsstring/gt lt/xssequencegt lt/xsgroupgt ltx
scomplexType name"bookType"gt ltxssequencegt
ltxsgroup ref"bookName"/gt ltxselement
name"pages" type"xsint"/gt
lt/xssequencegt lt/xscomplexTypegt
interface BookType String getTitle() void
setTitle(String x) String getAuthor() void
setAuthor(String) int getPages() void
setPages(int x)
13
Model groups, customized
ltxsgroup name"bookName"gt ltxssequencegt
ltxselement name"title" type"xsstring"/gt
ltxselement name"author"
type"xsstring/gt lt/xssequencegt lt/xsgroupgt ltx
scomplexType name"bookType"gt ltxssequencegt
ltxsgroup ref"bookName"/gt ltxselement
name"pages" type"xsint"/gt
lt/xssequencegt lt/xscomplexTypegt
interface BookName String getTitle() void
setTitle(String x) String getAuthor() void
setAuthor(String) interface BookType
BookName getBookName() void setBookName(BookNam
e) int getPages() void setPages(int x)
14
Summary of observations
  • Mapping often loses static typing information
    need to employ dynamic constraints
  • Complex content models with choice are most
    problematic
  • Alternative mapping styles
  • No good declarative specifications for the
    mappings

15
Opportunities
  • Formal specification of mapping styles
  • Formulate desired mapping properties
  • Verify that the mapping styles enjoy the
    properties
  • A toolkit for generating mapping compilers (as
    opposed to a single compiler)
Write a Comment
User Comments (0)
About PowerShow.com