Sun Microsystems

Язык XML делает данные переносимыми. Платформа Java делает код переносимым. Интерфейс Java API дня XML делает удобным ис

349 74 391KB

English Pages 25 Year 2001

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

Sun Microsystems

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

Sun Microsystems Web API

Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA 94303 U. S. A. 650-960-1300 2

,

2001. [email protected]

. JavaTM .

XML.

Sun Microsystems, Inc. 901 San Antonio Road ° Palo Alto, CA 94303 U. S. A. 650-960-1300. . , ,

,

.

,

Sun Microsystems , Berkeley BSD

TM

Communicator ,

,

. Sun

.

,

. UNIX X/ Open Company, Ltd. For Netscape : Copyright 1995 Netscape Communications Corporation. .

Sun, Sun Microsystems, the Sun logo, AnswerBook2, docs.sun.com, Solaris, Java, Java 2 Platform, Enterprise Edition, J2EE, JavaServer Pages, JSP, Java API for XML Processing, Java Architecture for XML Binding, Java API for XML Messaging, Java API for XML Registries, and Java API for XML-based RPC , Sun Microsystems, Inc. . SPARC SPARC International, Inc. . , SPARC, , Sun Microsystems, Inc. The OPEN LOOK and SunTM Graphical User Interface Xerox . Sun Sun, Sun . А Ч Ы А А: , FAR 52.227-14( g)( 2)( 6/ 87) FAR 52.227-19( 6/ 87),

Sun Microsystems, Inc. Xerox

,

Xerox Graphical User Interface, OPEN LOOK,

. DFAR 252.227-7015( b)( 6/ 95) “AS IS” ( ,

,

. Sun

-

DFAR 227.7202-3( a).

) , ,

.

,

. XML XML

.

Java

.

Java API

XML. : ,

API

,

, XML

Java

. XML . XML





, . ,

«

, Web.

XML,



»,

, ,

, .

, , JavaTM 2, Enterprise , ,

. TM

Edition (J2EE ).

, ,

J2EE platform

,

J2EE API

.

Java

XML

. ,



(API) Java .

API

,

XML, ,

.

,

,

Java

XML.

, . API

Java

XML

:

http://java.sun.com/xml Ч

XML? XML(eXtensible Markup Language – . .

), XML ,

XML

HTML

.

) – , HTML (HyperText Markup Language – , , , -

:

Mocha Java 11.95

Sumatra 12.50

and . 1 , ,

,

.

, ,

HTML



XML

XML

, ,

. .

, ,

HTML. XML, .

XML HTML

,

, XML.

XML XML (

.

, ).

,

,

, ( DTD

DTD. .

-

)

,

Document Type Definition DTD

(

XML

,

)

.

,

.





,

priceList

).

,

coffee,

name price.

,

, priceList, . coffee ( ,

: ,

,

.

-

Ч

,

.

XML

? DTD, priceList

DTD XML

-

,

,

DTD. XML ,

DTD. price

, name.

,

XML . priceList DTD, DTD pri eList,

,

DTD,

XML,

, , ,

,

,

,

,

,

,

.

,

,

.

XML .

,

, XML

,

,

. .

К

(API) Java Java. ,

XML •









Java

TM

Java

TM

XML

TM

XML.

Web:



.

(API), API for XML Processing (JAXP) –

: XML

,

Architecture for XML Binding (JAXB) – Java

(API), : Java TM API for XML Messaging (JAXM) – Internet Java TM API for XML Registries (JAXR) – Java

Java

XML

SOAP (Simple Object Access Protocol)

API for XML-based RPC (JAX-RPC) – Internet .

,

API ,

,

Java for XML

SOAP

, .

, Structured Information Standards, OASIS), , , XML SOAP. Java

XML ,

WWW-

(World Wide Web Consortium, W3C) (Organization for the Advancement of , , , . API Java XML – , . , JAXP , JAXM . , , . API .

JAXP К

.

JAXP(The JavaTM API for XML Processing) JAVA. JAXP for XML Parsing) DOM (Document Object Model)

XML

