Oracle9i Application Developer's Guide - XML Release 1 (9.0.1) Part Number A88894-01 |
|
This chapter contains the following sections:
Oracle JDeveloper9i 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 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.
JDeveloper9i has a new schema-driven XML editor. See Figure 11-1. 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 JDeveloper9i 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 Developers Kit (XDK) is integrated into JDeveloper, so that Jdeveloper offers many utilities that 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.
Oracle Business Components for Java is a 100%-Java, XML-powered framework that enables productive development, portable deployment, and flexible customization of multi-tier, 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.
Oracle JDeveloper9i supports building XML applications. JDeveloper new integrated schema-driven XML code editor works on XML Schema-based documents such as:
with "tag-insight" to help you easily enter the correct elements and attributes as defined by the schema. In addition to the editing capabilities, JDeveloper's XML code editor also has the following features:
See Also:
|
JDeveloper9i is an IDE that has been written in Java and therefore, runs on Windows NT, Windows 2000, Linux and Solaris operating systems. It needs a minimum of 128 Mb RAM.
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.
The beta release of JDeveloper9i will be available in the summer of 2001 from the Oracle Technology Network (OTN) at http://otn.oracle.com.
The Business Components for Java (BC4J) framework in JDeveloper9i uses XML to define the metadata that represents the declarative settings and features of the objects. Custom or complex business logic can be implemented in Java.
The business components for Java framework that ships with JDeveloper uses XML to store metadata about its application components. Important information is now stored in a structured document rather than in Java source code. This makes the application easier to understand and customize.
The application is now customizable without having access to the source code.
Figure 11-2 shows how BC4J is used with XSQL servlet to generate XML documents.
Business rules can be changed on site without needing access to the underlying component source code.
In JDeveloper9i, you can build XSQL Pages which can integrate with BC4J application modules and thereby serve application logic from the middle tier to multiple clients. You can retrieve XML data and present it to any kind of a client device just by applying the corresponding stylesheet.
The following features will assist you in building XSQL clients with BC4J:
The Web Object Gallery has icons to assist in creating XSQL, XML, and XSL documents easily. When you click on them, the basic tags for these pages are generated and you can then enhance them.
The XSQL Pages icon is of special interest because the XSQL Element Wizard can be used, after generating your basic XSQL pages, to insert data bound tags in the XSQL pages. Figure 11-3 illustrates JDeveloper's Object Gallery.
XSQL Element Wizard 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 11-4 illustrates the JDeveloper9i XSQL Element Wizard.
When you need create XSQL pages while building a web application, you can invoke Page Wizard which allows 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.
The following lists JDeveloper9i's supported Oracle XML Developer's Kit for Java (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 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 'out of box'. You can also update the XDK for Java components with the latest versions downloaded from Oracle Technology Network (OTN) at http://technet.oracle.com/tech/xml.
Oracle XDK for Java also includes the XML Transviewer Beans. These are a set of Java Beans 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. You can drop these beans into the TOOLS palette and use them to build applications such as XML/XSL editors.
See Also:
Chapter 23, "Using XML Transviewer Beans" for more information on how to use the Transviewer Beans. |
Including the Oracle XML Parser for Java in your project allows you to write applications that can search and process XML documents. You can include the Oracle XML Parser in your project with one click as JDeveloper has a built-in library for it.
Code Insight makes understanding and using the code easier and in-place access to JavaDoc on the classes for reference. The XML parser for Java facilitates processing an XML document using either of the following interfaces:
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:
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 JDeveloper9i 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.
XSQL ActionHandlers 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 ActionHandler.
Your XSQL Pages should be in the directory specified in the Project Property "HTML Paths" settings for "HTML Source Directory".
To debug your ActionHandler carry out these steps:
Oracle JDeveloper has an XML Data Generator Web Bean. It generates XML containing the data from a View Object and renders it to the output stream of a JSP response.
You can author JSP pages that use XML and XSL to render a response to the client.
This XML Web Bean can be used in JSP and Servlet applications. It reads data from a Business Component (View Object) and produces the appropriate XML. The strength of this Web Bean is that it analyzes the Business Component Application and navigates through it's hierarchy to produce the nested XML.
The XML Web Beans also allows the specification of an XSL Stylesheet. In addition to XML, the Web Bean can then generate HTML, WML, transformed XML and any other text format.
Portal-To- Go and Oracle JDeveloper together offer an extremely powerful environment for developing mobile applications. Developers can use JDeveloper to generate XML from the database or from a Business Components for Java Application and use Portal-To-Go to deliver content to Web browsers, PDAs, or Cell phones.
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.
<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> ...
To build this project in JDeveloper9i carry out the following steps:
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.
The XML Data Generator Web (Bean) can be used in JSP and Servlet applications. It reads data from a Business Component (View Object) and produces the appropriate XML. The strength of this Web Bean is the following:
The Data Generator Web Bean is in the "Data Web Beans" category of the JSP Elements wizard. Figure 11-5 illustrates accessing the XML Data Generator Web (Bean) from the JSP Element Wizard.
Call the Element Wizard from your JSP or XSQL Page by right-clicking anywhere on the Page where you want to include an element. Specify the stylesheet as a parameter in the Element Wizard.
Once you launch this wizard, you can specify a stylesheet to apply to the XML data that you generate and see the result of your output.
Figure 11-6 is an example output displayed by applying an XSL stylesheet to the employee listing.
XSQL Servlet offers a productive and easy way to get XML in and out of the database.
See Also:
Chapter 3, "Oracle XML Developer Kits (XDKs) and Components: Overview and General FAQs" and Chapter 10, "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:
<?xml version="1.0"?> <xsql:query xmlns:xsql="urn:oracle-xsql" connection="demo"> select * from emp order by empno </xsql:query>
Figure 11-7 shows what the raw employee XML data displayed on the browser.
If you want to output your data in a tabular form as shown in Figure 11-6, make a small modification to your XSQL code to specify a stylesheet. The changes you would make in this example are shown below highlighted.
<?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 like the table shown in Figure 11-6. You can do a lot more with XSQL Servlet of course.
See Also:
Chapter 10, "XSQL Pages Publishing Framework" and also the XDK for Java, XSQL Servlet Release Notes on OTN at http://technet.oracle.com/tech/xml |
This mobile application is a Departments database application that demonstrates how Business Components for Java (BC4J) and XML can be used to develop applications that can be accessed over wireless devices. The application consists of two main parts:
Figure 11-8 shows schematically how the mobile application works with BC4J, XSQL Servlet, XSL Stylesheets, and Oracle9i.
You can see a more comprehensive demo of a similar application on http://otn.oracle.com/tech/xml
First create the BC4J application. It connects to the SCOTT schema on an Oracle9i database. Figure 11-9 shows the XML file containing the metadata about the DEPT object. See "JDeveloper XML Example 1: BC4J Metadata" .
You can then create JSP pages based upon this BC4J application. In the JSP pages you are introduced to the XML Data Generator Web Beans. Figure 11-10 shows the XSQL file which calls the JSP page to create the new department.
We create XSLT stylesheets to go with the various client devices that we are going to access our data from. In your XSQL files, you specify the list of stylesheets and the protocols they go with which basically ties the stylesheets to the client device.
Figure 11-11 shows an example code snippet of a stylesheet (indexPP.xsl) which transforms the XML data to HTML for displaying on a browser on the Palm Pilot emulator.
Figure 11-12 shows the Cell Phone Emulator running the Departments Application Client. It also shows the setup screen for the Cell Phone Emulator.
Figure 11-13 shows the Palm Pilot Emulator accessing the Departments Application via HandWeb Browser.
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, i.e 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?
It seems to me that you may have stored some "invalid" state in your JSP. And 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 per 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 per 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.
I am using XmlData to retrieve data from a BC4J. I Do not use XmlData from a JSP, but from a standalone java application. In the record I target, I have the value 'R & D'.
XmlData returns 'R & D', which is fine for HTTP, but not for my needs. Can XmlData not escape the characters, and just return what's in the database?
XmlData builds an in-memory DOM, so it must be the XML parser's serialization that's doing this. The only way I know is to do the following:
I have downloaded JDeveloper on my laptop (Windows 95 operating system). I am trying to run a sample XML parser program (SimpleParse.java). This program imports org.w3c.dom.Document class. I have set CLASSPATH in autoexe.bat with correct directory. The program runs on DOS prompt with "java SimpleParse <filename>" command. I am trying to run the same program through JDeveloper but it gives me following error:
"identifier org.w3c.dom.Document not found"
Am I missing something?
Make sure to include the Library named:
"Oracle XML Parser 2.0"
is in your project. This library is pre-defined with JDev 3.0and higher and you just need to visit the Project | Properties... and look at the "Paths" tab to see your project's library list.
Click the (Add...) button and pick the above library from the list.
The org.w3c.dom.* interfaces are included in this Jar. They come from the W3C and define the Document Object Model standard API's for working with a tree of XML nodes.
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 isn't a way to use the '@code' directly in the 'document()' line?
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]"/>
And finally, another question: it is - 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?
Sure. 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:
<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>
<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ç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,'&code=',$code)"/> <xsl:value-of select="document($msgurl)/MESSAGE"/> </xsl:template> </xsl:stylesheet>
This is great if you want to fetch the message from over the web. Alternatively, you could use the msg.xsql above but include it in your XSQL Page if that makes sense using:
<xsql:include-xsql href="msg.xsql?lang={@lang}&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.
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?
The best way may be to use the Class Generator. Use XML SQL Utility 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.
Business Components for Java (BC4J) framework provides a general, meta-data-driven solution for mapping E-Commerce XML Messages into and out of the database. BC4J has a technical white paper on its features available at http://otn.oracle.com/products/jdev/info/techwp20/wp.html.
It is a Pure-Java, XML-Based business components framework for making building E-Commerce applications easier. It is a Java framework usable on its own, but also has tight development support built-into JDeveloper 3.0 IDE, available for download from http://otn.oracle.com/software/.
BC4J lets you flexibly map hierarchies of SQL-based "view components" to underlying business components that manage all application behavior (rules and processes) in a uniform way. It also supports *dynamic* functionality, so most of its features can be driven completely off XML metadata.
You can build a layer which flexibly maps any XML Document into and out of the database using this framework. One key benefit is that when XML Documents are put into the system, they automatically can have all the same business rules validated.
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|