Java and XML

Document Sample
Java and XML Powered By Docstoc
					 Why XML?                      Core XML-centric
 ‘XML Applications’               Standards: SAX and the
                                   DOM
 Data Analysis and
    Application Development       Building toward Beans:
                                   IBM’s BeanML
   Client-Server and
    Distributed Applications      Single-purpose: XWingML
   Transforming XML              Building on XML:
                                   JXML’s MDSAX & Coins
   Linking XML
                                  XML-oriented protocols:
   XML and the Web
                                   XML-RPC and XP
   Java and XML
                                  Futures
    Development
 Meaningful markup
 Single approach can accommodate both document
  and data structures, and can integrate both within
  documents.
 Good fit for object-oriented development - strict
  hierarchies ensure clean structures
 Relatively easy integration with legacy
  environments for creation, transport, presentation.
 Standard XML document structure allows separation
  of file handling from application architecture.
 Separation of file handling permits creation of generic
  components for information processing.
 Modular approach simplifies integration on many
  levels.
 Hierarchical structures of XML map well to objects and
  properties.
 Componentization made simpler by XML parsing works
  well with OOP development environments.
 Program Composition made possible by XML mapping
  to object structures and late binding.
 Needed: Data typing. Currently roll-your-own
 Real programmers write their own highly optimized
  input/output routines
 Can’t lock customers in to a proprietary and
  inscrutable file format. (Have to produce better
  programs!)
 XML is verbose, especially with all those wasteful end
  tags. Binary formats are more efficient.
            Different Concepts of ‘Application’


 Application as Data Structure

   • „Traditional‟ SGML usage - “HTML is an application of SGML”
   • Data structures may define family of software applications
 Application as Network Architecture

   • Web application or client-server application framework
   • Not necessarily programming - typically integration-focused
 Application as Software Package

   • „Traditional‟ software development view of applications
   • May involve program or component integration
 ‘Traditional’ document-centric approach focuses on
  using Java as tool for managing, presenting,
  transforming XML documents.
 XML documents the focus; application built to support
  documents, not application-specific documents.
 Can be used for both generic (non-vocabulary-specific)
  approaches and custom apps built for particular
  vocabularies, document types.
 Beyond Resource Files
 XML application structure and content mapped into
  document structure
 Smoothes compile cycles by permitting run-time
  program construction based on document content
 Simplifies repetitive programming chores like GUI
  construction.
 Data modeling as the first step in building an XML-
  centric application
 Data modeling as task of SGML consultants - is that
  always needed anymore?
 Key question: Am I building an application to support
  documents, or documents to support an application?
 Need to involve application developers in data
  modeling process at early stage
 Programmer’s perspective: develop XML first, or object
  first? Either approach is possible, though each more
  appropriate to particular situations.
 Additional consideration may be needed for
  application-data model integration.
 Extensible Style Language (XSL) provides
  template-based transformation language
 Architectural Forms (from SGML’s HyTime)
  provides attribute-based transformations. David
  Megginson’s XAF implementation applies this to
  XML.
 SAXON and MDSAX provide filters for
  programmatically transforming XML.
 Transformations may be document to document,
  DOM tree to DOM tree, or events to events.
 A critical piece of Web functionality that is seriously
  missing-in-action.
 Previous Working Draft: 3/3/98. Requirements
  Documents just issued.
 XLink’s approach is document-centric, but may be a
  good tool for modeling relations among objects as well
  as documents.
 XML was designed for the Web, with HTTP transport
  in mind, though any file-oriented approach is
  acceptable.
 XML’s ‘natural fit’ with structures used for HTML
  simplifies implementation using traditional Web
  server/browser applications as well as CGI and, of
  course, Java.
 Jon Bosak: ‘XML gives Java something to do.’
 Java provides among the best Unicode support (and
  useful tools for encoding conversions)
 Java is extremely network-friendly
 XML structures map easily to Java object structures.
 Extremely portable across platforms
 Many XML components are already available for Java,
  from parsers to XSL and XLink engines.
 Many of the core standards for processing XML are
  developed with Java in mind - SAX, DOM, etc.
 Frameworks for Java XML development, like MDSAX
  and SAXON, are readily available.
 The big leap from serialized documents to
  program structures, long the realm of experienced
  pros.
 XML was designed to avoid the many nightmares
  involved in parsing SGML.
 Parsing involves multiple stages of processing to
  return a complete picture of an XML document to
  an application.
 XML parsing tends to be assigned to a pre-built
  component, leaving the application to process
  data rather than parse text files.
                        XML Document


    Core Document Parser           DTD declarations

                                                                                               XML DTD

