[jboss-cvs] JBossAS SVN: r75880 - projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 16 05:47:53 EDT 2008


Author: alesj
Date: 2008-07-16 05:47:53 -0400 (Wed, 16 Jul 2008)
New Revision: 75880

Modified:
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleObjectModelFactoryDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java
Log:
[JBDEPLOY-58]; adding alt mappings.

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java	2008-07-16 08:20:24 UTC (rev 75879)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java	2008-07-16 09:47:53 UTC (rev 75880)
@@ -21,12 +21,14 @@
  */
 package org.jboss.deployers.vfs.spi.deployer;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
-import java.util.HashSet;
-import java.util.ArrayList;
-import java.io.InputStream;
-import java.io.IOException;
+import java.util.HashMap;
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithOutput;
@@ -44,6 +46,9 @@
  */
 public abstract class AbstractVFSParsingDeployer<T> extends AbstractParsingDeployerWithOutput<T> implements FileMatcher
 {
+   /** The alt mappings key */
+   private static final String ALT_MAPPINGS_MAP_KEY = "AltMappingsMap";
+
    /** The allow multiple fiels flag */
    private boolean allowMultipleFiles;
 
@@ -112,18 +117,46 @@
    }
 
    /**
+    * Get the alt mappings map.
+    *
+    * @param unit the deployment unit
+    * @return alt mappings map from attachments
+    */
+   @SuppressWarnings("unchecked")
+   protected static Map<String, Class<?>> getAltMappings(DeploymentUnit unit)
+   {
+      if (unit == null)
+         throw new IllegalArgumentException("Null deployment unit");
+
+      return unit.getAttachment(ALT_MAPPINGS_MAP_KEY, Map.class);
+   }
+
+   /**
     * Get metadata file.
     * First try altDD, then fallback to original name.
     *
     * @param unit the vfs deployment unit
-    * @param altPrefix altDD prefix
+    * @param altExpectedClass the expected class of altDD
     * @param originalName the original file name
+    * @param checkMetaDataFile should we fall back to metadata file
     * @return metadata file or null if it doesn't exist
     */
-   protected VirtualFile getMetadataFile(VFSDeploymentUnit unit, String altPrefix, String originalName)
+   protected VirtualFile getMetadataFile(VFSDeploymentUnit unit, Class<?> altExpectedClass, String originalName, boolean checkMetaDataFile)
    {
+      String altPrefix = (altExpectedClass != null ? altExpectedClass.getName() : originalName);
       VirtualFile file = unit.getAttachment(altPrefix + ".altDD", VirtualFile.class);
-      if(file == null && originalName != null)
+
+      if (file != null && altExpectedClass != null)
+      {
+         Map<String, Class<?>> altMappingsMap = getAltMappings(unit);
+         if (altMappingsMap == null)
+         {
+            altMappingsMap = new HashMap<String, Class<?>>();
+            unit.addAttachment(ALT_MAPPINGS_MAP_KEY, altMappingsMap, Map.class);
+         }
+         altMappingsMap.put(file.getName(), altExpectedClass);
+      }
+      if(checkMetaDataFile && file == null)
          file = unit.getMetaDataFile(originalName);
 
       return file;
@@ -132,39 +165,23 @@
    /**
     * Match file name to metadata class.
     *
+    * @param unit the deployment unit
     * @param fileName the file name
     * @return matching metadata class
     */
-   protected Class<?> matchFileToClass(String fileName)
+   protected Class<?> matchFileToClass(DeploymentUnit unit, String fileName)
    {
-      return null;
+      Map<String, Class<?>> altMappingsMap = getAltMappings(unit);
+      return altMappingsMap != null ? altMappingsMap.get(fileName) : null;
    }
 
-   /**
-    * Get altDD prefix from file name.
-    *
-    * First look into matching metadata classes.
-    * If no match found, fall back to file name.
-    *
-    * @param fileName the file name
-    * @return altDD prefix
-    */
-   protected String getAltDDPrefix(String fileName)
-   {
-      Class<?> expectedClass = matchFileToClass(fileName);
-      if (expectedClass != null)
-         return expectedClass.getName();
-      else
-         return fileName;
-   }
-
    @Override
    protected T parse(DeploymentUnit unit, String name, T root) throws Exception
    {
       // Try to find the metadata
       VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
 
-      VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput().getName(), name);
+      VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput(), name, true);
       if(file == null)
             return null;
 
@@ -183,7 +200,7 @@
 
       for (String name : names)
       {
-         VirtualFile file = getMetadataFile(vfsDeploymentUnit, getAltDDPrefix(name), name);
+         VirtualFile file = getMetadataFile(vfsDeploymentUnit, matchFileToClass(unit, name), name, true);
          if (file != null)
             files.add(file);
          else
@@ -208,7 +225,7 @@
       VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
 
       // let's check altDD first
-      VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput().getName(), null);
+      VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput(), name, false);
       if (file != null)
          return parseAndInit(vfsDeploymentUnit, file, root);
 
@@ -255,7 +272,7 @@
       for (String name : names)
       {
          // try finding altDD file
-         VirtualFile file = getMetadataFile(vfsDeploymentUnit, getAltDDPrefix(name), null);
+         VirtualFile file = getMetadataFile(vfsDeploymentUnit, matchFileToClass(unit, name), name, false);
          if (file == null)
          {
             List<VirtualFile> matched = vfsDeploymentUnit.getMetaDataFiles(name, suffix);

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleObjectModelFactoryDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleObjectModelFactoryDeployer.java	2008-07-16 08:20:24 UTC (rev 75879)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleObjectModelFactoryDeployer.java	2008-07-16 09:47:53 UTC (rev 75880)
@@ -51,7 +51,12 @@
          tRoot = expectedType.cast(root);
       else
          tRoot = null;
-      return getHelper().parse(expectedType, file, tRoot, getObjectModelFactory(expectedType, file, tRoot));
+
+      ObjectModelFactory objectModelFactory = getObjectModelFactory(expectedType, file, tRoot);
+      if (objectModelFactory == null)
+         log.warn("ObjectModelFactory factory is null, expectedType=" + expectedType + ", file=" + file);
+      
+      return getHelper().parse(expectedType, file, tRoot, objectModelFactory);
    }
 
    /**

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java	2008-07-16 08:20:24 UTC (rev 75879)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java	2008-07-16 09:47:53 UTC (rev 75880)
@@ -28,6 +28,7 @@
 import java.util.Set;
 
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -64,31 +65,44 @@
    /**
     * Match file to mapping metadata class.
     *
+    * @param unit the deployment unit
     * @param file the file
     * @return matching metadata class
     */
-   protected Class<?> matchFileToClass(VirtualFile file)
+   protected Class<?> matchFileToClass(DeploymentUnit unit, VirtualFile file)
    {
       if (file == null)
          throw new IllegalArgumentException("Null file");
 
-      return matchFileToClass(file.getName(), true);
+      return matchFileToClass(unit, file.getName(), true);
    }
 
-   protected Class<?> matchFileToClass(String fileName)
+   protected Class<?> matchFileToClass(DeploymentUnit unit, String fileName)
    {
-      return matchFileToClass(fileName, false);
+      return matchFileToClass(unit, fileName, false);
    }
 
    /**
     * Match file name mappings.
     *
+    * @param unit the deployment unit
     * @param fileName the file name
     * @param throwException should we throw an exception if no match found
     * @return match or null or IllegalArgumentException
     */
-   protected Class<?> matchFileToClass(String fileName, boolean throwException)
+   protected Class<?> matchFileToClass(DeploymentUnit unit, String fileName, boolean throwException)
    {
+      if (fileName == null)
+         throw new IllegalArgumentException("Null file name");
+
+      Map<String, Class<?>> altMappingsMap = getAltMappings(unit);
+      if (altMappingsMap != null)
+      {
+         Class<?> result = altMappingsMap.get(fileName);
+         if (result != null)
+            return result;
+      }
+
       Class<?> result = mappings.get(fileName);
       if (result == null)
       {
@@ -108,7 +122,7 @@
    @SuppressWarnings("unchecked")
    protected T parse(VFSDeploymentUnit unit, VirtualFile file, T root) throws Exception
    {
-      Class<?> expectedType = matchFileToClass(file);
+      Class<?> expectedType = matchFileToClass(unit, file);
       if (getOutput().isAssignableFrom(expectedType) == false)
          throw new IllegalArgumentException("Matched " + expectedType + " which is not assignable to output " + getOutput());
       if (root != null && expectedType.isInstance(root) == false)
@@ -136,7 +150,7 @@
       Map<Class<?> , List<Object>> metadata = new HashMap<Class<?>, List<Object>>();
       for (VirtualFile file : files)
       {
-         Class<?> clazz = matchFileToClass(file);
+         Class<?> clazz = matchFileToClass(unit, file);
          List<Object> instances = metadata.get(clazz);
          if (instances == null)
          {




More information about the jboss-cvs-commits mailing list