|
The First Try
For our first example we'll use an XML Schema file I'd used
earlier in an article about Castor. Here a simplified deployment descriptor for a web application
was used as an example. Let's look at a picture of this schema:
Figure 1. The structure of the web.xml schema (webapp.xsd)
To open a new window with a listing of the schema file click here.
Here's an example of a deployment descriptor file using this
schema, namely the one used by Struts' "blank
application":
Listing 1. web.xml for the Struts-blank
application
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
. . . (several other taglibs follow) . . .
</web-app>
Our first program will read and parse this file using XMLBeans.
The first step is to generate the specific XMLBeans classes from the
schema.
Go to the directory where your webapp.xsd file is
located and enter:
scomp -out
webapp.jar webapp.xsd The -out
parameter is used to name the output jar file. This is the
result you should see:  [There's a known bug in scomp. If
you receive a "CreateProcess exception", then the
scomp utility is trying to find the Java compiler (the
javac.exe file) in the Java runtime directory,
instead of looking in the JDK bin directory. The
fix is to set the location of the JDK bin-directory
in the start of the PATH environment variable. You
may find more information in the newsgroup(see the resources
section).
Look into the generated webapp.jar file to see what
was generated. You'll notice that the original schema file is
there and several files that contains the element names from the
xsd: WebApp, ServletMapping, Taglib etc. There are many files,
and all in all it's a somewhat confusing picture.
If you want to see the Java code that was generated there is a
"-src" option that saves the source to a specified
directory.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|