Well-f ormedness Sy ntax Checker
                                                                                          <?xml?>
                                                               Conf igurable Retriev al   <!ELEMENT...
                                                                     of External          <!ATTLIST...
       Entity Resolution                                             Resources
                                               DTD Resolv er



      Attribute Def aulting




      Structure Validation




         Tree Builder




                    Application
          <?xml?>




                    XML Document



        Monolithic Parser
         Loads document
        Parses declarations
            Builds DTD
 Interprets document against DTD
            May v alidate
        May build DOM tree
May prov ide XSL or XLink Serv ices




           Application
 Two dominant standards:
   Simple API for XML (SAX)
      Event-based model ‘reads’ document to application handlers.
      Supported by nearly all Java XML parsers.
      developed by XML-Dev mailing list (SAX2 in dev.)
   Document Object Model (DOM)
      Tree-based model passes complete picture of document to
       application at processing conclusion
      Java, JavaScript, IDL descriptions; Perl implementation in
       independent development.
      developed by W3C. Level 1 complete, Level 2 in progress.
 Development environment issues
 Platform issues
 Network issues
 Personal preference as the typically overriding issue
 Generic framework for use with any Bean-oriented
  Development (BeanML)
 Specific vocabulary aimed at particular area of Java
  development, with tools specific to that area
  (XWingML for Swing)
 Generic framework that can support multiple specific
  vocabularies (MDSAX and Coins)
 IBM’s AlphaWorks site offers Bean Markup Language
    tools, including a BeanML compiler and
    documentation.
   BeanML uses very Bean-specific vocabulary to
    configure JavaBeans.
   Small footprint (35K)
   Free download from IBM:
   http://www.alphaworks.ibm.com
<?xml version="1.0"?>


<bean class="java.awt.Panel">
  <property name="background" value="0xeeeeee"/>
  <property name="layout">
    <bean class="java.awt.BorderLayout"/>
  </property>


  <add>
    <bean class="demos.juggler.Juggler" id="Juggler">
      <property name="animationRate" value="50"/>
      <call-method name="start"/>
    </bean>
    <string>Center</string>
  </add>
…</bean>
 Similar to BeanML, but focused much more tightly on
  Swing GUI interfaces
 Currently available as toolkit; GUI editor supposed to
  available soon.
 Free download from Bluestone Software:
  http://www.bluestone.com
<?xml version="1.0"?>
<!DOCTYPE XwingML SYSTEM "file:///c:/XwingML/xml/xwingml.dtd">
<XwingML>
   <Classes>
      <Instance name="OpenFile" className="XMLOpenFile"/>
      <Instance name="SaveFile" className="XMLSaveFile"/>
      <Instance name="ParseFile" className="XMLParseFile"/>
      <Instance name="About" className="XMLAbout"/>
   </Classes>
  <JFrame name="MainFrame" title="Bluestone XMLEdit" image="icon.gif"
  x="10%" y="10%" width="80%" height="80%">
      <JMenuBar>
         <JMenu text="File" mnemonic="F">
           <JMenuItem icon="open.gif" text="Open..." mnemonic="O"
  accelerator="VK_O,CTRL_MASK" actionListener="OpenFile"/>
           <JMenuItem icon="save.gif" text="Save" mnemonic="S"
  accelerator="VK_S,CTRL_MASK" actionCommand="save"
  actionListener="SaveFile"/>
           <JMenuItem icon="save.gif" text="Save As..." mnemonic="a"
  actionCommand="saveas" actionListener="SaveFile"/>
            <Separator/>
           <JMenuItem text="Exit" mnemonic="x"
  accelerator="VK_X,CTRL_MASK"
  actionListener="com.bluestone.xml.swing.XwingMLExit"/>
 The existence of standard interfaces to XML
  documents - SAX and the DOM - has given rise to a
  number of component possibilities.
 SAX Filters, which accept SAX events as input and
  generate SAX events as output, are one key component
  architecture for Java-based XML development.
                 Application




