40
1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences 2 Agenda Summary of Previous Session XML Object Persistence Advanced XQuery Concepts Presentation Oriented Publishing (POP) Frameworks Web Services Assignment 5a-c (due next week)

g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

1

1

XML for Java Developers G22.3033-002

Session 10 - Main ThemeXML Information Retrieval (Part II)

And XML-Based Frameworks (Part I)

Dr. Jean-Claude Franchitti

New York UniversityComputer Science Department

Courant Institute of Mathematical Sciences

2

Agenda

Summary of Previous SessionXML Object PersistenceAdvanced XQuery ConceptsPresentation Oriented Publishing (POP) FrameworksWeb ServicesAssignment 5a-c (due next week)

Page 2: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

2

3

Summary of Previous SessionSummary of Previous SessionApplications of XML to Database Technology

XML Query Languages XPathXML Queries

XQuery: A Query Language for XMLXML Query EnginesXML Registries APIWeb Services Support in J2EE / .NetAssignment 5a+5b

4

Part I

XML Object Persistence

Also See:

http://www.rpbourret.com/xml/XMLAndDatabases.htm

Page 3: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

3

5

• Need for objects to exist beyond an application’s lifetime

Data StoreApplication

ObjectsObjectsObjects

Object Persistence

• Limitations of the OOP / RDBMS direct coding approach– Difficult to handle data structure changes– Difficult to reuse persistence logic

• Solution is to use a “Persistence Framework”

6

Direct JDBC

• JDBC is NOT a Persistence Framework– JDBC is a database

connection utility– Ok for “Window on data”

style application– Ok when business logic is

entrenched on databaseSQLrows

JDBC

Application

Page 4: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

4

7