, SAX (Simple API

, . JAXP

XSLT(XML

Stylesheet

Language

1.1

Transformations), XML

,

HTML. JAXP

(namespace),

DTD. , JAXP .

,

. XML, SAX

XSL , Reference Implementation ( Crimson,

DOM. XML . JAXP 1.1 XSLT Xanon Apache Software Foundation,

http://java.sun.com/xml) Sun .

(API) SAX SAX

, .

XML

,

, ContentHandler (“

: . . . SAX setNamespaceAware(true)

DOM ParserFactory.

, ,

,

.

XML (XSLT API). XSLT (XSL Transoformation), XML XSL XML JAXP

, XSLT SAX-, DOMSAX.

W3C XSL Working Group, XML . , , , XSL(XML Stylesheet Language – ). XML . , XSLT . , , HTML. javax.xml.transform, XSLT. API, DOM, DOMXML , XML HTML, XSL.

DOM-

XML

.

DOMTransformer object ,

XML

,

,

.

TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); DOM-

,

DOMSource

. DOMSource source = new DOMSource(document); StreamResult XML. File newXML = new File("newXML.xml"); FileOutputStream os = new FileOutputStream(newXML) ; StreamResult result = new StreamResult(os) ; transformer.transform(source, result) ;

XML XSLT newXML.xml

HTML

.

, HTML

XML . XML.

,

XSL ,

,

,

.

-

,

,

, ,

,

. HTML-

, .





,

XML

HTML,

.

< xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform">

Coffee Prices















, XML , Transformer

XSLT ,

. transformer

XML tFactory

,

TransformerFactory HTML

TransformerFactory .

TransformerFactory tFactory = TransformerFactory.newInstance() ; String stylesheet = "prices.xsl"; String sourceId = "newXML.xml"; File pricesHTML = new File("pricesHTML.html"); FileOutputStream os = new FileOutputStream(pricesHTM); Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheet) ) ; transform, (output stream). transformer.transform(new StreamSource(sourceId), new StreamResult(os));

,

JAXB JAXB

XML Java.

DTD, XML

,

JAXB ,

,

Java, . XML

Java, XML

.

JAXB, JAXB ,

,

DTD.

,

,

DTD,

,

DTD

-

JAXB.

DTD, ,

1.

: . ,

2.

XML

,

JAXB.

DTD ,

, .

, ,

.

,

, .

property (

).

DTD. DTD

DTD,

priceList.dtd.



JAXB ,

,

DTD .

,– , BigDecimal (

price ):

, ,

...

... DTD PriceList Coffee

PriceList List,

"

Coffee. ".

. "

"

:

BigDecimal getPrice(); void setPrice(BigDecimal x); PriceList,

Coffee

.

, XML.

– DTD. XML

.

XML , XML

Java

,

,

, XML .

DTD. .

, ,

– –

,

Java: , JAXM XML XML

. , ,

XML XML . :

Arabica 13.50

Mocha Java 11.95

Sumatra 12.50

XML

,

PriceList: FileInputStream fis =new FileInputStream("priceList.xml"); PriceList myPrices =PriceList.unmarshal(fis); Java, ,

XML , ,

Coffee, PriceList myNewPrices = new PriceList(); List listOfCoffees = myNewPrices.getCoffees(); Coffee zCoffee = new Coffee(); zCoffee.setName("Zapoteca"); zCoffee.setPrice("15.00"); listOfCoffees.add(zCoffee); XML Java.

myPrices. . XML PriceList,

Coffee

:

,

,

, JAXB

Java

XML

XML

,

Java.

Mocha Java Mocha Java

,– setPrice

.

.

,

Coffee:

List coffees =myPrices.getCoffees(); for (ListIterator i =coffees.listIterator();i.hasNext();){ Coffee myCoffee =(Coffee)i.next(); if (myCoffee.getName().equals("Mocha Java")){ myCoffee.setPrice("12.50"); } }

XML , XML XML

,

.

,

JAXB .

XML , myNewPrices:

XML

File newPrices =new File("newPriceList.xml"); FileOutputStream fos = new FileOutputStream(newPrices); myNewPrices.marshal(fos);

, JAXB -

Java ,

Java ,

Java

. XML.

XML.

,

XML

, JAXB

,

Java, XML.

Java, Java XML,

. . JAXB

XML

,

, ,

,

.

JAXP JAXP

JAXB

JAXB .

.

API

JAXP

, (API). SAX

,

,

.

,

,

DOM. , API

DOM

DOM

.

,

XML

API SAX

,

JAXP,

XSLT

, DOM. JAXP

,

. DOM,

XML , ,

JAXB. , . , JAXB

, JAXB, JAXB .

, DTD,

,

.

,

JAXB

, SAX, . . ,

DTD,

SAX ,

.

,