Document
           DTD Ev ent   Error Ev ent    Entity Ev ent
  Ev ent
            Handler      Handler          Handler
 Handler


                   Ev ents




                    SAX
                   Parser




                <?xml?>



                                       Copyright 1998 JXML, Inc.
                                       Permission is granted for
                                       redistribution and reuse
                                       that includes this label.
                XML Document
                                                                        Application




                                       List of Links

                                                       Document
Filters can be inserted in the                           Ev ent
                                                        Handler
                                                                  DTD Ev ent
                                                                   Handler
                                                                               Error Ev ent
                                                                                Handler
                                                                                               Entity Ev ent
                                                                                                 Handler


path between the parser and                            Document
                                                         Ev ent
the application, providing       XLinkFilter            Handler

                                                                          Ev ents
generic functionality to many
applications.
                                                                           SAX
                                                                          Parser




                                                                       <?xml?>


                                                                                              Copyright 1998 JXML, Inc.
                                                                                              Permission is granted for
                                                                                              redistribution and reuse
                                                                                              that includes this label.

                                                                       XML Document
                                                                       Application




                                      List of Links

                                                      Document
                                                                 DTD Ev ent   Error Ev ent   Entity Ev ent
                                                        Ev ent
                                                                  Handler      Handler         Handler
                                                       Handler


                                                      Document
                                                        Ev ent
                                XLinkFilter            Handler


                                        Stack of
                                       Elements       Document
                                                        Ev ent
                                                       Handler
                                LocationFilter
                                                                         Ev ents




                                                                          SAX
                                                                         Parser

Multiple filters may be layered and even
connected to provide additional generic
                                                                    <?xml?>
functionality.
                                                                                         Copyright 1998 JXML, Inc.
                                                                                         Permission is granted for
                                                                                         redistribution and reuse
                                                                                         that includes this label.

                                                                     XML Document
                                                                   Application




                      List of Links

                                            Document
                                                             DTD Ev ent   Error Ev ent   Entity Ev ent
                                              Ev ent
                                                              Handler      Handler         Handler
                                             Handler


                                            Document
                                              Ev ent
                XLinkFilter                  Handler


                        Stack of
                       Elements             Document
                                              Ev ent
                                             Handler
                LocationFilter
                                      Transf ormed Ev ents
                      Stack of
                    Namespaces              Document
                                              Ev ent
                                             Handler
                NamespaceFilter
                                                                     Ev ents




And so on....                                                         SAX
                                                                     Parser




                                                                <?xml?>


                                                                                     Copyright 1998 JXML, Inc.
                                                                                     Permission is granted for
                                                                                     redistribution and reuse
                                                                                     that includes this label.

                                                                 XML Document
 JXML’s MDSAX
 provides an overall                                               List of Links                                        Application




 architecture for
                                                                                                  Document
                                                                                                                  DTD Ev ent   Error Ev ent   Entity Ev ent

 encapsulating SAX         MDContext (Parsing Context)
                                                                                                    Ev ent
                                                                                                   Handler
                                                                                                                   Handler      Handler         Handler




 processors as well as a                                                                          Document
                                                                                                    Ev ent

 set of prebuilt filters        Extended
                                 Object
                                                               MDAppHandler
                                                                                                   Handler


                                                                                                  Document
                                Ref erence XPointer Context
                                                                                                    Ev ent

 that can be applied to                                         XLinkFilter                        Handler


                                                                                                  Document

 particular situations.                 Stack of
                                        Elements
                                                                                                    Ev ent
                                                                                                   Handler
                                                              MDElementTy pe (required by MDSAX)
                                                                                           Transf ormed Ev ents
                                                                    Stack of
                                                                 Namespaces                       Document

 (MDServlet provides                                            NamespaceFilter
                                                                                                    Ev ent
                                                                                                   Handler




 support for using this                                                                                                   Ev ents




 in server-side                                                                                                            SAX
                                                                                                                          Parser



 document processing.)                                                                                   XML Document                     Copyright 1999 JXML, Inc.
                                                                                                                                          Permission is granted for
                                                                                                                                          redistribution and reuse
                                                                                                                                          that includes this label.
                                                                                                                    <?xml?>


