[jboss-cvs] JBossAS SVN: r76662 - in projects/jboss-deployers/trunk: deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 5 08:55:48 EDT 2008


Author: adrian at jboss.org
Date: 2008-08-05 08:55:48 -0400 (Tue, 05 Aug 2008)
New Revision: 76662

Modified:
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/StructureDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSStructuralDeployers.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractCandidateStructureVisitor.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/CandidateStructureVisitorFactory.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/DefaultCandidateStructureVisitorFactory.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/VFSStructuralDeployersImpl.java
Log:
[JBDEPLOY-66] - Make a start on introducing the StructureContext - need to validate the replacement api

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java	2008-08-05 12:36:27 UTC (rev 76661)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java	2008-08-05 12:55:48 UTC (rev 76662)
@@ -22,11 +22,9 @@
 package org.jboss.deployers.vfs.plugins.structure;
 
 import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
 import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
-import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.logging.Logger;
-import org.jboss.virtual.VirtualFile;
 
 /**
  * StructureDeployerWrapper.<p>
@@ -61,21 +59,21 @@
       this.classLoader = SecurityActions.getContextClassLoader();
    }
    
-   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
+   public boolean determineStructure(StructureContext context) throws DeploymentException
    {
-      if (file == null)
-         throw new IllegalArgumentException("Null file");
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
 
       ClassLoader previous = SecurityActions.setContextClassLoader(classLoader);
       try
       {
-         boolean result = deployer.determineStructure(root, parent, file, metaData, deployers);
+         boolean result = deployer.determineStructure(context);
          if (log.isTraceEnabled())
          {
             if (result == false)
-               log.trace("Not recognised: " + file.getName());
+               log.trace("Not recognised: " + context.getName());
             else
-               log.trace("Recognised: " + file.getName());
+               log.trace("Recognised: " + context.getName());
          }
          return result;
       }

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/VFSStructuralDeployersImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/VFSStructuralDeployersImpl.java	2008-08-05 12:36:27 UTC (rev 76661)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/VFSStructuralDeployersImpl.java	2008-08-05 12:55:48 UTC (rev 76662)
@@ -36,6 +36,7 @@
 import org.jboss.deployers.spi.structure.StructureMetaDataFactory;
 import org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers;
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
 import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
@@ -134,10 +135,12 @@
       log.debug("Removed structure deployer " + deployer);
    }
    
+   @Deprecated // Remove this JBDEPLOY-66 
    public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData) throws DeploymentException
    {
       StructureMetaData structure = StructureMetaDataFactory.createStructureMetaData();
-      boolean result = doDetermineStructure(root, parent, file, structure);
+      StructureContext context = new StructureContext(root, parent, file, structure, this, null);
+      boolean result = doDetermineStructure(context);
       if (result)
       {
          String relativePath = AbstractStructureDeployer.getRelativePath(parent, file);
@@ -164,17 +167,46 @@
       return result;
    }
    
+   public boolean determineStructure(VirtualFile file, StructureContext parentContext) throws DeploymentException
+   {
+      StructureMetaData structure = StructureMetaDataFactory.createStructureMetaData();
+      StructureContext context = new StructureContext(file, structure, parentContext);
+      boolean result = doDetermineStructure(context);
+      if (result)
+      {
+         String relativePath = AbstractStructureDeployer.getRelativePath(context.getParent(), file);
+         
+         // Something said it recognised it
+         ContextInfo recognised = structure.getContext("");
+         if (recognised == null)
+            throw new IllegalStateException("Something recognised the deployment, but there is no context? " + file);
+         
+         // Create the context in the parent structure
+         ContextInfo parentContextInfo;
+         List<String> metaDataPath = recognised.getMetaDataPath();
+         if (metaDataPath == null || metaDataPath.isEmpty())
+            parentContextInfo = StructureMetaDataFactory.createContextInfo(relativePath, recognised.getClassPath());
+         else
+            parentContextInfo = StructureMetaDataFactory.createContextInfo(relativePath, metaDataPath, recognised.getClassPath());
+
+         // copy the modification type information
+         parentContextInfo.setModificationType(recognised.getModificationType());
+         StructureMetaData structureMetaData = parentContext.getMetaData();
+         structureMetaData.addContext(parentContextInfo);
+         MutableAttachments attachments = (MutableAttachments) parentContextInfo.getPredeterminedManagedObjects();
+         attachments.addAttachment(StructureMetaData.class, structure);
+      }
+      return result;
+   }
+   
    /**
     * Determine the structure
     * 
-    * @param root the root file
-    * @param parent the parent file
-    * @param file the file
-    * @param structureMetaData the structure metadata
+    * @param context the structure context
     * @return true when recognised
     * @throws DeploymentException for any error
     */
