Skip Headers

Oracle9i XML Developer's Kits Guide - XDK
Release 2 (9.2)

Part Number A96621-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

24
Developing XML Applications with JDeveloper

This chapter contains the following sections:

Introducing JDeveloper

Oracle JDeveloper is a J2EETM development environment with end-to-end support for developing, debugging, and deploying e-business applications. JDeveloper empowers users with highly productive tools, such as the industry's fastest Java debugger, a new profiler, and the innovative CodeCoach tool for code performance analysis and improvement.

To maximize productivity, JDeveloper provides a comprehensive set of integrated tools that support the complete development life cycle, from source code control, modeling, and coding through debugging, testing, profiling, and deploying. JDeveloper simplifies J2EE development by providing wizards, editors, visual design tools, and deployment tools to create high-quality standard J2EE components, including applets, JavaBeans, JavaServer Pages (JSP), servlets, and Enterprise JavaBeans (EJB). JDeveloper also provides a public Addin API to extend and customize the development environment and seamlessly integrate it with external products.

JDeveloper Covers the Complete Development Life Cycle

Java is a relatively new language, and Java development environments are catching up with traditional client/server tools. Developers now require a well-integrated development environment that supports the complete development life cycle:

          Checkout
             |
  |------ Design --------|
  |                      |
Tune                   Edit
  |                      |
Debug                 Compile
  |                      |
  |-------  Test --------|
             |
           Checkin
             |
           Deploy

In a typical scenario, a developer launches JDeveloper, checks out an application from the source control system and starts the development process. UML modelers help the developer with the design of the application, and possibly with the generation of source code. JDeveloper provides wizards and editor, both visual and code-based, to add functionality, and it includes various tools to compile, test, debug, and tune the application. When satisfied, the developer can check the application back into the source control system and deploy it to the final destination.

JDeveloper Runs on Windows, Linux, and SolarisTM Operating Environment

The 9i release of JDeveloper was completely rewritten in Java and now JDeveloper runs on any operating system that has a Java Virtual Machine (JDK 1.3 and later) and will be supported on Windows (NT, 2000, and XP), Linux and SolarisTM Operating Environment.

Another advantage is that the development environment is now fully extensible through the Addin API, which allows customers and third-party vendors to extend the product and integrate it with other products.

Java Alone Is Not Enough

Over the last few years, Java has become the programming language for the Internet. Some of the reasons for this popularity are its operating system independence, its simplicity, and its powerful component model.

To build complete e-business applications, however, developers will need more than Java alone. Oracle believes in, and has invested heavily, in the combination of Java, SQL, and XML. Java is used for programming the business and presentation logic, SQL for interacting with the database, and XML for passing information between loosely coupled applications.

JDeveloper helps developers build e-business applications using Java, XML, HTML, SQL, and PL/SQL. It provides various code editors and visual tools for each of these languages.

XML Tools in JDeveloper

The Oracle XDK is integrated into JDeveloper, offering many ways to create, handle, and transform XML. For example, with the XSQL Servlet, developers can query and manipulate database information, generate XML documents, transform the documents using XSLT stylesheets, and make them available on the Web.

JDeveloper has a new schema-driven XML editor. See Figure 24-1.

Figure 24-1 JDeveloper's Schema-Driven XML Editor in Action

Text description of jdevedit.gif follows.

Text description of the illustration jdevedit.gif

An XML Schema Definition defines the structure of an XML document and is used in the editor to validate the XML and help developers when typing. This feature is called Code Insight and provides a list of valid alternatives for XML elements or attributes in the document. Just by specifying the schema for a certain language, the editor can assist you in creating a document in that markup language.

Oracle JDeveloper simplifies the task of working with Java application code and XML data and documents at the same time. It features drag-and-drop XML development modules. These include the following:

Oracle XML Developer's Kit (XDK) is integrated into JDeveloper, so that it offers many utilities to help Java developers handle, create, and transform XML. For example, when designing with XSQL Servlet, you can query and manipulate database information, generate XML documents, transform them using XSLT stylesheets, and make them available on the web.

See Also:

Business Components for Java (BC4J)

To take J2EE application development to a higher level of productivity, JDeveloper now offers Business Components for Java (BC4J), a standards-based, server-side framework for creating scalable, high-performance Internet applications. The framework provides design-time facilities and runtime services to drastically simplify the task of building and reusing business logic.

Oracle Business Components for Java (BC4J) is a 100%-Java, XML-powered framework that enables productive development, portable deployment, and flexible customization of multitier, database-savvy applications from reusable business components.

Application developers use the Oracle Business Components framework and Oracle JDeveloper 's integrated design-time wizards, component editors, and productive Java coding environment to assemble and test application services from reusable business components.

These application services can then be deployed as either CORBA Server Objects or EJB Session Beans on enterprise-scale server platforms supporting Java technology.

