Upload
howell
View
92
Download
5
Embed Size (px)
DESCRIPTION
J2EE and The Next Generation. 内容列表. 1 XML and J2EE 1.3 2 Web Service and J2EE 1.5 3 Java EE 5.0 4 J2EE vs .NET 5 小结. 1 XML & J2EE 1.3. XML DTD, Schema XML Parser J2EE 1.3. [01] [11] [12] - PowerPoint PPT Presentation
Citation preview
J2EE and The Next Generation
内容列表
1 XML and J2EE 1.3 2 Web Service and J2EE 1.5 3 Java EE 5.0 4 J2EE vs .NET 5 小结
1 XML & J2EE 1.3
XML DTD, Schema XML Parser J2EE 1.3
[01] <?XML version="1.0" standalone="yes"?>
[11] <Students Class=”SY9061”>
[12] <Student SId="12345">
[13] <Name>Lin</Name>
[14] <Age>20</Age>
[15] </Student>
[16] <Student SId="12345">
[17] <Name>Lin</Name>
[18] </Student>
[19] </Students>
What Is XML?
XML was developed by an XML Working Group of the World Wide Web Consortium (W3C) in 1996
It was chaired by Jon Bosak of Sun Microsystems
XML is a family of technologies: XSL, XSLT, XPath, Xlink, Xpointer, DOM, etc.
XML is license-free, platform-independent and well-supported
The eXtensible Markup Language (XML) is the universal format for structured documents and data on the Web
As with HTML, you identify data using tags (identifiers enclosed in angle brackets, like this: <...>)
The tags are called "markup" But unlike HTML, XML tags tell you what the
data means, rather than how to display it
XML Document
A data object is an XML document if it is well-formed, as defined in XML specification
A well-formed XML document may in addition be valid if it meets certain further constraints
The document is composed of declarations, elements, comments, character references, and processing instructions, all of which are indicated in the document by explicit markup
Well-Formed XML Documents
A "Well Formed" XML document has correct XML syntax
A textual object is a well-formed XML document if it has the correct XML syntax: It contains one or more elements There is exactly one element, called the root, or
document element The name in an element's end-tag must match the
element type in the start-tag; Names are case-sensitive Each of the parsed entities which is referenced directly
or indirectly within the document is well-formed
XML Document Contents
Processing Instructions XML declaration Elements
Tags: Start-Tags, End-Tags Attributes Empty-Element Tags PCDATA CDATA White Spaces
Comments
Prolog
Content
序言
XML 声明: XML 文档应该以 XML 声明作为文档的开始,声明中指
定了版本、编码等信息 文档类型声明:
DOCTYPE 声明必须位于 XML 声明之后,且在任何文档元素之前。但是, XML 声明和 DOCTYPE 声明之间可以插入注释和处理指令。
混合项 注释 处理指令 空白字符
主体
XML 文档的主体是文档元素,每个 XML 文档都有且仅有一个文档元素,文档元素可以包含子元素(多个)。
尾声
包括注释、处理指令、与 / 或空白 ,即序言中的混合项
An Example XML Document
<?xml version="1.0" encoding="ISO-8859-1"?><tradeBatch>
<trade account="2520034" action="buy" Duration = "good-till-canceled">
<symbol>SUNW</symbol><quantity>1000</quantity><limit>20</limit><date>2001-03-05</date>
</trade><trade account="9240196" action="sell" duration="day">
<symbol>CSCO</symbol><quantity>500</quantity><date>2001-03-05</date>
</trade></tradeBatch><!-- This is a comment -->
有效的文档
有效的文档: 格式良好 包含文档类型声明 文档实例符合文档类型声明的约束。有效的文档:
有效性约束的两种方法: DTD Schema
DTD
文档类型定义 (Document Type Definition ,DTD) 是 XML 1.0 规范的一部分
DTD 可以定义词汇和词汇之间的语法规则,从而定义 XML 文档的结构。
1: <?XML version="1.0" standalone="yes"?>2: <!DOCTYPE Students [4: <!ELEMENT Students (Student+)>5: <!ATTLIST Students Class CDATA #REQUIRED>6: <!ELEMENT Student (Name, Age?)>7: <!ATTLIST Student SId CDATA #REQUIRED>9: <!ELEMENT Name (#PCDATA)>13: <!ELEMENT Age (#PCDATA)>18: ]>19: <Students Class=”SY9061”>20: <Student SId="12345">21: <Name>Lin</Name>22: <Age>20</Age>23: <Address>24: <Country>China</Country>25: <City>BeiJing</City>26: </Address>27: </Student>28: <Student SId="12345">29: <Name>Lin</Name>30: </Student>31: </Students>
DTD 各要素
ELEMENT – 元素 元素类型声明
ATTLIST 特定元素类型可设置的属性及这些属性的允许值声明
ENTITY 可重用的内容声明
NOTATION 不需要解析的外部内容(例如:二进制数据)的格式声明,
以及用于处理这些内容的外部应用程序
DTD 与文档的关联
DOCTYPE 标记 内部 DTD 子集
<!DocType catalog[… 内部声明 … ]> 外部 DTD 子集
<!DOCTYPE catalog SYSTEM “http://myserver/decs/pubcatalog.dtd”>
有效性验证
利用 D T D 和验证有效性的解析器,就能够立即对文档的完整性进行可靠的检查 。如果某个 X M L 文档引用了 D T D ,验证有效性的解析器应该读取 D T D ,并确保文档符合 D T D 中描述的语法
DTD 的缺点
DTD 有自己的特殊的语法,本身不是 XML 文档因此,我们编写 XML 文档时,需要使用两套解析器:一套用来分析 XML ,判断文档是否格式良好;另一套用于分析 DTD ,再用分析的结果去检查 XML 文档,判断 XML 是否有效。
DTD 只提供了有限的数据类型 结构封闭,不具备扩展性。 DTD 不支持名域机制,
因此,每个 XML 文档只能有一个 DTD ,从而限制了XML 文档的继承和重用。
2: <!DOCTYPE Students [4: <!ELEMENT Students (Student+)>5: <!ATTLIST Students Class CDATA #REQUIRED>6: <!ELEMENT Student (Name, Age?)>7: <!ATTLIST Student SId CDATA #REQUIRED>9: <!ELEMENT Name (#PCDATA)>13: <!ELEMENT Age (#PCDATA)>18: ]>
! 定义元素和内容模型
1: <?XML version="1.0" standalone="yes"?>19: <Students Class=”SY9061”>20: <Student SId="12345">21: <Name>Lin</Name>22: <Age>20</Age>23: <Address>24: <Country>China</Country>25: <City>BeiJing</City>26: </Address>27: </Student>28: <Student SId="12345">29: <Name>Lin</Name>30: </Student>31: </Students>
[01]<xsd:schema xmlns:xsd=http://www.w3.org/2000/08/XMLSchema[02] targetNamespace=”http://cscw.buaa.edu.cn/Schema-Stud”>
[03] <xsd:element name="students" type="StudentsType"/>
[09] <xsd:complexType name="StudentsType">[10] <xsd:sequence>[11] <xsd:element name="student" type="StudentType" maxOccus=”unbounded”/>[12] </xsd:sequence>[13] <xsd:attribute name="class" type="xsd:NMTOKEN"/>[14] </xsd:complexType>[15] <xsd:complexType name="StudentType">[16] <xsd:sequence>[17] <xsd:element name="name" type="xsd:string"/>[18] <xsd:element name="age" type="xsd:int" minOccus=”0”/>[19] </xsd:sequence>[20] <xsd:attribute name="sId" type="xsd:NMTOKEN"/>[21] </xsd:complexType>[22]</xsd:schema>
! 声明元素
! 定义类型
! 名域声明
Schema 的基本概念
类型定义 元素声明 名域 ……
类型定义<xsd:complexType name="StudentType"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="age“ type="xsd:int“ minOccus=”0”/> </xsd:sequence> <xsd:attribute name=“sId“ type="xsd:NMTOKEN"/></xsd:complexType>
Class StudentType{String name;int age;String sid;
}
元素声明元素声明 元素声明:<xsd:element name=“age" type=”xsd:int”/>对应于 java 中的变量声明:
int age;
属性声明:<xsd:attribute name=“b" type="xsd:NMTOKE
N“ use="fixed" value="US"/> 对应于 Java 的变量声明
NMTOKEN b;
Namespace
Namespace Schema 中通过元素 <schema> 的属性 targetN
amspace 指定名域 :targetNamespace=“http://www.example.co
m/PO1”
Namespace 对应于 Java 中的 package ,如: package cscw.mypackage
( C#没有 package ,改成 namespace )
Schema
Java 程序是类的集合, Schema 是类型定义和元素声明的集合 ,因此, Schema 可以类比于 Java 程序
XMLXML 文档实例文档实例 元素实例
– 进一步类推,可以得出 XML 文档的元素实例类比于 Java 中的类实例:
student = new StudentType();– XML 文档元素与 Java 类实例的类比是差别最大
的类比关系:前者是静态的文档,以字符形式存在;后者是程序的动态运行,以二进制形式存在于内存中。其实这个差别正是 XML得以广泛应用的原因之一:二进制的数据很难在网络的不同应用之间传递,而文本数据则很容易。
文档实例– XML 文档实例类比于运行中的 Java 程序。
SchemaSchema 与与 JavaJava 类比汇总类比汇总
XML Schema/Namespace
类型定义 元素声明 文档实例 /实例元素
Java 程序 /package
类 (class)
变量声明 程序 / 类实例
Schema 与 XML 文档的关联
[01]<?xml version="1.0"?>[02]<students [03] xmlns:stud=”http://act.buaa.edu.cn/Schema-Stud”[04] class=”SY9061”>[05] <student SId="12345">[06] <name>Lin</name>[07] <age>20</age>[08] </student>[09] <student sId="345657">[10] <name>Li</name>[11] </student>[12]</students>
Schema 的优点
本身是 XML 文档
内建丰富的数据类型;可以方便地定义数据类型
支持名域 (namespace)
XML 文档的处理 回调
回调是作为一种事件驱动模型工作的。当分析 XML 文档时,某些事件将触发回调方法。
SAX ,用于 XML 的一种简单 API ,是这种 XML 使用方法的事实上的标准。
树 根据 XML 文档,创建对应的树状结构。 最流行的 API 是文档对象模型 (DOM)。
数据绑定 将 XML Schema 编译成一个或多个 Java 类,其后, X
ML 对象和 Java 对象可以相互转换。 Sun 公司的 DataBinding
SAX——Simple API for XML
SAX ( Simple Application interface for XML) 接口规范是 XML 分析器和 XML 处理器提供的较 XML 更底层的接口。
SAX 诞生是在 XML-DEV 讨论组上,提出它的原因是有一些情况不适用 DOM 接口,而且 DOM 实现太大而且比较慢。
SAX 是一种事件驱动的接口,它的基本原理是,由接口的用户提供符合定义的处理器, XML 分析时遇到特定的事件,就去调用处理器中特定事件的处理函数。一般 SAX 都是 JAVA 的接口,但其实 C++ 也可以用 SAX 接口,但 C++ 的分析器比较少。
Parsing Reading and well-formed'ness checking and validating
Event-driven Parser You provide the event Handler Sequential read access only => one-time access
Fast and Lightweight Documents does not have to be entirely in memory Does not support modification of document
Started as a Community-driven project org.xml.sax
SAX is free!
SAX Example
<?xml version="1.0"?><doc>
<para>Hello, world!</para></doc>
An event-based interface will break the structure of this document down into a series of linear events:
start documentstart element: docstart element: paracharacters: Hello, world!end element: paraend element: docend document
SAX 需要用户提供一下几个处理器类的实现: DocumentHandlerXML :文件事件的处理器; DTDHandler : DTD 中事件的处理器; ErrorHandler :出错处理器。
写程序就是以下这么几步了: 首先需要从这几个类继承出自己的子类, 重载其中自己感兴趣的事件的处理方法。 向分析器,注册此处理器类,其实告诉分析器使用你的处理
器。 启动分析器。
SAXParser parser=new SAXParser();
// 注册事件处理器
parser.setDocumentHandler(new MyDocumentHandler());
parser.setErrorHandler(new MyErrorHandler());
// 解析文档
try{
parser.parser(fn);
}catch(Exception e){
System.out.println(“Exception invoking parser.”);
}
DOM: Document Object Model The Document Object Model (DOM) is an
application programming interface (API) for processing well-formed and valid XML documents
It defines the logical structure of documents and the way a document is accessed and manipulated
With the Document Object Model, programmers can build documents, navigate their structure, and add, modify, or delete elements and content
DOM Example:Example table, taken from an HTML document<TABLE>
<TBODY><TR>
<TD>Shady Grove</TD><TD>Aeolian</TD>
</TR><TR>
<TD>Over the River, Charlie</TD><TD>Dorian</TD>
</TR></TBODY>
</TABLE>
DOM 规范定义了对象和接口的集合,通过他们可以访问和操作文档对象
DOM 定义了 12 种节点类型,有些类型的节点有不同的子节点,另外一些节点没有再低层的子节点,所有这些节点构成了树型结构,描述了文档的逻辑结构。 Document Element Attr Text
import java.xml.parsers.*;
import org.w3c.dom.*;
DocumentBuilderFactory factory=
DocumentBuilderFactory.newInstance();
factory.setValidating(true);
// 构造解析器DocumentBuilder builder = factory.newDocumnetBuilder();
// 解析文档,得到文档对象Document doc=builder.parse("mydoc.xml");
JAXB
Java Architecture for XML Binding JAXB provides a fast and convenient way to
create a two-way mapping between XML documents and Java objects
WARNING: Significant changes could occur between the current working draft and the final 1.0 specification
Motivations of JAXB
SAX and DOM Too low-level APIs
Requires XML knowledge Hard to program
You have to build your high-level Java objects yourself
Hard to maintain Schema change forces reprogramming
Forces a lot of coding Need for APIs that provide higher-level
abstraction
XML Binding——What Is It?
Map components of an XML document to in-memory objects
Object should represent intended meaning of document according to its schema
What should the classes be? Some cases obvious: String, Date, Vector. In general, classes should be generated directly
from the schema, i.e.: A Java. technology-level binding of the schema
Schema vs. Class
The Binding Framework Cycle
Others Namespace in XML XML Information set Canonical XML XPath XML Digital Signature XML Encryption XSL XSLT XPointer XLink XBase
Core Java APIs for XML
JAXP: Java API for XML Processing 1.1 available since March 2001
JAXB: Java Architecture for XML Binding Early Access available since June 2001
JAXP 1.1
Java Community Process initiative JSR-000063 A thin and lightweight Java API for parsing and
transforming XML documents Allows for pluggable parsers and transformers Allows parsing of XML document using:
Event-drive (SAX 2.0) Tree based (DOM Level 2)
Allows transforming XML document using: XSL and XSLT
JAXP Specification 1.1 http://java.sun.com/Download4
J2EE 1.3
J2EE 1.3 Increased XML integration, 2001 Support for JAXP1.1: SAX-2, DOM level 2,
XSLT XML view of JSP 1.2 Servlet filter in Servlet 2.3 : XSLT
transformation
2 Web Services & J2EE 1.4
XML RPC SOAP WSDL UDDI ebXML J2EE 1.4
XML RPC
Xml-rpc 是工作在 internet上的远程过程调用协议。
这种远程过程调用使用 http 作为传输协议, xml 作为传送信息的编码格式。
一个 xml-rpc消息就是一个请求体为 xml 的 http-post请求,被调用的方法在服务器端执行并将执行结果以 xml 格式编码后返回。
Request example Here's an example of an XML-RPC request:
POST /RPC2 HTTP1.0 User-Agent: Frontier5.1.2 (WinNT) Host: betty.userland.com Content-Type: textxml Content-length: 181
<?xml version="1.0"?> <methodCall> <methodName>examples.getStateName</methodName> <params> <param> <value><i4>41</i4></value> </param> </params> </methodCall>
Response example Here's an example of a response to an XML-RPC request:
HTTP1.1 200 OK Connection: close Content-Length: 158 Content-Type: textxml Date: Fri, 17 Jul 1998 19:55:08 GMT Server: UserLand Frontier5.1.2-WinNT
<?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse>
RMI VS RPC :在 RMI 和 RPC 之间最主要的区别在于方法是如何别调用的。 在 RPC 中,当一个请求到达 RPC服务器时,这个请求就包含了一个参数集和一个文本值,通常形成“ classname.methodname” 的形式。 这就向 RPC服务器表明,被请求的方法在为“ classna
me” 的类中,名叫“ methodname” 。 然后 RPC服务器就去搜索与之相匹配的类和方法,
并把它作为那种方法参数类型的输入。 这里的参数类型是与 RPC请求中的类型是匹配的。一旦匹配成功,这个方法就被调用了,其结果被编码后返回客户方。
What Is SOAP?
Simple Object Access Protocol Wire protocol similar to
IIOP for CORBA JRMP for RMI
XML is used for data encoding “Text” based protocol vs “binary” protocol
Supports XML-based RPC Runs over HTTP, SMTP
What SOAP Is Not
Not a component model So it will not replace objects and components, i.e.,
EJB, JavaBeans Not a programming language
. So it will not replace Java
Where Is SOAP?
SOAP 1.1 submitted as W3C note W3C XML Protocol working group
SOAP 1.2 draft spec in public review http://www.w3.org/TR/soap12/
Convergence with ebXML's Message Service SOAP with Attachments
SOAP tries to pick up where XML-RPC left off by implementing : user defined data types the ability to specify the recipient message specific processing control and other features.
SOAP Message Format
SOAP RPC Request Example
SOAP RPC Response Example
SOAP and Transports
Comes with a binding for HTTP Firewall path-through Request/Response model
Likely to include other transports SMTP, FTP, RMI/IIOP, JMS
SOAP RPC Request over HTTP
Java Programming API for SOAP
JAX-RPC (JSR-101) Java. API for XML-based RPC
JAXM (JSR-67) Java. API for XML Messaging Based on SOAP 1.1 and the SOAP
with Attachment specifications Supports higher-level and application-specific prot
ocols built on top of SOAP ebXML
WSDL (Web Services Definition Language) XML format for describing web services Web service is described as
A set of communication endpoints (or ports) capable of exchanging messages
Endpoint is made of . Abstract definitions of port types, operations
and messages Concrete binding to networking protocol and
message format
JSR 110: Java APIs for WSDL
Provides API support to: Create WSDL document programmatically Parse WSDL document (from XML) Query WSDL document
Will be used by: Client and server for dynamic lookup Containers to deploy and invoke services Development, deployment, and browser tools
UDDI (Universal Description, Discovery and Integration)
Programmatic registration and discovery of business entities and their Web services
Based on SOAP, XML, HTTP Registry data
Business registration Service type registration
JSR 93: Java. API for XML Registries API to expose heterogeneous/distributed XM
L registries: ebXML, UDDI, . Publish, subscribe, query, associate.
Web service metadata Schemas Business processes Documents ...
ebXML (Electronic Business XML)
ebXML Architectural Components Business Process and Information Modeling Registry Trading Partner Information Core Components and Core Library Messaging Service
Java Programming API for ebXML
JAXM (JSR-67) ebXML Message Service
JAXR (JSR-93) ebXML Registry
J2EE 1.4
J2EE 1.4, 2003 J2EE 1.4 里对于 Web Services 的支持包括:
Web services for J2EE 1.1 Java API for XML-based Remote ProcedureCall
s (JAX-RPC) 1.1 WS-I Basic Profile 1.0 SOAP with Attachments API for Java (SAAJ)1.2 Java APIs for XML Registries (JAXR) 1.0
Web Services
Service integration over the web Loosely coupled Enabled by XML An extension of the Web computing model
XML-based RPC XML Messaging
XML Based RPC
Standards SOAP 1.1 W3C XMLP
Java API JAX-RPC (JSR 101)
Model for the J2EE Platform JSR 109
XML Messaging
Standards Multipart MIME SOAP 1.1 with attachments The ebXML 1.0 Message Service W3C XMLP
Java API JAXM (JSR 63)
Model for the J2EE Platform EJB MDB with JAXM Connector
Rich Clients
Web Launching Java. Web Start software (JNLP)
Client/Server Communication HTTP Post XML-based RPC XML messaging
MIDP Clients
Provisioning clients as a service Device dependent aspects Business aspects Client Provisioning for the J2EE platform (JSR 12
4) Client/Server communication
HTTP Post
Browser Clients
JavaServer Pages. (JSP. ) specification, GUI Components GUI Component Architecture for Java Technology
based Server Apps (JSR 127.Java Faces)
Java APIs for Web Services
Service Description (WSDL) JSR 110 (Java API for WSDL) JAX−RPC
Service Registration and Discovery(UDDI, ebXML Reg/Rep) JAXR
Service Invocation (SOAP, ebXML Message Service) JAXM, JAX−RPC
Electronic business framework JAXM with ebXML Message Service (TR&P) profil
e JAXR with ebXML Registry/Repository JSR−157: Java API for ebXML CPP/CPA
J2EE Web Services Framework JSR 151: J2EE 1.4 JSR 109: (Enterprise Web services) JAXM, JAX−RPC
XML document management JAXP (Java API for XML processing) JAXB (Java API for XML data−binding)
Security XML Encryption (JSR 106) XML Digital Signature (JSR 105) XML Trust Service (JSR 104) Web services security assertions (JSR 155)
Java Web Services Development Pack (JWSDP) Provides a convenient all−in−one package
Support both web applications and Web services Contains
Java XML Pack Tomcat JSP Tag Library (JSTL) JSSE (Java Secure Socket Extension) Ant build tool Java WSDP Registry Server (UDDI server)
Early Access available from Jan. 2002
3 Java EE 5.0
J2SE 1.5 已正式更名为 J2SE 5.0 同样的从 J2EE 1.5 之后,也不再使用 1.x
的版本编号,改成 J2EE 5.0 、 J2EE 6.0
J2SETM 5.0 “Tiger”
Java EE 5.0
EoD (Ease-of-Development) is the main theme Simplify common scenarios
Remove boilerplate code Rely on defaults whenever possible Drastically reduce deployment descriptors
Add utility classes / helpers Exploit new Tiger features
Especially JSR-175 metadata annotations
Java EE 5.0
Java EE 5 : Java EE 不再象以前那样只注重大型商业系统的开发,而是更关注小到中型系统的开发,简化这部分系统开发步骤。 落实这一简化行动的最大特征是在 Java 5.0(Java 1.5) 中加
入 Annotations ,通过 Annotations 引入,降低 Java EE开发时,既要写 code ,又要写 XML配置文件之苦
透过 Metadata 的语法 ( 或是称为 Annotation) ,你可以将部署所需要的条件写在类别或方法之前,以适当的工具加以读取,就能自动帮你产生出各式部署 EJB 所需的设定档或是类别。
4 J2EE vs .NET Key Differentiators
Overview of APIs and Services
5 小结
J2EE 是什么? J2EE 是 Java EE
J2EE 是一段历史
J2EE 是未来?
J2EE 的功能十分强大,但功能强大的后遗症就是复杂度也随之提升 若 Java 要提升在运算技术中的中心角色,它必须降低困难度。
J2EE 从创新到走进市场的速度问题 Java Community Process(JCP)
主要参考文献 Web Service Infrastructure JavaTM Technology and XML, Sri
dhar Reddy, [email protected] , www.sun.com/developers/EvangCentral , Sun Microsystems, 2002
XML-RPC Specification, by Dave Winer, 1999.6, http://www.xmlrpc.com/
Building Blocks of Web Services: SOAP, WSDL, UDDI, and ebXML. Sang Shin, [email protected] , Sun Microsystems, 2002
J2EE™: Platform of Choice for Web Services, Sang Shin, [email protected] , Sun Microsystems, 2002
Web Services Infrastructure:Java 2 Platform, Enterprise Edition (J2EE) , Gary Downing, [email protected] , Sun Microsystems, 2002
The End!