-   protected boolean doDetermineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData) throws DeploymentException
+   protected boolean doDetermineStructure(StructureContext context) throws DeploymentException
    {
       StructureDeployer[] theDeployers; 
       synchronized (this)
@@ -187,22 +219,22 @@
 
       boolean trace = log.isTraceEnabled();
       if (trace)
-         log.trace("Determining structure for " + file.getName() + " deployers=" + Arrays.asList(theDeployers));
+         log.trace("Determining structure for " + context.getName() + " deployers=" + Arrays.asList(theDeployers));
       
       
       boolean result = false;
       for (StructureDeployer deployer : theDeployers)
       {
-         if (deployer.determineStructure(root, parent, file, structureMetaData, this))
+         if (deployer.determineStructure(context))
          {
             if (trace)
-               log.trace(file.getName() + " recognised by " + deployer);
+               log.trace(context.getName() + " recognised by " + deployer);
             result = true;
             break;
          }
       }
       if (result == false && trace)
-         log.trace(file.getName() + " not recognised");
+         log.trace(context.getName() + " not recognised");
       return result;
    }
 
@@ -217,7 +249,8 @@
       VirtualFile root = vfsDeployment.getRoot();
       if (root == null)
          throw new IllegalStateException("Deployment has no root " + deployment);
-      if (doDetermineStructure(root, null, root, structure) == false)
+      StructureContext context = new StructureContext(root, structure, this);
+      if (doDetermineStructure(context) == false)
          throw new DeploymentException("No deployer recognised the structure of " + deployment.getName());
    }
 }

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/StructureDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/StructureDeployer.java	2008-08-05 12:36:27 UTC (rev 76661)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/StructureDeployer.java	2008-08-05 12:55:48 UTC (rev 76662)
@@ -21,10 +21,8 @@
  */
 package org.jboss.deployers.vfs.spi.structure;
 
-import org.jboss.deployers.spi.Ordered;
 import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.structure.StructureMetaData;
-import org.jboss.virtual.VirtualFile;
+import org.jboss.deployers.spi.Ordered;
 
 /**
  * A StructureDeployer translates a deployment virtual file root into
@@ -38,13 +36,9 @@
    /**
     * Determine the structure of a deployment
     * 
-    * @param root the root file
-    * @param parent the parent file
-    * @param file the candidate file of the deployment
-    * @param metaData the structure metadata to build
-    * @param deployers the available structure deployers
-    * @return true when it is recognised
-    * @throws DeploymentException for any error
+    * @param context the structure context
+    * @return true when it recognised the context
+    * @throws DeploymentException for an error
     */
-   boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException;
+   boolean determineStructure(StructureContext context) throws DeploymentException;
 }

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSStructuralDeployers.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSStructuralDeployers.java	2008-08-05 12:36:27 UTC (rev 76661)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSStructuralDeployers.java	2008-08-05 12:55:48 UTC (rev 76662)
@@ -43,5 +43,16 @@
     * @return true when recognised, false otherwise
     * @throws DeploymentException for any error
     */
