[jboss-cvs] JBossAS SVN: r103063 - projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 26 15:09:09 EDT 2010


Author: alesj
Date: 2010-03-26 15:09:08 -0400 (Fri, 26 Mar 2010)
New Revision: 103063

Modified:
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java
Log:
Extract module unit lookup code.

Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java	2010-03-26 18:51:45 UTC (rev 103062)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java	2010-03-26 19:09:08 UTC (rev 103063)
@@ -55,19 +55,11 @@
     */
    public static <T> T getUtil(DeploymentUnit unit, Class<T> utilType)
    {
-      if (unit == null)
-         throw new IllegalArgumentException("Null unit");
       if (utilType == null)
          throw new IllegalArgumentException("Null util type");
 
-      // group util per module
-      DeploymentUnit moduleUnit = unit;
-      while(moduleUnit != null && moduleUnit.isAttachmentPresent(Module.class) == false)
-         moduleUnit = moduleUnit.getParent();
+      DeploymentUnit moduleUnit = getModuleUnit(unit);
 
-      if (moduleUnit == null)
-         throw new IllegalArgumentException("No module in unit: " + unit);
-
       T util = moduleUnit.getAttachment(utilType);
       if (util == null)
       {
@@ -84,6 +76,28 @@
    }
 
    /**
+    * Get module unit.
+    *
+    * @param unit the current unit
+    * @return unit containing Module, or exception if no such unit exists
+    */
+   public static DeploymentUnit getModuleUnit(DeploymentUnit unit)
+   {
+      if (unit == null)
+         throw new IllegalArgumentException("Null unit");
+
+      // group util per module
+      DeploymentUnit moduleUnit = unit;
+      while(moduleUnit != null && moduleUnit.isAttachmentPresent(Module.class) == false)
+         moduleUnit = moduleUnit.getParent();
+
+      if (moduleUnit == null)
+         throw new IllegalArgumentException("No module in unit: " + unit);
+
+      return moduleUnit;
+   }
+
+   /**
     * Wrap util lookup in lazy lookup.
     *
     * @param unit the deployment unit




More information about the jboss-cvs-commits mailing list