⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch13s135.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Configuring and Using JAXP 1.1 In JBoss</title><link rel="stylesheet" href="styles.css" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets Vimages/callouts/"><link rel="home" href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html" title="JBoss 3.0 Documentation"><link rel="up" href="ch13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13.html" title="Chapter 13. HOWTO"><link rel="previous" href="ch13s131.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s131.html" title="Customizing the JRMPContainerInvoker Socket Factories"><link rel="next" href="ch13s144.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s144.html" title="Clustering in JBoss 3.0 alpha"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="jboss.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/jboss.gif" border="0"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch13s131.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s131.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch13s144.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s144.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table><div class="section"><a name="d0e11833"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="d0e11833"></a>Configuring and Using JAXP 1.1 In JBoss</h2></div></div><p>
  <span class="author">Scott Stark</span>
  <tt>&lt;<a href="mailto:Scott_Stark@displayscape.com">Scott_Stark@displayscape.com</a>&gt;</tt>
 </p><div class="section"><a name="d0e11847"></a><div class="titlepage"><div><h3 class="title"><a name="d0e11847"></a>Introduction</h3></div></div><p>JBoss uses the JAXP 1.1 optional package to JAXP to parse and transform XML documents using a pure Java API that is independent of a particular XML processor implementation. This allows the flexibility to swap between XML processors without making application code changes. Version 1.1 includes an XSLT framework based on TrAX (Transformation API for XML) plus some updates to the parsing API to support DOM Level 2 and SAX version 2.0 and an improved scheme to locate pluggable implementations. </p></div><div class="section"><a name="d0e11852"></a><div class="titlepage"><div><h3 class="title"><a name="d0e11852"></a>Configuring XML Parsers and Transformers</h3></div></div><p>This section covers how one configures which xml parser and transformers the JBoss uses. It is based largely on the current <a href="javascript:if(confirm('http://java.sun.com/xml/download.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://java.sun.com/xml/download.html'" tppabs="http://java.sun.com/xml/download.html" target="_top">Java API for XML Processing (JAXP) 1.1</a> specification. The types of configurable objects include DOM parsers, SAX parsers and XSLT transformers. First we'll describe the configuration options for the various objects per the JAXP spec and then show how JBoss uses the configuration properties and how you can change them.</p><div class="section"><a name="howto.jaxp.sax"></a><div class="titlepage"><div><h4 class="title"><a name="howto.jaxp.sax"></a>SAX Parser Configuration</h4></div></div><p>The SAX Plugability classes allow an application programmer to provide an implementation of the