+   @Deprecated // Remove this JBDEPLOY-66
    boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData structureMetaData) throws DeploymentException;
+
+   /**
+    * Determine the structure of a virtual file
+    *
+    * @param file the virtual file
+    * @param parentContext the parent context
+    * @return true when recognised, false otherwise
+    * @throws DeploymentException for any error
+    */
+   boolean determineStructure(VirtualFile file, StructureContext parentContext) throws DeploymentException;
 }

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractCandidateStructureVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractCandidateStructureVisitor.java	2008-08-05 12:36:27 UTC (rev 76661)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractCandidateStructureVisitor.java	2008-08-05 12:55:48 UTC (rev 76662)
@@ -25,7 +25,7 @@
 
 import org.jboss.deployers.spi.structure.ContextInfo;
 import org.jboss.deployers.spi.structure.StructureMetaData;
-import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
 import org.jboss.logging.Logger;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.VirtualFileFilter;
@@ -43,18 +43,9 @@
    /** The log */
    private static final Logger log = Logger.getLogger(AbstractCandidateStructureVisitor.class);
 
-   /** The root deployment file */
-   private final VirtualFile root;
+   /** The structure context */
+   private StructureContext context;
 
-   /** The parent deployment file */
-   private final VirtualFile parent;
-
-   /** The meta data */
-   private final StructureMetaData metaData;
-   
-   /** The deployers */
-   private final VFSStructuralDeployers deployers;
-
    /** Ignore directories */
    private boolean ignoreDirectories;
 
@@ -64,36 +55,27 @@
    /**
     * Create a new CandidateStructureVisitor.
     * 
-    * @param root the root
-    * @param parent the parent
-    * @param metaData the structure meta data
-    * @param deployers the structure deployers
+    * @param context the context
     * @throws IllegalArgumentException for a null parent
     */
-   public AbstractCandidateStructureVisitor(VirtualFile root, VirtualFile parent, StructureMetaData metaData, VFSStructuralDeployers deployers)
+   public AbstractCandidateStructureVisitor(StructureContext context)
    {
-      this(root, parent, metaData, deployers, null);
+      this(context, null);
    }
    
    /**
     * Create a new CandidateStructureVisitor.
     * 
-    * @param root the root
-    * @param parent the parent
-    * @param metaData the structure meta data
-    * @param deployers the structure deployers
+    * @param context the context
     * @param attributes the attributes
     * @throws IllegalArgumentException for a null parent
     */