. .

JAXB DTD,

,

DTD, JAXP

, ,

. • • • •

JAXB



JAXP

• • • •

,

: ,

XML ,

: :

SAX,

DOM ,

DTD

, XSLT ,

XML

JAXM К

.

API

Java

XML XML Attachments ebXML.

SOAP , ,

(The Java API for XML Messaging, JAXM) Internet. SOAP

1.1

. .

, JAXM

,

, ,

,

,

,

. ,

. ,

,

,

,

,

.

,

,

. JAXM ("JAXM client"), . JAXM

, ,

JAXM,

. ,

JAXM

. "

-

,

JAXM (

"

) ,

.

, .

SOAPConnection.call, . .

,

;

, SOAPConnection, ,

, ,

, ,

,

-

JAXM, (

,

)

.

,

. JAXM

, J2EETM. ,

(servlet)

,

, :

,

, .

JAXM . SOAP SOAPBody ,

, SOAPEnvelope

,

SOAP SOAPHeader . ,

XML

, SOAPBody. SOAP

XML .

, ,

XML.

, ProviderConnection.

JAXM

" "

-

-

,

,

SOAPConnection,

" SOAPConnection, . SOAPConnection,

", .

SOAPConnectionFactory. SOAPConnectionFactory,

:

SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance(); factory

SOAPConnection:

JAXM

SOAPConnection con =factory.createConnection();

, ProviderConnection

,

, .

ProviderConnection , SOAPConnection . ProviderConnectionFactory, :

ProviderConnectionFactory pcFactory = ProviderConnectionFactory.newInstance(); ProviderConnection pcCon = pcFactory.createConnection(); pcCon .

JAXM

ProviderConnection –

ProviderConnectionFactory, .

ProviderConnectionFactory JNDI API "CoffeeBreakProvider". ProviderConnectionFactory, Java,

. ProviderConnectionFactory

2 , ,

. ProviderConnectionFactory JAXM

.

,

: Context ctx = getInitialContext(); ProviderConnectionFactory pcFactory = (ProviderConnectionFactory) ctx.lookup("CoffeeBreakProvider"); ProviderConnection con = pcFactory.createConnection(); con

ProviderConnection

,

Coffee Break.

, MessageFactory

. . MessageFactory. SOAPMessage

.

MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage m = messageFactory.createMessage(); SOAPMessage

,

messageFactory, SOAP. ,

m

,

. JAXM API , ebXML

SOAP

BizTalk SOAP

. SOAP.

, (profile). MessageFactory, createMessageFactory ProviderConnection . SOAPMessage , MessageFactory , . , , schemaURI URI , m2 , createMessageFactory. MessageFactory messageFactory2 = con.createMessageFactory(); SOAPMessage m2 = messageFactory2.createMessage(); SOAPMessage SOAPEnvelope, SOAPBody, SOAPHeader SOAPBody

– m

m2 – SOAPHeader ( ,

.

SOAPPart , ).

SOAPPart,

AttachmentPart

.

SOAP , SOAPEnvelope,

SOAPPart, SOAPHeader. , – SOAPHeaderElement SOAPBodyElement , SOAPElement.addTextNode. SOAPBody, SOAPBodyElement . , Name , SOAPBodyElement. addTextNode:

SOAPBody XML

XML

SOAP

, createName,

SOAPPart sp = m.getSOAPPart(); SOAPEnvelope envelope = sp.getSOAPEnvelope(); SOAPBody body = envelope.getSOAPBody(); SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("text", "hotitems","http://hotitems.com/products/gizmo"); bodyElement.addTextNode("some-xml-text");

SOAPPart SAXSource, DOMSource , SOAP , . StreamSource DOMSource,

javax.xml.transform.Source, , ;

SAXSource, XML .

SOAPPart , DocumentBulder.

StreamSource ,

XML

DOMSource. JAXP DocumentBulderFactory

SOAPMessage. .

.

– XML ,

DOMSource. SOAPPart.setContent:

domSource

,

DOMSource

