geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Geronimo Wiki] Update of "Advanced Plugin Sample" by AaronMulder
Date Sat, 10 Jun 2006 23:15:51 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Geronimo Wiki" for change notification.

The following page has been changed by AaronMulder:
http://wiki.apache.org/geronimo/Advanced_Plugin_Sample

------------------------------------------------------------------------------
  }}}
  
  === Quartz Job Deployer ===
+ 
+ The deployer has a couple main responsibilites:
+  * Check whether this deployer can deploy the requested module
+  * Confirm that the deployment plan is valid
+  * Generate a Module ID for the deployment
+  * Create GBeans that will be the "deployed" form of the module
+ 
+ Generally, this can be reduced to "input XML, output either null or Module ID plus GBeans".
+ 
+ Here's the deployer:
  
  {{{
  /**
@@ -914, +924 @@

   * @version $Rev: 355877 $ $Date: 2005-12-10 21:48:27 -0500 (Sat, 10 Dec 2005) $
   */
  public class QuartzJobDeployer implements ConfigurationBuilder {
-     private static final QName SERVICE_QNAME = JobsDocument.type.getDocumentElementName();
+     private static final QName JOBS_QNAME = JobsDocument.type.getDocumentElementName();
  
      private final Environment defaultEnvironment;
      private final Collection repositories;
@@ -956, +966 @@

              XmlCursor cursor = xmlObject.newCursor();
              try {
                  cursor.toFirstChild();
-                 if (!SERVICE_QNAME.equals(cursor.getName())) {
+                 if (!JOBS_QNAME.equals(cursor.getName())) {
                      return null;
                  }
              } finally {
@@ -1105, +1115 @@

      }
  }
  }}}
+ 
+ One thing to notice is how the Quartz Job Deployment Plan is connected to the Quartz Job
Deployer.  It is based on the schema namespace ({{{http://geronimo.apache.org/xml/ns/plugins/quartz-0.1}}}),
and the fact that the plan was in the right place for us to find to begin with.  For all the
deployers we've done so far, we use XMLBeans to create JavaBeans connected to the schema.
 Then we use XMLBeans to read in the deployment plan, and check whether it's the type this
deployer expects.  Here's an excerpt from the deployer above:
+ {{{
+ XmlObject xmlObject;
+ if (planFile != null) {
+     xmlObject = XmlBeansUtil.parse(planFile.toURL());
+ } else {
+     URL path = DeploymentUtil.createJarURL(jarFile, "META-INF/geronimo-quartz.xml");
+     try {
+         xmlObject = XmlBeansUtil.parse(path);
+     } catch (FileNotFoundException e) {
+         // It has a JAR but no plan, and nothing at META-INF/geronimo-quartz.xml,
+         // therefore it's not a quartz job deployment
+         return null;
+     }
+ }
+ if (xmlObject == null) {
+     return null;
+ }
+ }}}
+ 
+ This part establishes that we can load a plan at all.  If not, it either means no plan was
provided, or the plan is in the module at a different location (e.g. {{{WEB-INF/geronimo-web.xml}}},
meaning it's definitely not a Quartz job).  Either way, this deployer can't handle the archive
so we return null.
+ 
+ If we get past that, it means that we found a plan.  So we go on to check the type:
+ {{{
+ XmlCursor cursor = xmlObject.newCursor();
+ try {
+     cursor.toFirstChild();
+     if (!SERVICE_QNAME.equals(cursor.getName())) {
+         return null;
+     }
+ } finally {
+     cursor.dispose();
+ }
+ }}}
+ The constant JOBS_QNAME is a reference to the schema namespace of the first element in the
file.  If it's the one we're looking for, great.  Otherwise, even though we found a plan,
it was not the right *type* of plan (e.g. someone passed a web plan on the command line),
so this deployer can't handle it.
+ 
+ If we get past those two checks (plan present and plan has correct namespace) then we assume
that it really was meant for this deployer to handle, and for other kinds of errors (syntax
error in plan, etc.) we throw a deployment exception.  Some of the deployers have additional
logic to silently upgrade old-format plans to current-format plans, but this one does not.
  
  === Geronimo Plan for Quartz Deployer ===
  

Mime
View raw message