Available for free download from http:/www.jxml.com
 MDSAX goes beyond layered filter processing,
  using its own set of XML tools to build the
  pathways that events will follow.
 ContextML is an extensible markup language that
  developers can use to specify the paths events will
  follow. Effectively, MDSAX builds itself based on a
  set of XML documents.
 Coins lets you re-serialize your objects.
The bootstrap process for MDSAX
<context>
   <element/>
   <documentRouter>
          <elementRouter key="context">
                   <x key="displayOutput"
   resultClass="com.jxml.mdsax.examples.output.DisplayOutput"/>
                   <x key="context"
   resultClass="com.jxml.mdsax.MDContextFactoryImpl"/>
                   <x key="documentRouter"
   resultClass="com.jxml.mdsax.MDDocumentRouterFactory"/>
                   <x key="stack"
   resultClass="com.jxml.mdsax.MDFilterStackFactoryImpl"/>
                   <x key="element"
          resultClass="com.jxml.mdsax.MDElementFactoryImpl"/>
                   <x key="elementRouter"
          resultClass="com.jxml.mdsax.MDElementRouterFactory"/>
                   <x key="passAll"
          resultClass="com.jxml.mdsax.MDPassAllFactory"/>
                   <x key="trace"
          resultClass="com.jxml.mdsax.MDTraceFilterFactory"/>
                   <x key="display"
          resultClass="com.jxml.mdsax.MDDisplayFilterFactory"/>
<context>
   <attList>
          <att name="ID" type="id" status="#IMPLIED"/>
   </attList>
   <elementRouter>
          <stack key="buttonGroup">
                   <element/>
                   <xs resultClass="javax.swing.ButtonGroup"/>
          </stack>
          <stack key="button">
                   <element/>
                   <xs resultClass="javax.swing.JButton"/>
          </stack>
          <stack key="radioButton">
                   <element/>
                   <xs resultClass="javax.swing.JRadioButton"/>
          </stack>
          <stack key="panel">
                   <element/>
                   <xs resultClass="javax.swing.JPanel"/>
          </stack>
          <stack key="sFrame">
                   <attList>
<sFrame

            title="Simple"

            ID="frame1"

            metalButton="MetalButton"

            motifButton="MotifButton"

            windowsButton="WindowsButton">



            <panel constraints="Center">

                                 <button text="Hello, world">

                                                                <buttonProperties mnemonic="h"/>

                                 </button>

                                 <buttonGroup ID="bg1"/>

                                 <radioButton

                                                                text="Metal"

                                                                ID="MetalButton"

                                                                actionCommand="javax.swing.plaf.metal.MetalLookAndFeel">



                                                                <buttonProperties buttonGroup="bg1" mnemonic="m"/>

                                                                <action eventDestination="frame1"/>

                                 </radioButton>

                                 <radioButton

                                                                text="Motif"

                                                                ID="MotifButton"

                                                                actionCommand="com.sun.java.swing.plaf.motif.MotifLookAndFeel">



                                                                <buttonProperties buttonGroup="bg1" mnemonic="o"/>

                                                                <action eventDestination="frame1"/>

                                 </radioButton>

                                 <radioButton

                                                                text="Windows"

                                                                ID="WindowsButton"

                                                                actionCommand="com.sun.java.swing.plaf.windows.WindowsLookAndFeel">



                                                                <buttonProperties buttonGroup="bg1" mnemonic="w"/>

                                                                <action eventDestination="frame1"/>

                                 </radioButton>

            </panel>

</sFrame>
 NASA and Century Computing are building a
  markup language/Java combination supporting
  remote control of instruments in hostile
  environments.
 XML provides foundation for descriptions of
  instruments, input/output
 AIML is a subset of more general IML - could be
  used with any instruments
 Combining the easy exchange and creation of XML
  documents with program composition and similar
  method-oriented strategies
 Using XML to relay data and command information
  among dissimilar systems
 Prospect of using COBOL output to build Java
  programs...
 Remote Procedure Call Origins
 Uses HTTP as carrier
   allows routing through firewalls without special
    configuration
   can rely on HTTP security, authentication, session
    management
 Developed by Frontier, Microsoft
 Implementations in Java, Perl, Python, etc.
 www.xml-rpc.com
POST /rpchandler HTTP/1.0             HTTP/1.1 200 OK
User-Agent: MyClient/1.0 (WinNT)      Server: JavaWebServer/1.1
Host: mycomputer.simonstl.com         Content-Length:
Content-Type: text/xml                Content-Type: text/xml
Content-length:169                    Date: Fri, 12 Feb 1999 19:01:32
                                        GMT
<?xml version="1.0"?>                 <?xml version="1.0?>
<methodCall>                          <methodResponse>
<methodName>test.returnId</method       <params>
  Name>                                     <param>
  <params>
     <param>                               <value><string>Server
<value><string>ASCII</string></valu     12345</string></value>
  e>                                       </param>
     </param>                           </params>
  <params>                            </methodResponse>
</methodCall>
 IETF - http//www.ietf.org/internet-drafts/draft-
  harding-extensible-protocol-00.txt
 Sets up two streams passing information as
  request/response
 Java implementation available

 “To extend XML from a class of data objects into a
  protocol is to extend the rules for constructing a
  single document into rules for constructing two
  interrelated streams of documents. Accordingly, we
  introduce mechanisms for handling both the sequential
  and interrelated aspects of the document streams.”
 Shift from code-oriented development to
  document-oriented integration
 Small components can make a difference - moving
  from large projects to large collections of smaller
  projects
 Open source, open process, and the ability to
  compete in this market
 The end of CORBA and COM? Probably no, but...
 Distributed processing on heterogeneous systems
 Debugging simplified!
 Client and server architectures can use identical
  components (and middleware too!)
 Less dependence on proprietary approaches
                           General

simonstl.com - essays, XLinkFilter project, and more:
       http://www.simonstl.com
XMLsoftware.com - a directory of software and components for
processing XML:
       http://www.xmlsoftware.com
Robin Cover’s XML pages - a guide to everything XML:
       http://www.oasis-open.org/cover/xml.html
Café Con Leche - An almost daily guide to XML:
       http://metalab.unc.edu/xml/
              Development Frameworks and Tools

IBM’s AlphaWorks: (All kinds of XML projects, mostly Java)
       http://www.alphaworks.ibm.com
JXML: (MDSAX and Coins)
       http://www.jxml.com
SAXON (a framework for processing SAX events)
       http://home.iclweb.com/icl2/mhkay/saxon.html
Docuverse DOM (free DOM implementation)
       http://www.docuverse.com/domsdk/index.html
                      More Components

John Cowan’s XML index (ParserFilter, NamespaceFilter, much more)
      http://www.ccil.org/~cowan/XML/
Free XML Software (maintained by Lars Marius Garshol)
      http://www.stud.ifi.uio.no/~larsga/linker/XMLtools.html
James Clark’s XML Resources (XML tools in Java, C, and C++)
      http://www.jclark.com/xml/

				
DOCUMENT INFO
Shared By:
Stats:
views:66
posted:10/22/2010
language:English
pages:47
Description: Know about Java and XML