SOAPPart soapPart = message.getSOAPPart(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse("file:///foo.bar/soap.xml"); DOMSource domSource = new DOMSource(doc); soapPart.setContent(domSource);

XML

Message ,

,

-

. ,

, URL javax.activation.DataHandler. attachPart

,

.

JPEG, dh, m , .

Message

attachPart URL

.

AttachmentPart, ,

URL url = new URL("http://foo.bar/img.jpg"); DataHandler dh = new DataHandler(url); AttachmentPart attachPart = m.createAttachmentPart(dh); m.addAttachmentPart(attachPart); SOAPMessage Object

AttachmentPart createAttachmentPart.

AttachmentPart attachPart = m.createAttachmentPart("content-string", "text/plain"); m.addAttachmentPart(attachPart); dsf AttachmentPart AttachmentPart.setContent. ByteArrayInputStream,

Object

Object jpeg.

AttachmentPart ap = m.createAttachmentPart(); byte[] jpegData = ...; ap.setContent(new ByteArrayInputStream(jpegData), "image/jpeg"); m.addAttachmentPart(ap);

SOAPMessage,

.

SOAPConnection

.

, Endpoint,

. URL

.

SOAPMessage response = soapConnection.call(message, urlEndpoint); ,

, .

ProviderConnection ,

, . .

. providerConnection.send(message);

,

,

, – .

JAXR К

. JavaTM API

XML Registries (JAXP) . , . JAXR

"

" , ,

Java ,

(

(

ebXML),

UDDI). ,

.

,

,

. ,

.

, DTD JAXR

,

DTD

,

XML

DTD , . , .

JAXR, Java,

.

JAXR. .

,

,

JAXR

.

. ,

Java

, . .

RegistryServise rs The Coffee Break, Break Industry Classification System – org, , orgs orgs.

,

JAXR ,

, BusinessLifeCycleManager lcm. Organization org, The Coffee NAICS (the North American ). , The Coffee Break, Collection orgs. lcm, Organization,

RegistryService rs = connection.getRegistryService(); BusinessLifeCycleManager lcm = rs.getBusinessLifeCycleManager(); Organization org = lcm.createOrganization("The Coffee Break"); org.setDescription("Purveyor of only the finest coffees. Established 1895"); ClassificationScheme cScheme = lcm.createClassificationScheme("ntis-gov:naics", "North American Industry Classification System"); javax.xml.registry.infomodel.Key cKey = lcm.createKey("uuid:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2"); cScheme.setKey(cKey);

Classification classification = (Classification) lcm.createClassification(cScheme, "Snack and Nonalcoholic Beverage Bars","722213"); Collection classifications = new ArrayList(); classifications.add(classification); org.addClassifications(classifications); Collection orgs = new ArrayList(); orgs.add(org); lcm.saveOrganizations(orgs);

. JAXR BusinessQueryManager findOrganizations,

. The Coffee Break.

bqm ,

null, Collection findQualifiers –

bqm .

. , findQualifiers

, String,

, ,

Collection “Coffee”. The Coffee Break.

,

,

, Collection



namePatterns. , namePatterns. , , classifications,

,

, The Coffee Break.

BusinessQueryManager bqm = rs.getBusinessQueryManager(); // Define find qualifiers Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.CASE_ SENSITIVE_ MATCH); Collection namePatterns = new ArrayList(); namePatterns.add("%Coffee%"); //Find orgs with name containing Coffee //Find using only the name and the classifications BulkResponse response = bqm.findOrganizations(findQualifiers, namePatterns, null, classifications,null,null); Collection orgs = response.getCollection();

JAXR

SQL DeclarativeQueryManager.

.

,

DeclarativeQueryManager dqm = rs.getDeclarativeQueryManager(); Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, "SELECT id FROM RegistryEntry WHERE name LIKE %Coffee%" + "AND majorVersion >= 1 AND" + "(majorVersion >= 2 OR minorVersion >= 3)"); BulkResponse response2 = dqm.executeQuery(query); response2 BulkResponse “Coffee”

id (uuid)

RegistyEntry,

. JAXP

JASM. JAXR

.

, ,

JAX-RPC К

. JavaTM API