XML Object Persistence(“SOAP Competitors" in http://www.cis.ohio-state.edu/rsrg/ase/colloquia/craig-swartout-xml.pdf)

Started as SODL and XMOPSimple Object Definition LanguageXML Metadata Object Persistence

XML and JavaBeans interoperability (e.g., BML, Coins, etc.)XML and EJB integrationXML serialization for Java (e.g., Koala, etc.)SOAP - XML-RPC protocol

Ability to invoke (persistent) objects’ methods remotely

8

• Example Project: XSU (www.cis.ksu.edu/~htu3434/presentation.ppt) – Transform data retrieved from object-relational database

tables into XML – Extract data from a XML document and insert the data into

the appropriate columns/attributes of a table – Extract data from a XML document and apply this data to

updating or deleting values of the appropriate columns/attributes

• Implementation– DB: Oracle 9i Release 1 Server– XSU Utility/Tool + Castor– Alternatives to Castor:

XML DB (Oracle 9i Release 2)http://abra.sourceforge.net/doc/javadoc/org/ephman/abra/tools/Marshaller.html

Transferring Data Between Databases and Java Objects via XML

Page 5: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

5

9

XSU

Oracle 9iSampleData XML

document

Castor XML

Java classes

Objects

XSU Architecturewww.cis.ksu.edu/~htu3434/presentation.ppt

10

• Enables full separation of business and persistence logic

• Easily customizable for different applications

• Enables added functionality (e.g., object caching)

Persistence Broker Design Patternwww.lap.ttu.ee/erki/failid/konspekt/bakalaureusetoo/defence.ppt

Page 6: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

6

11

Database

User Interface Classes

Business classes

Persistence Broker

Cache

Database

User Interface Classes

Business classes

Simple architecture Using a Persistence Broker

Persistence Broker Architecture

12Database

PersistenceBroker

ReflectionPersistence Mapping

Cache

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

Query Mechanism

ApplicationApplicationApplications

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjectsIdentities

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

Field Values

PersistentObjects

PersistentObjects

Field Values

PersistentObjects

PersistentObjectsSELECT Results

PersistentObjects

PersistentObjectsACTION Queries

PersistentObjects

PersistentObjectsSELECT Queries

Conversion

PersistentObjects

PersistentObjects

Field Values

PersistentObjects

PersistentObjects

Persistent Objects

PersistentObjects

PersistentObjectsQueries

PersistentObjects

PersistentObjects

Field Values

PersistentObjects

PersistentObjectsColumn Values

Storing and deleting

Handles executing SQL statements

Converts object field values to table column

values and vice versa

Contains mappings between classes and tables

Caches persistent objects

Accesses object fields dynamically

Looking up cached instances

Deleting storage and deletion

PersistentObjects

PersistentObjects

PersistentObjects

Delegating queries from the application

to lower level

Specifying the field values of objects to

store or deleteReturning the field values for retrieved

objects

PersistentObjects

PersistentObjects

Field Values

Specifying the criteria field values

Retrieving

Database-specific SQL queries

PersistentObjects

PersistentObjectsQueries

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

PersistentObjects

Page 7: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

7

13

Object Persistence Layer in J2EEhttp://www.jfs2003.de/folien/A6_Clarke_Oracle.PPT

• Abstracts persistence details from the application layer

SQLrows

Objects

Persistence Layer

Objectsobject-level

querying and creationresults are objects

results arereturned as

raw data

API uses SQLor databasespecific calls

object creation and updates through object-level API

J2EE & Web

Services

JDBC

14

TopLink Runtime Architecture

Data Source

TopLinkApplication

Application Server

Session

Data A

ccess

Mappings

JDB

C

J2EE Container

JTACMP/BMP

Cache

Query

TXEntitiesJava

Objects

EJB Entity Beans

JSP,Servlet,Struts,

etc.

AppLogic

Page 8: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

8

15

TopLink & XML / J2EE

• XML documents can be represented at different levels of abstractions in J2EE applications:

– Parsed document (DOM, SAX …) - parser– Unmanaged Java objects from non-transactional data

source – data converter– Managed Java objects from a transactional data

source – persistence manager• Developers do not need to work with low level

XML documents and manually code persistence manager functionality

16

Three Levels of XML Representation

XML ParserO-X Data Converter

XMLDocument

UnmanagedObject

Persistence Manager

XDB EIS

JDBC J2C

DOM ManagedObject/EJB

File

WebService BPM JMS

Page 9: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

9

17

Sun JDO

• Java Data Objects (JDO) • First standardized, completely object oriented

approach to object persistence.• Developed as Java Specification Request 12

under the support of the Java Community Process.

• Application programmers can use JDO to directly store their Java domain model instances into the persistent store.

• JDO fills a large gap in the area of database programming.

18

Benefits of Using JDO

• Transparent persistence• Database independence • Portability • Ease of use • High performance • Integration with EJB

Page 10: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

10

19

JDO Architecture

20

Software Stacks Supported

MyApplication Persistence Manager(XJDO

Implementation)

Java-based Data Store Access

(eXist XML DB Driver Class Impl)

Data Store(eXist Native XML

DB)

MyApplication Persistence Manager(LiDO JDO

Implementation)

Java-based Data Store Access

(mysql-connector-java-2.0.14)

Data Store(My SQL)

MyApplication Persistence Manager(LiDO JDO

Implementation)

Java-based Data Store Access

(LIBeLIS file db connector)

Data Store(LIBeLIS' FileDB)

Page 11: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

11

21

eXist Native XML DBhttp://exist.sourceforge.net/

• eXist is an Open Source, native XML DB• eXist features

– Completely written in Java– Lightweight– Efficient– Index-based XPath query processing– Extensions for keyword search– Tight integration with existing XML development tools– Can be deployed two ways:

• A stand-alone server process, inside a servlet-engine • Directly embedded into an application.

• Other popular native XML DB: Apache Xindice– http://xml.apache.org/xindice/

22

Object Instance Returned toApplication Developer

eXist XML Database

<xobj package=”xobj.test.beans”class=”Person”><field name=”firstName”value=”Luann”/><field name =”lastName”value=”Ahrens”/>

ElementName=”xobj”

AttrPackage=“xjdo.test.beans”

xjdo.test.beans.PersonfirstName=”Luann”lastName=”Ahrens”address=”555 NoWhere St.”

XML Document Stored in XML Database

Document object when retrieved from XML database as DOM

Conversion Process for Retrieved Objectshttp://students.depaul.edu/~lahrens/se690/deliver/XJDO-Final%20Pres.ppt

org.w3c.Document

Page 12: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

12

23

XJDO and XSLT Compatibility

• Possible to use the data in XML data base for other means without using the XJDO application

• Data can be accessed by other than via Java applications using XJDO

• Using XSLT and XPath, the XJDO XML format can be transformed to a different XML format

<xobj package=“xjdo,test.beans” name=“Person”><field name=“fName” value=“Luann”/><field name=“lName” value=“Ahrens” /><field name=“address” value=“555 NoWhere St.” />

</xobj>

<xjdo.test.beans.Person><firstName>Luann</firstName><lastName>Ahrens</lastName><address>555 NoWhere St.</address>

</xjdo.test.beans.Person>

XSLT Transformation

24

Part II

Advanced XQuery Concepts

Page 13: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

13

25

XQuery Today• XQuery: The W3C XML Query Language• DOM+XPath+XSLT applications can now be

implemented in just one language: XQuery • XQuery is expressive, concise, easy to learn• XQuery is implementable, and optimizable• XQuery supports integration of data from

multiple sources• Several implementations of XQuery are

currently available• XQuery provides preliminary support for update

26

XQuery Design Goals

• Language Expressive power– Functionality derived from XML-QL, XQL, SQL, OQL– Applicable to the many different types of XML data– Implementation based on published use-cases

• XQuery Engine Implementations– Can be implemented on top of traditional databases,

XML repositories, XML programming libraries, etc.– Queries may combine data from many sources

• Minimalist design– Small, easy to understand, clean semantics

Page 14: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

14

27

Querying Heterogeneous Data

DOM

SAX

DBMS

XML

Java

COBOL

DOM

SAX

DBMS

XML

Java

COBOL

XQuery

W3C XML Query Data Model

W3C XML Query Data Model

28

XQuery Expressions

• XQuery is a functional language– Each query is an expression– Expressions can be easily combined

• Structure of a query– Namespace declarations (optional)– Function definitions (optional)– Query expression: may include many expressions

Page 15: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

15

29

XQuery Expressions

• Path expressions: /a//b[c = 5]• FLWR expressions: FOR ... LET ... WHERE ... RETURN• Element constructors: <a> ... </a>• Variables and constants: $x, 5• Operators and function calls: x + y, -z, foo(x, y)• Conditional expressions: IF ... THEN ... ELSE• Quantifiers: EVERY var IN expr SATISFIES expr• Sorted expressions: expr SORTBY (expr ASCENDING , ... )• Updates expressions: INSERT, REPLACE, DELETE

30

Sample Document<books>

<book year=“2002"> <title>XML and Java</title><author>

<last>Maruyama</last><first>H.</first>

</author> <publisher>Addison- Wesley</publisher> <price> 34.99</price>

</book></books>

Page 16: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

16

31

Element Constructors# Element constructors look like the XML they construct

<book year=“2002"> <title>XML and Java</title><author>

<last>Maruyama</last><first>H.</first>

</author> <publisher>Addison- Wesley</publisher> <price> 34.99</price>

</book>

32

Path Expressions

<books> <book year=“2002">

<title>XML and Java</title><author>

<last>Maruyama</last><first>H.</first>

</author> <publisher>Addison- Wesley</publisher> <price> 34.99</price>

</book></books>

# XQuery uses the abbreviated syntax# of XPath for path expressions

document(“books.xml”)

/books/book/author

//author[last=“Maruyama” and first=“H.”]

document(“books.xml”)//author

Page 17: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

17

33

Path Expressions - Extensions# Range expressions/books/book/author[1 TO 2]

# BEFORE and AFTER//book[ author[last=“Maruyama”] BEFORE

author[last=“Clark”] ]

# NamespacesNAMESPACE rev = "www.xmlsoftware.com”//rev:rating

# Dereference//publisher/web/@href->html

34

FLWR Expressions

• FOR - LET - WHERE - RETURN• Similar to SQL’s SELECT - FROM - WHERE

FOR $book IN document("books.xml")//bookWHERE $book/publisher = "Addison-Wesley"RETURN

<book>{

$book/title,$book/author

}</book>

Page 18: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

18

35

FOR vs. LET

• FOR iterates on a sequence, binds a variable to each node• LET binds a variable to a sequence as a whole

FOR $book IN document("books.xml")//bookLET $a := $book/authorWHERE contains($book/publisher, "Addison-Wesley”)RETURN

<book>{

$book/title,<count> Number of authors: { count($a) } </count>

}</book>

36

Inner Joins

FOR $book IN document("www.books.com/bib.xml")//book,$quote IN document("www.amazon.com/quotes.xml")//listing

WHERE $book/isbn = $quote/isbnRETURN

<book>{ $book/title }{ $quote/price }

</book>SORTBY (title)

Page 19: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

19

37

Outer Joins

FOR $book IN document("books.xml")//bookRETURN

<book>{ $book/title }{

FOR $review IN document("reviews.xml")//reviewWHERE $book/isbn = $review/isbnRETURN $review/rating

}</book>

SORTBY (title)

38

Combining Expressions<bibliography>{FOR $book IN document("books.xml")//bookRETURN

<book>{

$book/author, $book/title

}</book>

SORTBY (author, title)}</bibliography>

Page 20: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

20

39

Combining Expressions

<bibliography>Expression

</bibliography>

40

Combining Expressions

<bibliography>Expression

</bibliography>

Can be extended as:

<bibliography>{

FOR $book IN ExpressionRETURN

Expression}</bibliography>

Page 21: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

21

41

Combining Expressions(continued)

<bibliography>{FOR $book IN ExpressionRETURN

<book>{

Expression, Expression

}</book>

SORTBY (Expression, Expression)}</bibliography>

42

<bibliography>{FOR $book IN document("bib.xml")//bookRETURN

<book>{

$book/author, $book/title

}</book>

SORTBY (author, title)}</bibliography>

Combining Expressions(example)

Page 22: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

22

43

Functions

• Built-in functions– max(), min(), sum(), count(), avg()– distinct(), empty(), contains()– the normative set has not yet been fixed

• User-defined functions– Defined in XQuery syntax– May be recursive– May be typed

• Extensibility mechanisms will be added

44

Functions(continued)

FUNCTION depth(ELEMENT $e) RETURNS integer{

-- An empty element has depth 1-- Otherwise, add 1 to max depth of childrenIF empty($e/*)

THEN 1ELSE max(depth($e/*)) + 1

}

depth(document("partlist.xml"))

Page 23: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

23

45

Data Types

• W3C XML Schema simple types – string "Hello" – boolean true, false – integer 47, -369 – float -2.57, 3.805E-2

• Type constructor functions– date("2000-06-25")

• Operators and functions to be defined...

46

Bibliography Example<?xml version="1.0"?><books>

<book><title> XML and Java </title><author>

<lastname> Maruyama </lastname><firstname> Hiroshi </firstname>

</author> <pubinfo>

<publisher> Addison Wesley </publisher><price> 34.99 </price><year> 2002 </year>

</pubinfo></book>

</books>

Page 24: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

24

47

Books by Author

<?xml version="1.0"?><books>

<book><title> XML and Java </title><author>

<lastname> Maruyama </lastname><firstname> Hiroshi </firstname>

</author> <pubinfo>

<publisher> Addison Wesley </publisher><price> 34.99 </price><year> 2002 </year>

</pubinfo></book>

</books>

<booksByAuthor><author>

<name><last> Maruyama </last><first> Hiroshi </first>

</name><book> XML and Java (1st Edition) </book><book> XML and Java (2nd Edition) </book>

<author>. . .

</booksByAuthor>

48

Inverting the Hierarchy

<?xml version="1.0"?><books>

<book><title> XML and Java </title><author>

<lastname> Maruyama </lastname><firstname> Hiroshi </firstname>

</author> <pubinfo>

<publisher> Addison Wesley </publisher><price> 34.99 </price><year> 2002 </year>

</pubinfo></book>

</books>

FOR $a IN distinct(document(“books/books.xml")//book/author)LET $b := document(“books/books.xml")//book[author = $a]RETURN

<book>{ $a }{ $b/title SORTBY (.) }

</book>SORTBY(author/last, author/first)

Page 25: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

25

49

INSERT, DELETE, REPLACE

• INSERTFOR $e IN /emp

INSERT <n_skills> count($e/skill) </n_skills> BEFORE $e/skill[1]

• REPLACEFOR $e IN /emp

WHERE $e/empno = "1234”REPLACE $e/job WITH <job> “Software Architect"</job>

50

INSERT, DELETE, REPLACE(continued)

• DELETE

FOR $e IN /emp/[job = "Programmer"],$s IN $e/skill

WHERE $s/rating < 4OR $s/cert_date < date(“2000-01-01")

DELETE $s

Page 26: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

26

51

Current Limitations on Update

• No distributed update - single data source• No updates on views

52

Advanced XQuery Concepts

Mainstream XQuery EnginesSoftware AG’s QuiP

http://developer.softwareag.com/tamino/quip/

H. Katz XQEnginehttp://www.fatdog.com

API for XML Databaseshttp://www.xmldb.org/xapi/

Supported in eXist and ozone-db

Experiment with Complex Queries and QuiP

Page 27: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

27

53

XQuery Additional Information

• W3C XQueryhttp://www.w3.org/TR/xquery.html

• W3C XML Query Use Caseshttp://www.w3.org/TR/xmlquery-use-cases.html

• W3C XML Query Requirements http://www.w3.org/TR/xmlquery-req.html

• W3C XML Query Data Modelhttp://www.w3.org/TR/query-datamodel.html

• W3C XML Query Algebrahttp://www.w3.org/TR/query-algebra.html

54

Part III

Presentation-Oriented PublishingFrameworks

Page 28: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

28

55

POP FrameworksClient-Side POP

IE5Server-Side POP

Cocoon & XSPRocketCPAN’s Perl Framework

Referenceshttp://www.runtime-collective.com/JavaXML.htmlhttp://www.andrena.de/Objektforum/Archiv/Download/2002-10-ka-PortalsWithArachne3.pdf

56

Apache Cocoonhttp://xml.apache.org/cocoon

• XML based publishing Framework• An Apache Software Foundation open source project• Written in Java, runs mostly as a servlet• Started as a simple servlet based XSL styling engine

for http://java.apache.org site• Current version is in the second generation of

evolution• Designed for scalability ( uses SAX processing ) --

can process huge documents using small amount of memory

Page 29: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

29

57

Apache Cocoon(continued)

• Cocoon promotes the separation of Content, Logic, Presentation and Management in web-site design.

58

Cocoon ServletDirs. & FilesDirectory for auto mountingsub-sitemaps

Cocoon Configuration file

A sub-sitemap directory

Main sitemap file

Directory for log files

Page 30: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

30

59

Cocoon Sitemap

• Sitemap Goal– Used to de-couple the exposed URI space from the

actual location of resources– Allows easily changeable specification of

processing steps

• Sitemap Contents– Component declarations

• generators, transformers, serializers, ...

– Resource declarations• named collection of pipeline components

– Pipeline declarations• sequential arrangement of components for processing

60

Cocoon Sitemap(continued)

• A sitemap is an XML file• Sitemaps are hierarchical -- A sitemap

can point, explicitly or implicitly, to sub-sitemaps

• A sitemap is translated into a java program and is compiled into bytecode

• Changes to sitemaps can be loaded dynamically and asynchronously

Page 31: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

31

61

Sample Cocoon Pipeline<map:pipeline>

<map:match pattern="hello.html"><map:generate src="docs/samples/hello-page.xml"/><map:transform src="stylesheets/page/simple-page2html.xsl"/><map:serialize type="html"/>

</map:match>

<map:match pattern="images/**.png"><map:read src="resources/images/{1}.png" mime-type="image/png"/>

</map:match>

<map:handle-errors><map:transform src="context://stylesheets/system/error2html.xsl"/><map:serialize status-code="500"/>

</map:handle-errors></map:pipeline>

62

Cocoon Request Processing

• Request is dispatched to matching pipeline• Basic pipeline operation

– The generator generates XML content– Zero or more transformers transform the content– The serializer writes it to the output stream

• Different Kinds of generators– File, Directory, XSP, JSP, Stream, …

• Different Kinds of transformers– XSLT, I18N, Log, …

• Different Kind of Serializers– HTML, XML, Text, PDF, SVG, ...

Page 32: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

32

63

Dynamic Content Generation from XSP

<!-- A simple XSP Page --><xsp:page language="java”

xmlns:xsp=“http://apache.org/xsp” ><page>

<title>A Simple XSP Page</title><content><para>dynamically generated

list:</para><ul><xsp:logic>

for (int i=0; i &lt; 3; i++) { <li> Item

<xsp:expr>i</xsp:expr></li>

} </xsp:logic></ul></content>

</page></xsp:page>

64

Part IV

Web Services

Page 33: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

33

65

Web Services Summary

• Web Services are– described in WSDL– exchange SOAP messages– use HTTP as transport– optionally, registered in UDDI registry

• Interaction can happen using RPC style or Document Exchange style, synchronously or asynchronously

• Knowledge of Implementation language or deployment platform is not required for interaction.

• Web Services promise Interoperability.

66

SOAP Summary

• XML based protocol for exchange of information– Encoding rules for datatype

instances– Convention for representing

RPC invocations• Designed for loosely-coupled

distributed computing• Used with XML Schema• Transport independent• SOAP with Attachments allow

arbitrary data to be packaged.

SOAP Message StructureSOAP Envelope

[HeaderElement]

HeaderEntries

Body Element

[FaultElement]

Page 34: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

34

67

WSDL Summary

• A WSDL document describes– What the service can do– Where it resides– How to invoke it

• WSDL are like IDL but lot more flexible and extensible

• Defines binding for SOAP, HTTP GET/POST and MIME

• WSDL descriptions can be made available from an UDDI registry

WSDL Document StructureWSDLDocument

{Messages}

[Types]

{Services}

{PortTypes}

{Bindings}

68

Web Services Platform

Environment, tools, libraries and other resources for:– Development of web services

• top down -- start with user code and generate WSDL• bottom up -- start with WSDL and generate interfaces• middle out -- a combination• discovery of service interfaces

– Deployment of web services• publishing of services• pre and post processing of SOAP requests, responses• processing requests for WSDL descriptions

– Consumption of Web Services• discovery of Web Service• invocation of/interaction with Web Services

Page 35: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

35

69

Java Platforms and Standards

• Java Platforms for Web Services– Apache SOAP 2.2, Apache Axis, UDDI4J, Cocoon– JWSDK ( Reference Implementation from Sun )– etc.

• Java Standards for Web Services– JAXM ( Java XML Messaging )– JAX-RPC ( Java Web Service Client Prog. model)– JSR 109 ( Java Web Service Prog. Model, deployment, ...)– JAXR ( Java API to access Web Service Registries )– J2EE 1.4 ( J2EE platform for Web Services )

• Java standards promise portability

70

Current State of Java Platforms and Standards

• Handle synchronous RPC style Web Services quite well

• Not so good at supporting Web Services with document exchange style, especially with asynchronous interface

• Have difficulty dealing with large data• Many approaches to build and consume Web Services

( but must adhere to wire protocols )• Standards in many areas are still emerging

– routing, reliable messaging– security– transactioning– ...

Page 36: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

36

71

Using Cocoon as a Presentation Framework for Web-Services

www.pankaj-k.net/sdwest2002/Cocoon-FWS.ppt

Client Tier Web Tier

Web Services

WS Registry

Enterprise Apps

Servlet Container

Cocoon

72

Cocoon as a Processing Framework for Web Services

(continued)

Client Tier Web Tier

Web Services

WS Registry

Enterprise Apps

Servlet Container Cocoon

P1P2

Page 37: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

37

73

Sample Implementation• Use Google Web Services API from

http://www.google.com/apis to create a simple web application that accepts a search string from user and displays the list of result entries.

• Sample is based on the XSP contributed by Ugo Cei in Cocoon-dev mailing list

• Application components:• sitemap.xmap -- Sitemap for this application• index.html -- HTML file to accept search string• google.xsp -- XSP file that makes the SOAP call to Google

Web Service using SOAP logicsheet.• search-results.xsl -- XSL stylesheet to transform SOAP

response from Google Web Service to HTML page

• Downloadable from:• http://www.pankaj-k.net/sdwest2002/google.zip

74

Application Architecture

Browser Google WSCocoon Servlet

http://<host>/cocoon/mount/google/

index.html

…/search?q=...

executes google.xsp

SOAP request

SOAP response

Search results in HTML

Maps request to index.html

Applies search-results.xsl

Page 38: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

38

75

Part V

Conclusions

76

SummaryBindings approaches are currently implemented between XML and JavaBeans/EJBsSoftware AG’s Quip implements complex query processing as per XQuery 1.0Server-side POP is the approach of choice for XML processing

Page 39: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

39

77

ReadingsReadings

XML and Java: Chapter 11, Appendix D

Developing Java Web Services: Chapters 6, 9, 11-14Handouts posted on the course web site

Project Frameworks Setup (ongoing)Howard Katz’s XQEngine, Software AG’s QuiPApache’s Web Server, TomCat/JRun, and CocoonApache’s Xerces, Xalan, SaxonAntenna House XML Formatter, Apache’s FOP, X-smilesPublishing Systems at http://www.xmlsoftware.com

Visibroker 4.5 (or BES 5.2.1), WebLogic 6.1-8.1, WAS 5.0POSE & KVM (See Session 3 handout)

78

Assignment

Assignment #5:#5a+b continued from last week#5c: This part of the project focuses on the discovery/design/development of the application presentation layer architecture using XML-Based presentation frameworks. The discovery/design/development process should adhere to the following steps: (a) Determining how W3C recommendations will be applied (e.g., determine when DOM is appropriate, etc.), (b) Using the details and syntax of core W3C recommendations (XML, XSL, DOM, XPath, namespaces, DTDs, XML well-formedness, Schemas, etc.), (c) Refining the application presentation layer architecture design as necessary based on data model, data integration, data rendering, and data query issues

Page 40: g22 3033 002 c101 - NYU · 1 1 XML for Java Developers G22.3033-002 Session 10 - Main Theme XML Information Retrieval (Part II) And XML-Based Frameworks (Part I) Dr. Jean-Claude Franchitti

40

79

Assignment(continued)

Assignment #5:#5c: This part of the project also focuses on the discovery/design/development of the non-presentation specific application architecture using XML-Based frameworks. The discovery/design/development process should follow the same steps as the ones listed in assignment #5a. Additionally, particular care should be taken at determining the implications of a given architecture on the overall XML design related considerations

More specific project related information, and extra credit assignments will be provided during the session

80

Next Session:XML-Based Frameworks (Part II)

and Additional XML Services

XML and Application ServersPresentation Oriented Publishing (POP) FrameworksMessage Oriented Middleware (MOM) FrameworksWeb ServicesXML MessagingXML Security