-   public AbstractCandidateStructureVisitor(VirtualFile root, VirtualFile parent, StructureMetaData metaData, VFSStructuralDeployers deployers, VisitorAttributes attributes)
+   public AbstractCandidateStructureVisitor(StructureContext context, VisitorAttributes attributes)
    {
       super(attributes);
-      if (parent == null)
-         throw new IllegalArgumentException("Null parent");
-      this.root = root;
-      this.parent = parent;
-      this.metaData = metaData;
-      this.deployers = deployers;
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+      this.context = context;
    }
 
    /**
@@ -103,7 +85,7 @@
     */
    public VirtualFile getParent()
    {
-      return parent;
+      return context.getFile();
    }
 
    /**
@@ -148,9 +130,10 @@
 
    public void visit(VirtualFile file)
    {
-      String path = AbstractStructureDeployer.getRelativePath(parent, file);
-      ContextInfo context = metaData.getContext(path);
-      if (context == null)
+      String path = AbstractStructureDeployer.getRelativePath(context, file);
+      StructureMetaData metaData = context.getMetaData();
+      ContextInfo contextInfo = metaData.getContext(path);
+      if (contextInfo == null)
       {
          // Ignore directories when asked
          try
@@ -171,7 +154,7 @@
          try
          {
             // Ask the deployers to process this file
-            deployers.determineStructure(root, parent, file, metaData);
+            context.determineChildStructure(file);
          }
          catch (Exception e)
          {

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java	2008-08-05 12:36:27 UTC (rev 76661)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java	2008-08-05 12:55:48 UTC (rev 76662)
@@ -25,10 +25,12 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.structure.ClassPathEntry;
 import org.jboss.deployers.spi.structure.ContextInfo;
 import org.jboss.deployers.spi.structure.StructureMetaData;
 import org.jboss.deployers.spi.structure.StructureMetaDataFactory;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
 import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.logging.Logger;
@@ -64,6 +66,21 @@
    /**
     * Get the relative path between two virtual files
     * 
+    * @param context the structure context
+    * @param child the child
+    * @return the relative path
+    */
+   public static final String getRelativePath(StructureContext context, VirtualFile child)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      return getRelativePath(context.getParent(), child);
+   }
+
+   /**
+    * Get the relative path between two virtual files
+    * 
     * @param parent the parent
     * @param child the child
     * @return the relative path
@@ -112,6 +129,18 @@
       this.contextInfoOrder = contextInfoOrder;
    }
 
+   // This should be an abstract method JBDEPLOY-66
+   public boolean determineStructure(StructureContext context) throws DeploymentException
+   {
+      return determineStructure(context.getRoot(), context.getParent(), context.getFile(), context.getMetaData(), context.getDeployers());
+   }
+
+   @Deprecated // Remove this JBDEPLOY-66
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
+   {
+      return false;
+   }
+   
    /**
     * Get the candidateStructureVisitorFactory.
     * 
@@ -141,6 +170,7 @@
     * @param parent the parent file
     * @return true when top level
     */