XML-based RPC (JAX-RPC) Java , XML (RPC – Remote Procedure Call). Java API : Java IDL Remote Method Invocation (RMI). API , . , JAX-RPC XML, . Java IDL COBRA (Common Object Request Broker Architecture) OMG IDL (Object Management Group's Interface Definition Language). RMI RPC, Java, , RMI IIOP . Sun COBRA RMI JAX-RPC, . RPC , , . . JAX-RPC , , XML-based RPC Java, XML .

JAX-RPC. JAX-RPC .

, RCP

,

,

J2EE

,

,

. Web-

, stock quote, SOAP.

.

,

RPC

SOAP

, ,

WSDL (Web Services Description Language). WSDL JAX-RPC, , . , , Java. JAX-RPC SOAP . , , JAX-RPC, SOAP , JAXM, SOAP, . , ebXML, SOAP. JAXM, JAX-RPC,

• • • JAX-RPC RPC JASM JAX-RPC,

, (Web.

, Java

, ,

, ) Java,

, , JAX-RPC

, ,

:

. ,

SOAP, .

Java

,

, XML.

,

К

. Java API Java APIs ,

,

XML , ,

XML,

.

, -

. ,

.

. ,

The Coffee Break

.

-

.

. , ebXML,

The Coffee Break . JAXR . JAXR-

JAXR, JAXM, ebXML

.

. . – .

JAXM

,

,

.

JAXM-

.

, JAX-RPC

,

, ,

stock quotes,

, .

TheCoffee Break XML

,

.

XML,

,

.

. JAXB

-

, DTD. (

.

,

DTD DTD

.

,

,

, , ,

, Coffee The Coffee Break, . DTD , JAXM.

, SAX name

DOM.) price. .

, JAXB .

-

, XML

, ,

, JAXM.

. , The Coffee Break HTML . , The Coffee Break . , HTML – HTML Submit, .

. .

,

, 25%,

,

. ,

,

. JSP

.

JavaServer Pages JSP

TM

(JSP

TM

), ,

. , . Web-

,

, Java API

XML .

, J2EE

XML ,

( ,

Asynchronous

)

,

,

.

,

.

. synchronous.

,

B2B (Business-to-Business) , ,

. ,

B2C (Business-to-customer) ,

,

. API

DOM (Document Object Model)

XML . Java

DOM

, W3C. JAXP

API

. ,

DTD (Document Type Definition) XML . ebXML (Electronic Business XML) XML , XML Internet.

.

, ,

,

HTML (HyperText Markup Language)

Web Internet.

HTTP (HyperText Transfer Protocol) J2EETM (Java TM 2 Platform, Enterprise Edition) Java 2, Java, J2SE.

. .

J2SETM (Java TM 2 Platform, Standard Edition) Java 2, . API

JAX Pack

.

Java,

.

,

Java

XML (JAXP, JAXB, JAXM, JAXR Web Services Pack.

JAXB (JavaTM Architecture for XML Binding) Java. JAXB , DTD. XML XML . JAXM (JavaTM API for XML Messaging) Java. JAXM

J2EE

XML

API

JAXR (JavaTM API for XML Registries) Internet. API

JAX-RPC (JavaTM API for XML RPC)

XML , DTD), ,

,

DTD,

API SOAP 1.1 , ebXML

JAXP (JavaTM API for XML Messaging) SAX, DOM, XSLT

(

JAX-RPC).

SOAP Attachments BizTalk, .

XML XML (XML Namespaces). API

. JAXP

Java

,

XML

Java. loosely coupled ( .

)

,

,

OASIS (Organization for the Advancement of Structured Information Standards) , , XML. Registry Web-

, . "

"

Rerository –

.

. repository

, ( XML

. , , , RosettaNet PIP3A4

, XML XML,

)

,

. XML

schema

.

: DTD.

API, XML-DEV mail list,

SAX Simple API for XML Parsing XML. SAX OASIS standards body. JAXP

Java

SAX API

SAX. ,

synchronous

. , .

, call.

,

, .

JAXM API .

SOAP (Simple Object Access Protocol)

XML

. .

UDDI

(Universal .

Description, Discovery, and Integration) XML

, Web-

.

.

web services XML

, .

,

,

JAX-RPC,

,

. ,

Web Service Pack

Java 2. Java Web GUIs), Tomcat (an open-source technologies), JAX Pack ( Java APIs XML).

JavaServer Faces ( implementation of JavaServer Pages

WSDL (Web Services Description Language) -

Web.

WebWWW (World Wide Web) -

.

XML

.

,

W3C (World Wide Web Consortium) WWWWeb

API Java Servlet

,

.

,

. Web-

XML (eXtensible Markup Language) -

. ,

XML.

. ,

Web-

. W3C

XML Namespaces

,

. XSL (eXtensible Stylesheet Language) XML, XSLT,

JAXP-

, XML XSL.

.

XSLT (XSL Transformations) - XSL-

, XML-

DTD

. XSL

XSL. ,

XSL,

XSLT. ,

HTML.

XML XSLT

XSLT, XSL.

XSL,