Download presentation
Presentation is loading. Please wait.
Published byAsher Simpson Modified over 8 years ago
1
Apache Axis2 AXIOM - AXis Object Model
2
2 Agenda Processing XML / Why AXIOM? AXIOM Architecture Builders Deferred Building Caching Factories Input/Output Using AXIOM – Code examples Resources Exercises
3
3 Processing XML XML related applications work with Raw XML data XML files, strings containing XML, I/O streams,... XML parsers SAX, StAX, DOM (parser),... XML object models Represent an XML infoset as an object hierarchy (e.g. DOM – JDOM, dom4j) Application data object models Represent data in an application specific entity (object) hierarchy (e.g. By using XMLBeans, ADB)
4
4 Why AXIOM? A high performance object model specifically developed to address the needs of Web services environments Fast Low memory footprint What are the differences found in AXIOM?
5
5 AXIOM Way of Treating SOAP... MEGABYTES OF DATA HERE... An arbitrary header: Preferred to be processed through an OM (with read/write capabilities) Body: Preferred to be processed through a data binding framework (if ever required by a SOAP node)
6
6 XML Programming Models Current Models Document object models (eg : DOM) Complete XML in memory (A tree hierarchy) Document stream models (eg : SAX) XML infosets are parsed serially Can only go forward (no reverse gear)
7
7 Streaming Push/Pull Parsers Streaming push Emits (or “pushes”) events for the entire XML stream from the beginning to the end. SAX Streaming pull Let the client iterate though events or “pull” them. StAX – JSR 173 10111101100 pus h pul l parse r clien t
8
8 Advantages of Pull Parsing The client controls the application thread Pull parsing libraries can be much smaller and the client code to interact with those libraries are much simpler Pull clients can read multiple documents at one time with a single thread Can filter XML documents such that elements unnecessary to the client can be ignored
9
9 AXIOM Architecture
10
10 AXIOM Architecture Builders StAXOMBuilder Generic builder StAXSOAPModelBuilder Can read SOAP messages and builds SOAP object model based on AXIOM MTOMStAXSOAPModelBuilder Can read MTOM messages
11
11 AXIOM Architecture - Deferred Building Partial building of object model in memory Model is built on-demand and only up to the extent information is required. Saves memory, without compromising performance. Transparent to the user
12
12 AXIOM Architecture - Deferred Building Cont… MEGABYTES OF DATA h = envelope.getHeader(securityQName) Build object model to here...and then you can do body = envelope.getBody(); reader = body.getXMLStreamReader(); while (reader.hasNext()) {... }
13
13 AXIOM Architecture - Caching Information can be accessed with or without building the object model Enables intelligent and controlled use of memory example: sending messages doesn't require to build the object model
14
14 AXIOM Architecture - Concept of Factories
15
15 AXIOM Architecture- Input/Output Pull Event Stream Push Event Stream Pull Event Stream Programmatic Creation Push Event Stream
16
16 AXIOM Architecture – Input/Output Cont... AXIOM Pull stream Push stream API Read (tree) API Write (tree ) STAXOMBuilder. getDocumentElement() OMElement.getChildren() etc OMFactory.createOMElement() OMElement.serialize() OMElement. getXMLStreamReader() SAXOMBuilder. getDocumentElement()
17
17 Using AXIOM StAXOMBuilder builder = new StAXOMBuilder(new FileInputStream(xmlFile)); OMElement documentElement = builder.getDocumentElement(); System.out.println("xml = " + documentElement.toStringWithConsume()); Example : Read an XML File in to AXIOM and print it our to Sytem.out
18
18 Using AXIOM (Cont…) StAXOMBuilder builder = new StAXOMBuilder(new FileInputStream(xmlFile)); OMElement documentElement = builder.getDocumentElement(); System.out.println("xml = " + documentElement.toStringWithConsume()); Create an OM Builder from the given FileInputStream
19
19 Using AXIOM (Cont…) StAXOMBuilder builder = new StAXOMBuilder(new FileInputStream(xmlFile)); OMElement documentElement = builder.getDocumentElement(); System.out.println("xml = " + documentElement.toStringWithConsume()); Get the document element from the builder
20
20 Using AXIOM (Cont…) StAXOMBuilder builder = new StAXOMBuilder(new FileInputStream(xmlFile)); OMElement documentElement = builder.getDocumentElement(); System.out.println("xml = " + documentElement.toStringWithConsume()); Print the document element. toStringWithConsume() method will print the xml in to the out stream without building an OM tree
21
21 Navigating Object Model Iterator allChildren = presentationElement.getChildren(); while (allChildren.hasNext()) { OMNode omNode = (OMNode) allChildren.next(); omNode.serialize(System.out); System.out.println(""); }
22
22 Navigating Object Model Cont… Iterator allChildren = presentationElement.getChildren(); while (allChildren.hasNext()) { OMNode omNode = (OMNode) allChildren.next(); omNode.serialize(System.out); System.out.println(""); } Provides an iterator API to navigate children. This enables to differ building of object model
23
23 Navigating Object Model Cont… Iterator allChildren = presentationElement.getChildren(); while (allChildren.hasNext()) { OMNode omNode = (OMNode) allChildren.next(); omNode.serialize(System.out); System.out.println(""); } All AXIOM objects (OMElement, OMText, etc.,) extends from OMNode
24
24 Navigating Object Model Cont… OMElement presenter = presentationElement.getFirstChildWithName( new Qname("Presenter")); System.out.println("presenter = " + presenter); Searching for a specific element
25
25 Getting Events From Objects // Get an XMLStreamReader from the article element with // caching XMLStreamReader xmlStreamReader = presentationElement.getXMLStreamReader(); // Get an XMLStreamReader from the article element // without caching XMLStreamReader xmlStreamReaderWithoutCaching = presentationElement.getXMLStreamReaderWithoutCaching();
26
26 Resources AXIOM Project http://ws.apache.org/commons/axiom/ http://ws.apache.org/commons/axiom/ AXIOM API Documentation Available on-line (see above URL) or with AXIOM download Performance of AXIOM A comparison with other XML object model mechanisms found here: http://www.ibm.com/developerworks/webservices/library/ws-java2/ http://www.ibm.com/developerworks/webservices/library/ws-java2/
27
27 Exercises Download AXIOM binary distribution from http://ws.apache.org/commons/axiom/http://ws.apache.org/commons/axiom/ Look at the API documentation for the details of OMNode, OMElement, OMContainer, StAXOMBuilder, StAXSOAPModelBuilder The sample code contains the file SOAPHeaderProcessor.java. Follow the instructions given in the file to modify a SOAP header using AXIOM.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.