org.xml.sax.DefaultHandler API to a SAXParser implementation and parse XML documents. In order to obtain a SAXParser instance, an application programmer first obtains an instance of a SAXParserFactory.
The SAXParserFactory instance is obtained via the static newInstance method of the SAXParserFactory class. This method uses the following ordered lookup procedure to determine the SAXParserFactory implementation class to load:</p><div class="orderedlist"><ol type="1"><li><p><a name="d0e11866"></a>Use the javax.xml.parsers.SAXParserFactory system property</p></li><li><p><a name="d0e11869"></a>Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above.</p></li><li><p><a name="d0e11872"></a>Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API will look for the classname in the file META-INF/services/javax.xml.parsers.SAXParserFactory in jars available to the runtime.</p></li><li><p><a name="d0e11875"></a>Platform default SAXParserFactory instance.</p></li></ol></div></div><div class="section"><a name="howto.jaxp.dom"></a><div class="titlepage"><div><h4 class="title"><a name="howto.jaxp.dom"></a>DOM Parser Configuration</h4></div></div><p>The DOM plugability classes allow a programmer to parse an XML document and obtain an org.w3c.dom.Document object from a DocumentBuilder implementation which wraps an underlying DOM implementation. In order to obtain a DocumentBuilder instance, an application programmer first obtains an instance of a Document-BuilderFactory. The DocumentBuilderFactory instance is obtained via the static newInstance method of the DocumentBuilderFactory class. This method uses the following ordered lookup procedure to determine the DocumentBuilderFactory implementation class to load:</p><div class="orderedlist"><ol type="1"><li><p><a name="d0e11884"></a>Use the javax.xml.parsers.DocumentBuilderFactory system property</p></li><li><p><a name="d0e11887"></a>Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above.</p></li><li><p><a name="d0e11890"></a>Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API will look for the classname in the file META-INF/services/javax.xml.parsers.DocumentBuilderFactory in jars available to the runtime.</p></li><li><p><a name="d0e11893"></a>Platform default SAXParserFactory instance.</p></li></ol></div></div><div class="section"><a name="howto.jaxp.xslt"></a><div class="titlepage"><div><h4 class="title"><a name="howto.jaxp.xslt"></a>XSLT Transformer Configuration</h4></div></div><p>The XSLT Plugability classes allow an application programmer to obtain a Transformer object that is based on a specific XSLT stylesheet from a TransformerFactory implementation. In order to obtain a Transformer object, 
a programmer first obtains an instance of the TransformerFactory. The TransformerFactory instance is obtained via the static newInstance method of the TransformerFactory class. This method uses the following ordered lookup procedure to determine the TransformerFactory implementation class to load:</p><div class="orderedlist"><ol type="1"><li><p><a name="d0e11902"></a>Use the javax.xml.transform.TransformerFactory system property</p></li><li><p><a name="d0e11905"></a>Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above.</p></li><li><p><a name="d0e11908"></a>Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API will look for the classname in the file META-INF/services/javax.xml.transform.TransformerFactory in jars available to the runtime.</p></li><li><p><a name="d0e11911"></a>Platform default TransformFactory instance.</p></li></ol></div></div><div class="section"><a name="howto.jaxp.jboss.config"></a><div class="titlepage"><div><h4 class="title"><a name="howto.jaxp.jboss.config"></a>Changing the JBoss Defaults</h4></div></div><p>JBoss uses a DOM DocumentBuilder to parse the jboss.jcml configuration file. The run.bat and run.sh startup scripts sets the javax.xml.parsers.DocumentBuilderFactory and  javax.xml.parsers.SAXParserFactory system properties to the bundled Crimson 1.1 DOM and SAX parsers contained in lib/crimson.jar. <a href="ch13s135.html#howto.jaxp.run.sh.crimson" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s135.html#howto.jaxp.run.sh.crimson" title="Figure 13.30. The run.sh setup for the Crimson xml parsers">Figure 13.30</a> shows the setup.</p><div class="figure"><p><a name="howto.jaxp.run.sh.crimson"></a><b>Figure 13.30. The run.sh setup for the Crimson xml parsers</b></p><pre class="programlisting"># Add the XML parser jars and set the JAXP factory names
# Crimson parser JAXP setup(default)
CLASSPATH=$CLASSPATH:../lib/crimson.jar
JAXP=-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.crimson.jaxp.DocumentBuilderFactoryImpl
JAXP="$JAXP -Djavax.xml.parsers.SAXParserFactory=org.apache.crimson.jaxp.SAXParserFactoryImpl"</pre></div><p>To change JBoss to use the Xerces parser, you would need change the setup to that shown in <a href="ch13s135.html#howto.jaxp.run.sh.xerces" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s135.html#howto.jaxp.run.sh.xerces" title="Figure 13.31. The run.sh setup for the Xerces xml parsers">Figure 13.31</a> assuming you copied the xerces.jar into the JBoss lib directory.</p><div class="figure"><p><a name="howto.jaxp.run.sh.xerces"></a><b>Figure 13.31. The run.sh setup for the Xerces xml parsers</b></p><pre class="programlisting"># Add the XML parser jars and set the JAXP factory names
# Xerces parser JAXP setup
CLASSPATH=$CLASSPATH:../lib/xerces.jar
JAXP=-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
JAXP="$JAXP -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"</pre></div><p>JBoss does not currently use any XSLT transformers and so does not set a default value for the javax.xml.transform.TransformerFactory system property. To setup the desired transformer you are free to use any of the approaches described in <a href="ch13s135.html#howto.jaxp.xslt" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s135.html#howto.jaxp.xslt" title="XSLT Transformer Configuration">the section called &#8220;XSLT Transformer Configuration&#8221;</a>.</p></div></div><div class="section"><a name="d0e11939"></a><div class="titlepage"><div><h3 class="title"><a name="d0e11939"></a>Using JAXP</h3></div></div><p>To aide in porting your xml parser creation to use the JAXP package, this section gives some small code fragments showing the use of each type of factory. See the JAXP spec or JavaDoc for the full usage details.</p><div class="figure"><p><a name="jaxp.howto.sax.example"></a><b>Figure 13.32. Example SAX Parser Creation</b></p><pre class="programlisting">import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

SAXParser parser = null;
DefaultHandler handler = new DefaultHandler()
{
 ...
}

try
{
 SAXParserFactory factory = SAXParserFactory.newInstance();
 parser = factory.newSAXParser();
 String docURI = ...;
 parser.parse(docURI);
}
catch(SAXException e)
{
 ...
}
catch(java.io.IOException e)
{
 ...
}
catch(ParserConfigurationException e)
{
 ...
}
catch(FactoryConfigurationError e)
{
 ...
}</pre></div><div class="figure"><p><a name="jaxp.howto.dom.example"></a><b>Figure 13.33. Example DOM Parser Creation</b></p><pre class="programlisting">import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -