[CVS jcontainer] Add in classman docs

Peter Donald <pdonald-yCVjj/[email protected]> Wed, 31 Mar 2004 22:45:55 -0600
Newsgroups gmane.comp.java.jcontainer.cvs
Message-ID <[email protected]>
<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>jcontainer/loom/site/xdocs/reference</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1"><span id="added">classman.xml</span></a></tt></td><td align="right" id="added">+166</td><td></td><td nowrap="nowrap" align="right">added <a href="http://xstream.cvs.codehaus.org/jcontainer/loom/site/xdocs/reference/classman.xml?rev=1.1&amp;content-type=text/vnd.viewcvs-markup">1.1</a></td></tr>
</table>
<pre class="comment">
Add in classman docs
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname" id="added"><a href="http://xstream.cvs.codehaus.org/jcontainer">jcontainer</a>/<a href="http://xstream.cvs.codehaus.org/jcontainer/loom">loom</a>/<a href="http://xstream.cvs.codehaus.org/jcontainer/loom/site">site</a>/<a href="http://xstream.cvs.codehaus.org/jcontainer/loom/site/xdocs">xdocs</a>/<a href="http://xstream.cvs.codehaus.org/jcontainer/loom/site/xdocs/reference">reference</a><br /></span>
<div class="fileheader" id="added"><big><b>classman.xml</b></big> <small id="info">added at <a href="http://xstream.cvs.codehaus.org/jcontainer/loom/site/xdocs/reference/classman.xml?rev=1.1&amp;content-type=text/vnd.viewcvs-markup">1.1</a></small></div>
<pre class="diff"><small id="info">diff -N classman.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ classman.xml	1 Apr 2004 04:45:55 -0000	1.1
@@ -0,0 +1,166 @@
</small></pre><pre class="diff" id="added">+&lt;?xml version="1.0"?&gt;
+
+&lt;document&gt;
+    &lt;properties&gt;
+        &lt;title&gt;ClassMan - Overview&lt;/title&gt;
+        &lt;author&gt;Peter Donald&lt;/author&gt;
+    &lt;/properties&gt;
+    &lt;body&gt;
+        &lt;section name="Introduction"&gt;
+            &lt;p&gt;The ClassMan toolkit integrated into Loom is a set of utility
+            classes that enable ClassLoader hierarchies to be constructed from
+            xml configurations. The toolkit supports hierarchial ClassLoaders
+            and ClassLoaders defined by directed graphs via the use of "Join"
+            ClassLoaders that can have multiple parents. This results in
+            construction of a ClassLoader lattice.&lt;/p&gt;
+            &lt;p&gt;Each non-Join ClassLoader can be defined in terms of;&lt;/p&gt;
+            &lt;ul&gt;
+                &lt;li&gt;Entrys: URLs designating either a directory or a file&lt;/li&gt;
+                &lt;li&gt;FileSets: Sets of files defined in a manner similar to Ants Filests.&lt;/li&gt;
+                &lt;li&gt;
+                    &lt;a href="../Extension.html"&gt;
+                Extensions&lt;/a&gt;: Definitions of Extensions, aka "Optional Packages".
+                &lt;/li&gt;
+            &lt;/ul&gt;
+            &lt;p&gt;Each ClassLoader also has a name and a parent. The parent is the
+            name of the parent ClassLoader. Usually the parent ClassLoaders are
+            one of the predefined ClassLoaders. The predefined are passed into
+            the ClassMan toolkit from external application code.&lt;/p&gt;
+            &lt;p&gt;The predefined ClassLoaders are generally named according to
+            a pattern that places the '*' at start and end of name. ie
+            "*myPredefinedClassLoader*". Loom predefines the following
+            classloaders.&lt;/p&gt;
+            &lt;ul&gt;
+                &lt;li&gt;*system*: The System ClassLoader.&lt;/li&gt;
+                &lt;li&gt;*common*: Common between container and application code.&lt;/li&gt;
+                &lt;li&gt;*shared*: Shared between all application code. Note: This is currently
+                equivelent to *common*.&lt;/li&gt;
+            &lt;/ul&gt;
+            &lt;p&gt;The commented
+                &lt;a href="classloader.dtd"&gt;DTD&lt;/a&gt; describes the
+            descriptor format explicitly.
+            &lt;/p&gt;
+        &lt;/section&gt;
+        &lt;section name="Loom Sample"&gt;
+            &lt;p&gt;Let us also assume that we want to host a servlet container
+            (like Catalina, Jo! or Jetty) in Loom. The servlet
+            specification requires that the servlets are capable of
+            "seeing" the servlet API but recomends strongly that no servlet
+            should be able to access any container specific classes.&lt;/p&gt;
+            &lt;p&gt;To satisfy this requirement we decided to place the
+            Servlet API classes in a parent ClassLoader to the Containers
+            ClassLoader and each Web Applications ClassLoader. ie&lt;/p&gt;
+            &lt;pre&gt;&lt;![CDATA[
+     Servlet API CL
+           |
+    +------+------+
+    |             |
+ Servlet        WebApp
+Container         CL
+    CL
+            ]]&gt;&lt;/pre&gt;
+            &lt;p&gt;This way, both the Container and the WebApp ClassLoaders will
+            load the Servlet API from the same ClassLoader.&lt;/p&gt;
+            &lt;p&gt;Unfortunately, in our case Loom already assembles the
+            Servlet Container CL by default and does not give us the
+            opportunity to construct the Servlet API CL as a parent ClassLoader.
+            Luckily we can overide this using the ClassMan toolkit using the
+            following configuration file.&lt;/p&gt;
+            &lt;source&gt;&lt;![CDATA[
+&lt;classloaders default="container" version="1.0"&gt;
+
+  &lt;!-- needed to run under earlier JVMs that do not include JNDI --&gt;
+  &lt;classloader name="jndi-api" parent="*system*"&gt;
+    &lt;entry location="sar:SAR-INF/ext/jndi.jar"/&gt;
+  &lt;/classloader&gt;
+
+  &lt;!--
+    The actual Servlet API classLoader. Note that this does not specify
+    a physical location but instead defines an extension. This allows
+    the container to search for the library that best satisfies this
+    extension. Usually all the extensions are stored in a central directory
+    and Loom will search through the jars in central to find the servlet
+    jar. This allows several applications to share the same jar.
+  --&gt;
+  &lt;classloader name="servlet-api" parent="*system*"&gt;
+    &lt;extension&gt;
+      &lt;name&gt;javax.servlet&lt;/name&gt;
+      &lt;specification-version&gt;2.3&lt;/specification-version&gt;
+      &lt;vendor-id&gt;org.apache.jakarta&lt;/vendor-id&gt;
+      &lt;vendor-version&gt;1.2.3.4&lt;/vendor-version&gt;
+    &lt;/extension&gt;
+  &lt;/classloader&gt;
+
+  &lt;!--
+    This is a special ClassLoader that merges two other
+    ClassLoaders together. When you try to load a class from
+    this ClassLoader, the ClassLoader will first try to load
+    the class from servlet-api ClassLoader and then try to
+    load the class from the jndi-api ClassLoader. This works
+    fine if the ClassLoaders define disjoint sets of classes.
+    ie No class should be loadable from both the servlet-api
+    ClassLoader and the jndi-api ClassLoader (with the exception
+    of Classes Loaded from System ClassLoader).
+  --&gt;
+  &lt;join name="webapp-common"&gt;
+     &lt;classloader-ref name="servlet-api"/&gt;
+     &lt;classloader-ref name="jndi-api"/&gt;
+  &lt;/join&gt;
+
+  &lt;!--
+    This classloader is needed to join the Loom API
+    and the Servlet API into one ClassLoader. This is needed
+    because the container is built using Loom APIs
+    but needs to share the Servlet APIs with the WebApps.
+  --&gt;
+  &lt;join name="container-base"&gt;
+     &lt;classloader-ref name="webapp-common"/&gt;
+     &lt;classloader-ref name="*common*"/&gt;
+  &lt;/join&gt;
+
+  &lt;!--
+    This classloader is the one used to actually load the
+    Servlet Container. We know this as it is specified as the
+    default ClassLoader in &lt;classloaders/&gt; element.
+  --&gt;
+  &lt;classloader name="container" parent="container-base"&gt;
+    &lt;entry location="sar:SAR-INF/classes/"/&gt;
+    &lt;fileset dir="sar:SAR-INF/lib/"&gt;
+      &lt;include name="*.jar"/&gt;
+    &lt;/fileset&gt;
+  &lt;/classloader&gt;
+
+&lt;/classloaders&gt;
+            ]]&gt;&lt;/source&gt;
+            &lt;p&gt;The first thing you notice about this is that
+            the ClassLoader hierarchy is much more complicated.
+            In fact the diagram now looks like;&lt;/p&gt;
+            &lt;pre&gt;&lt;![CDATA[
+          "servlet-api"   "jndi-api"
+               CL             CL
+                |             |
+                +------+------+
+                       |
+ "*common*"    "webapp-common" CL
+       |               |
+       +----+   +------+------+
+            |   |             |
+         "container-        WebApp
+             base"            CL
+               CL         (This is constructed
+               |           by Container but
+          "container"      shown for completeness)
+                CL
+            ]]&gt;&lt;/pre&gt;
+            &lt;p&gt;In reality we could have merged "servlet-api" and
+            "jndi-api" into "webapp-common" but we separated them for
+            illustration purposes.&lt;/p&gt;
+            &lt;p&gt;The above demonstrates one of the most complex examples
+            that you are likely to come across. This arose because there
+            was multiple "containers" hosted in same ClassLoader
+            hierarchy. The Servlet API specification requires that
+            implementation classes not be visible to API clients.
+            The Loom API specification requires the same thing.&lt;/p&gt;
+        &lt;/section&gt;
+    &lt;/body&gt;
+&lt;/document&gt;
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.8</small></center>
</body></html>