+   @Deprecated // Remove JBDEPLOY-66 - use StructureContext.isTopLevel()
    public boolean isTopLevel(VirtualFile parent)
    {
       return parent == null;
@@ -149,6 +179,54 @@
    /**
     * Add an entry to the context classpath.
     * 
+    * @param structureContext - the structure context
+    * @param entry - the candidate file to add as a classpath entry
+    * @param includeEntry - a flag indicating if the entry should be added to
+    *    the classpath
+    * @param includeRootManifestCP - a flag indicating if the entry metainf
+    *    manifest classpath should be included.
+    * @param context - the context to populate
+    * @throws IOException on any IO error
+    */
+   protected void addClassPath(StructureContext structureContext, VirtualFile entry, boolean includeEntry, boolean includeRootManifestCP, ContextInfo context) throws IOException
+   {
+      boolean trace = log.isTraceEnabled();
+      
+      List<VirtualFile> paths = new ArrayList<VirtualFile>();
+
+      // The path we have been told to add
+      if (includeEntry)
+         paths.add(entry);
+
+      // Add the manifest locations
+      if (includeRootManifestCP && isLeaf(entry) == false)
+      {
+         try
+         {
+            VFSUtils.addManifestLocations(entry, paths);
+         }
+         catch(Exception e)
+         {
+            if (trace)
+               log.trace("Failed to add manifest locations", e);
+         }
+      }
+
+      // Translate from VirtualFile to relative paths
+      VirtualFile root = structureContext.getRoot();
+      for (VirtualFile vf : paths)
+      {
+         String entryPath = getRelativePath(root, vf);
+         ClassPathEntry cpe = StructureMetaDataFactory.createClassPathEntry(entryPath);
+         context.addClassPathEntry(cpe);
+         if (trace)
+            log.trace("Added classpath entry " + entryPath + " for " + vf.getName() + " from " + root);
+      }
+   }
+
+   /**
+    * Add an entry to the context classpath.
+    * 
     * @param root - the root file the classpath entry should be relative to
     * @param entry - the candidate file to add as a classpath entry
     * @param includeEntry - a flag indicating if the entry should be added to
@@ -158,6 +236,7 @@
     * @param context - the context to populate
     * @throws IOException on any IO error
     */
+   @Deprecated // Remove JBDEPLOY-66
    protected void addClassPath(VirtualFile root, VirtualFile entry, boolean includeEntry, boolean includeRootManifestCP, ContextInfo context) throws IOException
    {
       boolean trace = log.isTraceEnabled();
@@ -196,6 +275,35 @@
    /**
     * Add all children as candidates
     * 
+    * @param context the structure context
+    * @throws Exception for any error
+    */
+   protected void addAllChildren(StructureContext context) throws Exception
+   {
+      addChildren(context, null);
+   }
+
+   /**
+    * Add all children as candidates
+    * 
+    * @param context the structure context
+
+    * @param attributes the visitor attributes uses {@link VisitorAttributes#DEFAULT} when null
+    * @throws Exception for any error
+    */
+   protected void addChildren(StructureContext context, VisitorAttributes attributes) throws Exception
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      VirtualFile file = context.getFile();
+      VirtualFileVisitor visitor = candidateStructureVisitorFactory.createVisitor(context, attributes);
+      file.visit(visitor);
+   }
+
+   /**
+    * Add all children as candidates
+    * 
     * @param root the root context
     * @param parent the parent context
     * @param metaData the structure meta data
@@ -221,9 +329,9 @@
    {
       if (parent == null)
          throw new IllegalArgumentException("Null parent");
-      
-      VirtualFileVisitor visitor = candidateStructureVisitorFactory.createVisitor(root, parent, metaData, deployers, attributes);
-      parent.visit(visitor);
+
+      StructureContext context = new StructureContext(root, null, parent, metaData, deployers, null);
+      addChildren(context, attributes);
    }
    
    /**
@@ -233,7 +341,7 @@
     * @return true when it is a leaf
     * @throws IOException for any error
     */
-   protected boolean isLeaf(VirtualFile file) throws IOException
+   protected static boolean isLeaf(VirtualFile file) throws IOException
    {
       return SecurityActions.isLeaf(file);
    }
@@ -241,11 +349,39 @@
    /**
     * Create a context
     * 
+    * @param context the structure context
+    * @return the context info
+    * @throws IllegalArgumentException for a null root or structure metaData
+    */
+   protected ContextInfo createContext(StructureContext context)
+   {
+      return createContext(context, (String) null);
+   }
+
+   /**
+    * Create a context
+    *
+    * @param context the structure context
+    * @param metaDataPath the metadata path
+    * @return the context info
+    * @throws IllegalArgumentException for a null root or structure metaData
+    */
+   protected ContextInfo createContext(StructureContext context, String metaDataPath)
+   {
+      ContextInfo result = applyMetadataPath(context, metaDataPath);
+      applyStructure(context, result);
+      return result;
+   }
+   
+   /**
+    * Create a context
+    * 
     * @param root the root context
     * @param structureMetaData the structure metadata
     * @return the context info
     * @throws IllegalArgumentException for a null root or structure metaData
     */
+   @Deprecated // Remove JBDEPLOY-66
    protected ContextInfo createContext(VirtualFile root, StructureMetaData structureMetaData)
    {
       return createContext(root, (String)null, structureMetaData);
@@ -260,6 +396,7 @@
     * @return the context info
     * @throws IllegalArgumentException for a null root or structure metaData
     */
+   @Deprecated // Remove JBDEPLOY-66
    protected ContextInfo createContext(VirtualFile root, String metaDataPath, StructureMetaData structureMetaData)
    {
       ContextInfo result = applyMetadataPath(root, metaDataPath);
@@ -270,10 +407,47 @@
    /**
     * Apply metadata on root to create context.
     *
+    * @param context the context
+    * @param metaDataPath the metadata path
+    * @return the context info
+    */
+   protected ContextInfo applyMetadataPath(StructureContext context, String metaDataPath)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      // Determine whether the metadata path exists
+      if (metaDataPath != null)
+      {
+         VirtualFile root = context.getRoot();
+         try
+         {
+            VirtualFile child = root.getChild(metaDataPath);
+            if (child == null)
+               metaDataPath = null;
+         }
+         catch (IOException e)
+         {
+            log.warn("Not using metadata path " + metaDataPath + " for " + root.getName() + " reason: " + e.getMessage());
+            metaDataPath = null;
+         }
+      }
+
+      // Create and link the context
+      if (metaDataPath != null)
+         return StructureMetaDataFactory.createContextInfo("", metaDataPath, null);
+      else
+         return StructureMetaDataFactory.createContextInfo("", null);
+   }
+
+   /**
+    * Apply metadata on root to create context.
+    *
     * @param root the root context
     * @param metaDataPath the metadata path
     * @return the context info
     */
+   @Deprecated // Remove JBDEPLOY-66
    protected ContextInfo applyMetadataPath(VirtualFile root, String metaDataPath)
    {
       if (root == null)
@@ -305,12 +479,67 @@
    /**
     * Create a context
     *
+    * @param context the structure context
+    * @param metaDataPaths the metadata paths
+    * @return the context info
+    * @throws IllegalArgumentException for a null root or structure metaData
+    */
+   protected ContextInfo createContext(StructureContext context, String[] metaDataPaths)
+   {
+      ContextInfo result = applyMetadataPaths(context, metaDataPaths);
+      applyStructure(context, result);
+      return result;
+   }
+
+   /**
+    * Apply metadata on root to create context.
+    *
+    * @param context the structure context
+    * @param metaDataPaths the metadata paths
+    * @return the context info
+    */
+   protected ContextInfo applyMetadataPaths(StructureContext context, String[] metaDataPaths)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      VirtualFile root = context.getRoot();
+      List<String> metaDataPath = CollectionsFactory.createLazyList();
+      // Determine whether the metadata paths exists
+      if (metaDataPaths != null && metaDataPaths.length > 0)
+      {
+         for(String path : metaDataPaths)
+         {
+            try
+            {
+               VirtualFile child = root.getChild(path);
+               if (child != null)
+                  metaDataPath.add(path);
+            }
+            catch (IOException e)
+            {
+               log.warn("Not using metadata path " + path + " for " + root.getName() + " reason: " + e.getMessage());
+            }
+         }
+      }
+
+      // Create and link the context
+      if (metaDataPath.isEmpty())
+         return StructureMetaDataFactory.createContextInfo("", null);
+      else
+         return StructureMetaDataFactory.createContextInfo("", metaDataPath, null);
+   }
+
+   /**
+    * Create a context
+    *
     * @param root the root context
     * @param metaDataPaths the metadata paths
     * @param structureMetaData the structure metadata
     * @return the context info
     * @throws IllegalArgumentException for a null root or structure metaData
     */
+   @Deprecated // Remove JBDEPLOY-66
    protected ContextInfo createContext(VirtualFile root, String[] metaDataPaths, StructureMetaData structureMetaData)
    {
       ContextInfo result = applyMetadataPaths(root, metaDataPaths);
@@ -325,6 +554,7 @@
     * @param metaDataPaths the metadata paths
     * @return the context info
     */
+   @Deprecated // Remove JBDEPLOY-66
    protected ContextInfo applyMetadataPaths(VirtualFile root, String[] metaDataPaths)
    {
       if (root == null)
@@ -359,10 +589,44 @@
    /**
     * Apply structure metadata on context.
     *
+    * @param context the structure context
+    * @param contextInfo the new created context
+    */
+   protected void applyStructure(StructureContext context, ContextInfo contextInfo)
+   {
+      boolean trace = log.isTraceEnabled();
+
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      VirtualFile root = context.getRoot();
+      applyContextInfo(context, contextInfo);
+      context.addChild(contextInfo);
+      if (trace)
+         log.trace("Added context " + context + " from " + root.getName());
+   }
+
+   /**
+    * Apply context info.
+    * Can be overridden for specific root.
+    *
+    * @param context the structure context
+    * @param result the new context info
+    */
+   protected void applyContextInfo(StructureContext context, ContextInfo result)
+   {
+      if (result != null && contextInfoOrder != null)
+         result.setRelativeOrder(contextInfoOrder);
+   }
+
+   /**
+    * Apply structure metadata on context.
+    *
     * @param root the root context
     * @param structureMetaData the structure metadata
     * @param context the new created context
     */
+   @Deprecated // remove JBDEPLOY-66
    protected void applyStructure(VirtualFile root, StructureMetaData structureMetaData, ContextInfo context)
    {
       boolean trace = log.isTraceEnabled();
@@ -386,6 +650,7 @@
     * @param root the root file
     * @param result the new context info
     */
+   @Deprecated // remove JBDEPLOY-66
    protected void applyContextInfo(VirtualFile root, ContextInfo result)
    {
       if (result != null && contextInfoOrder != null)

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/CandidateStructureVisitorFactory.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/CandidateStructureVisitorFactory.java	2008-08-05 12:36:27 UTC (rev 76661)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/CandidateStructureVisitorFactory.java	2008-08-05 12:55:48 UTC (rev 76662)
@@ -21,9 +21,7 @@
 */
 package org.jboss.deployers.vfs.spi.structure.helpers;
 
-import org.jboss.deployers.spi.structure.StructureMetaData;
-import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
-import org.jboss.virtual.VirtualFile;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
 import org.jboss.virtual.VirtualFileVisitor;
 import org.jboss.virtual.VisitorAttributes;
 
@@ -38,13 +36,10 @@
    /**
     * Create the visitor
     * 
-    * @param root the root virtual file
-    * @param parent the parent virtual file
-    * @param metaData the structure metaData
-    * @param deployers the structure deployers
+    * @param context the structure context
     * @param attributes the visitor attributes uses {@link VisitorAttributes#DEFAULT} when null
     * @return the visitor
     * @throws Exception for any error
     */
-   VirtualFileVisitor createVisitor(VirtualFile root, VirtualFile parent, StructureMetaData metaData, VFSStructuralDeployers deployers, VisitorAttributes attributes) throws Exception;
+   VirtualFileVisitor createVisitor(StructureContext context, VisitorAttributes attributes) throws Exception;
 }

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/DefaultCandidateStructureVisitorFactory.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/DefaultCandidateStructureVisitorFactory.java	2008-08-05 12:36:27 UTC (rev 76661)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/DefaultCandidateStructureVisitorFactory.java	2008-08-05 12:55:48 UTC (rev 76662)
@@ -21,9 +21,7 @@
 */
 package org.jboss.deployers.vfs.spi.structure.helpers;
 
-import org.jboss.deployers.spi.structure.StructureMetaData;
-import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
-import org.jboss.virtual.VirtualFile;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
 import org.jboss.virtual.VirtualFileFilter;
 import org.jboss.virtual.VirtualFileVisitor;
 import org.jboss.virtual.VisitorAttributes;
@@ -62,9 +60,9 @@
       this.filter = filter;
    }
 
-   public VirtualFileVisitor createVisitor(VirtualFile root, VirtualFile parent, StructureMetaData metaData, VFSStructuralDeployers deployers, VisitorAttributes attributes) throws Exception
+   public VirtualFileVisitor createVisitor(StructureContext context, VisitorAttributes attributes) throws Exception
    {
-      AbstractCandidateStructureVisitor visitor = new AbstractCandidateStructureVisitor(root, parent, metaData, deployers, attributes);
+      AbstractCandidateStructureVisitor visitor = new AbstractCandidateStructureVisitor(context, attributes);
       if (filter != null)
          visitor.setFilter(filter);
       return visitor;




More information about the jboss-cvs-commits mailing list