The same server-side business component can be deployed without modification as either a JavaServer Pages/Servlet application or Enterprise JavaBeans component. This deployment flexibility, enables developers to reuse the same business logic and data models to deliver applications to a variety of clients, browsers, and wireless Internet devices without having to rewrite code.

In JDeveloper, you can customize the functionality of existing Business Components by using the new visual wizards to modify your XML metadata descriptions.

See Also:

Chapter 25, "Introduction to BC4J"

Integrated Web Services Development

JDeveloper integrates standard J2EE development techniques seamlessly with both the latest XML and emerging Web Services Standards (including SOAP, UDDI, and WSDL) and their Java-based equivalents. To preserve existing investments in PL/SQL and J2EE applications, JDeveloper makes it very easy for developers to create, deploy and consume Web Services from J2EE and PL/SQL applications using:

What's Needed to Run JDeveloper

JDeveloper is an IDE that has been written in Java and therefore, runs on Windows NT, Windows 2000, Linux and SolarisTM Operating Environment systems. It needs a minimum of 128 Mb RAM.

Minimum system requirements for JDeveloper

Refer to JDeveloper Release Notes. As more products are run on the same machine, system requirements are increased. A typical development environment for running JDeveloper includes:

These add to system requirements, in terms of actual CPU usage and in disk space needs.

Business rules can be changed on site without needing access to the underlying component source code.

XSQL Component Palette

XSQL Component Palette provides you with a mechanism to add tags which allows accessing database tables or BC4J View Objects. You can either perform queries against them or update the underlying database tables through them. Figure 24-2, "JDeveloper's XSQL Component Palette" illustrates the JDeveloper XSQL Component Palette.

Figure 24-2 JDeveloper's XSQL Component Palette

Text description of fig24-4.gif follows.

Text description of the illustration fig24-4.gif

Page Selector Wizard

When you need to create XSQL pages while building a web application, you can invoke Page Wizard which enables you to create XSQL Pages on top of either database tables directly or on top of BC4J View Objects. When you choose to build an XSQL Page on top of a BC4J View Object, you are prompted to select an application module from a list or create a new application module and then build the XSQL Pages based application.

See Also:

Oracle9i Java Developer's Guide

XDK Features in JDeveloper

The following lists JDeveloper's supported XDK for Java components:

You can use the XML Parser for Java including the XSLT Processor and the XML SQL Utility in JDeveloper as all these tools are written in Java. JDeveloper provides these components.

Sample programs which demonstrate how to use these tools can be found in the [JDeveloper]/Samples/xmlsamples directory.

Oracle XDK Integration in JDeveloper

Oracle XDK for Java consists of the following XML tools:

All these utilities are written in Java and hence can easily be dropped into JDeveloper and used with no further effort. You can also update the XDK for Java components with the latest versions downloaded from Oracle Technology Network (OTN) at http://otn.oracle.com/tech/xml.

Oracle XDK for Java also includes the XML Transviewer Beans. These are a set of JavaBeans that permit the easy addition of graphical or visual interfaces to XML applications. Bean encapsulation includes documentation and descriptors that make them accessible directly from JDeveloper.

See Also:

Chapter 10, "XDK JavaBeans" for more information on how to use the Transviewer Beans.

Developing Web Applications in JDeveloper Using XSQL Pages

The XSQL Servlet is a tool that processes SQL queries and outputs the result set as XML. This processor is implemented as a Java servlet and takes as its input an XML file containing embedded SQL queries. It uses the XML Parser for Java and the XML SQL Utility to perform many of its operations.

The XSQL Servlet offers a productive and easy way to get XML in and out of the database. Using simple scripts you can:

JDeveloper XSQL Example 1: emp.xsql

For example, consider the following XML example:

<?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="emp.xsl"?> 
<FAQ xmlns:xsql="urn:oracle-xsql" connection = "scott"> 
  <xsql:query doc-element="EMPLOYEES" row-element="EMP"> 
    select e.ename, e.sal, d.dname as department 
    from dept d, emp e 
    where d.deptno = e.deptno 
  </xsql:query> 
</FAQ> 

Generates the following:

<EMPLOYEES> 
  <EMP> 
    <ENAME>Scott</ENAME> 
    <SAL>1000</SAL> 
    <DEPARTMENT>Boston</DEPARTMENT> 
  </EMP> 
  <EMP> 
  ... 
</EMPLOYEES> 

With JDeveloper you can easily develop and execute XSQL files. The built in Web Server and the user's default Web Browser will be used to display the resulting pages.

Using Action Handlers in XSQL Pages

XSQL Action Handlers are Java classes which can be invoked from XSQL Page applications very easily. Since these are Java classes they can be debugged from JDeveloper just like any other Java application.

If you are building an XSQL Pages application, you can make use of the XSQL Action Handler to extend the set of actions that can be performed to handle more complex jobs. You will need to debug this Action Handler.

Your XSQL Pages should be in the directory specified in the Project Property "HTML Paths" settings for "HTML Source Directory".

To debug your Action Handler carry out these steps:

  1. Assume you have created an .xsql file which has reference to a custom Action Handler called MyActionHandler.
  2. Debug this Action Handler because it is not exactly behaving as you expect.
  3. Set breakpoints in your Java source file.
  4. Right mouse click on the .xsql file and then choose Debug... from the menu.

    See Also:

    The JDeveloper Guide under the online HELP menu.

Building XML Applications with JDeveloper

Consider the following example that demonstrates how XML is used to represent data, not present it. It shows the many to one relationship between employees and departments.

JDeveloper XDK Example 1: BC4J Metadata

<Departments>
<Dept>
   <Deptno>10</Deptno>
   <Dname>Sales></Dname>
   <Loc>
   <Employees>
     <Employee>
        <Empno>1001></Empno>
        <Ename>Scott</Ename>
        <Salary>80000</Salary>
     </Employee>
   </Employees>
...
     </Employee>
   </Employees>
</Dept>
<Dept>
...

Procedure for Building Applications in JDeveloper

To build an XSQL project in JDeveloper carry out the following steps:

  1. Start a New JDeveloper Project by selecting File >New Project.
  2. Create a Business Components for Java application.
  3. Choose File>New from the menu. Click OK.
  4. Choose WebObjects>XSQL from the menus.
  5. Position the cursor between the <PAGE> and <?PAGE> tags.
  6. From Component Palette, choose ViewObjects Show tag.
  7. Select the application module from the list that pops up.

When you finish these steps in the Page Wizard, you should have an XSQL Page based on the Business Components for Java (BC4J) framework View objects. When you run this page, it sends the XML data to your browser. You could optionally create a stylesheet to format the data so that it appears in a way that you prefer or you can tune it so that it can be displayed on a PDA or cellphone.

Using XSQL Servlet from JDeveloper

XSQL Servlet offers a productive and easy way to get XML in and out of the database.

See Also:

Chapter 9, "XSQL Pages Publishing Framework" for information about how to use XSQL Servlet.

When using XSQL Servlet in JDeveloper, you do not need to include the XSQL Runtime in your project as this is already done for any new XSQL Page or XSQL wizard-based application.

Using simple scripts you can do the following from JDeveloper:

Consider a simple query in an XSQL file, which returns details about all the employees in the emp table. The XSQL code to get this information would be as shown in Example 2.

JDeveloper XSQL Example 2: Employee Data from Table emp: emp.xsql

<?xml version="1.0"?> 
<xsql:query xmlns:xsql="urn:oracle-xsql" connection="demo"> 
    select * 
    from emp 
    order by empno 
</xsql:query> 

Figure 24-3 shows what the raw employee XML data displayed on the browser.

Figure 24-3 Employee Data in Raw XML Format

Text description of jdev_08.jpg follows.

Text description of the illustration jdev_08.jpg

If you want to output your data in a tabular form, make a small modification to your XSQL code to specify a stylesheet. The changes you would make in this example are shown later highlighted.

JDeveloper XSQL Example 3: Employee Data with Stylesheet Added

<?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="emp.xsl"?> 
<xsql:query xmlns:xsql="urn:oracle-xsql" connection="demo"> 
    select * 
    from emp 
    order by empno 
</xsql:query> 

The result would be a table. You can do a lot more with XSQL Servlet of course.

See Also:

Chapter 9, "XSQL Pages Publishing Framework" and also the XDK for Java, XSQL Servlet Release Notes on OTN at http://otn.oracle.com/tech/xml

Frequently Asked Questions About JDeveloper and XML Applications

This section lists JDeveloper questions and answers.

How Do I Construct an XML Document in JSP?

I am dynamically constructing an XML document in a JSP page (from the results of data returned by a PL/SQL API) using the classes generated by the Class generator (based on a DTD) and then applying a XSL stylesheet to render the transformation in HTML. I see that this works fine only for the first time, that is, when the JSP is first accessed (and internally compiled), and fails every time the same page is accessed thereafter.

The error I get is:

"oracle.xml.parser.v2.XMLDOMException: Node doesn't belong to the current 
document"

The only way to make it work again is to compile the JSP, by just 'touching' the JSP page. Of course, this again works only once. I am using Apache JServ.

How can this be overcome? Does the static code in the Java class generated for the top level node have to do anything with it?

Answer: It seems to me that you may have stored some invalid state in your JSP. The XML Parser picks this invalid state, then, throws the exception you mentioned.

As far as I know, CRM does not use an HTTP session in their application. I guess this is true in your case also. You may have used a member variable to store some invalid state unintentionally. Member variables are the variables declared by the following syntax:

<%! %> 

For example:

<%! Document doc=null; %>

Many JSP users misunderstand that they need to use this syntax to declare variables. In fact, you do not need to do that. In most of cases, you do not need a member variable. Member variables are shared by all requests and are initialized only once in the lifetime of the JSP.

Most users need stack variables or method variables. These are created and initialized for each request. They are declared as a form of scriptlet as shown in the following example:

<% Document doc=null; %>

In this case, every request has its own doc object, and the doc object is initialized to null for each request.

If you do not store an "invalid" state in session or method variables in your JSP, then there may be other reasons that cause this.

Is There a Way to Use the @code Directly in the document() Line?

Now, if I wish to use the @code as a key, I use

<xsl:template match="aTextNode">
    ...
   <xsl:param name="labelCode" select="@code"/>
     <xsl:value-of
 select="document('messages.xml')/messages/msg[@id=$labelCode and
 @lang=$lang]"/>
    ...
   </xsl:template>

that works too, but I was wondering if there is a way to use the @code directly in the document() line?

Answer: This is what the current() function is useful for. Rather than:

<xsl:param name="labelCode" select="@code"/>
<xsl:value-of
select="document('messages.xml')/messages/msg[@id=$labelCode and
@lang=$lang]"/>

you can do:

<xsl:value-of
select="document('messages.xml')/messages/msg[@id=current()/@code
                      and @lang = $lang]"/>

How Do I Retrieve Data from messages.xml?

Is it, or will it be, possible to retrieve the data stored in messages.xml from the database? How is the document() instruction going to work where listener and servlet will run inside the database?

Answer: Yes. By the spec, the XSLT engine should read and cache the document referred to in the document() function. It caches the parsed document based on the string-form of the URI you pass in, so here's how you can achieve a database-based message lookup:

  1. CREATE TABLE MESSAGES (lang VARCHAR2(2), code NUMBER, message VARCHAR2(200));
  2. Create an XSQL page like msg.xsql:
    <xsql:query lang="en" xmlns:xsql="urn:oracle-xsql" connection="demo"
                row-element="" rowset-element="">
          select message
            from messages
           where lang = '{@lang}'
             and code = {@code}
    </xsql:query>
    
    
  3. Create a stylesheet that uses msg.xsql in the document() function as in this example:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
      <xsl:template match="/">
      <html><body>
        In English my name is
          <xsl:call-template name="msg">
             <xsl:with-param name="code">101</xsl:with-param>
          </xsl:call-template><br/>
        En espanol mi nombre es
          <xsl:call-template name="msg">
             <xsl:with-param name="code">101</xsl:with-param>
             <xsl:with-param name="lang">es</xsl:with-param>
          </xsl:call-template><br/>
        En fran&#231;ais, je m'appelle
          <xsl:call-template name="msg">
             <xsl:with-param name="code">101</xsl:with-param>
             <xsl:with-param name="lang">fr</xsl:with-param>
          </xsl:call-template><br/>
        In italiano, mi chiamo
          <xsl:call-template name="msg">
             <xsl:with-param name="code">101</xsl:with-param>
             <xsl:with-param name="lang">it</xsl:with-param>
          </xsl:call-template>
      </body></html>
      </xsl:template>
      <xsl:template name="msg">
        <xsl:param name="lang">en</xsl:param>
        <xsl:param name="code"/>
        <xsl:variable name="msgurl"
    select="concat('http://xml/msg.xsql?lang=',$lang,'&amp;code=',$code)"/>
        <xsl:value-of select="document($msgurl)/MESSAGE"/>
      </xsl:template>
    </xsl:stylesheet>
    
    
  4. Try it out at http://xml/testmessage.xsql

This is great if you want to fetch the message from over the web. Alternatively, you could use the msg.xsql preceding but include it in your XSQL Page if that makes sense using:

<xsql:include-xsql href="msg.xsql?lang={@lang}&amp;code={@code}"/>

Or you could write your own custom action handler to use JDBC to fetch the message and include it in the XSQL page yourself.

How Do I Move Complex XML Documents to a Database?

I am moving XML documents to an Oracle database. The documents are fairly complex. Can an XML document and the Oracle Developer's Kit (XDK) generate a possible DDL format for how the XML Document should be stored in the database, ideally generating an Object-Relational Structure. Does anyone know of a tool that can do this?

Answer: The best way may be to use the Class Generator. Use the XML SQL Utility (XSU) if DTD files are not already created. You'll still have to write a mapping program.

Another method is to create views and write stored procedures to update multiple tables. Unfortunately, you'll have to create your tables and views beforehand in either case.


Go to previous page Go to next page
Oracle
Copyright © 2001, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback