[jboss-cvs] JBossAS SVN: r79923 - projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vfs.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 22 09:55:16 EDT 2008


Author: petemuir
Date: 2008-10-22 09:55:15 -0400 (Wed, 22 Oct 2008)
New Revision: 79923

Added:
   projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vfs/SeamResourceDiscovery.java
Log:
Add an example of how to get the deployment requirements from Seam, and then set the discovered resources and classes back

Added: projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vfs/SeamResourceDiscovery.java
===================================================================
--- projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vfs/SeamResourceDiscovery.java	                        (rev 0)
+++ projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vfs/SeamResourceDiscovery.java	2008-10-22 13:55:15 UTC (rev 79923)
@@ -0,0 +1,99 @@
+package org.jboss.seam.integration.jbossas.vfs;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.jboss.seam.deployment.AbstractScanner;
+import org.jboss.seam.deployment.ClassDeploymentHandler;
+import org.jboss.seam.deployment.ClassDeploymentMetadata;
+import org.jboss.seam.deployment.ClassDescriptor;
+import org.jboss.seam.deployment.DeploymentHandler;
+import org.jboss.seam.deployment.DeploymentStrategy;
+import org.jboss.seam.deployment.FileDescriptor;
+import org.jboss.seam.deployment.Scanner;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Seam Resource Discovery for JBoss MC
+ * 
+ * Actually, not a scanner at all :-)
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @author Pete Muir
+ */
+public class SeamResourceDiscovery implements Scanner
+{
+
+   private DeploymentStrategy deploymentStrategy;
+	
+   public SeamResourceDiscovery(DeploymentStrategy deploymentStrategy) 
+   {
+	   this.deploymentStrategy = deploymentStrategy;
+   }
+
+   public void scanDirectories(File[] directories)
+   {
+      for (Entry<String, DeploymentHandler> entry : deploymentStrategy.getDeploymentHandlers().entrySet())
+      {
+         DeploymentHandler deploymentHandler = entry.getValue();
+         
+         if (deploymentHandler instanceof ClassDeploymentHandler)
+         {
+            ClassDeploymentHandler classDeploymentHandler = (ClassDeploymentHandler) deploymentHandler;
+            // Any class with any of these annotations should be returned
+            Set<Class<? extends Annotation>> annotations = classDeploymentHandler.getMetadata().getClassAnnotatedWith();
+            Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
+            // TODO retrieve discovered classes from MC AnnotationEnvironment
+            for (Class<?> clazz : discoveredClasses)
+            {
+               String classFileName = classFilenameFromClassName(clazz.getName());
+               classDeploymentHandler.getClasses().add(new ClassDescriptor(classFileName, deploymentStrategy.getClassLoader().getResource(classFileName), clazz));
+            }
+         } 
+         else
+         {
+            // Any resource with this suffix should be returned
+            String fileNameSuffix = deploymentHandler.getMetadata().getFileNameSuffix();
+            Set<URL> discoveredResources = new HashSet<URL>();
+            // TODO retrieve discovered resources from MC
+            for (URL url : discoveredResources)
+            {
+               String fileName = ""; // TODO discover "simple" file name - just the path in the jar
+               deploymentHandler.getResources().add(new FileDescriptor(fileName, url));
+            }
+         }
+      }
+   }
+
+   public void scanResources(String[] resources)
+   {
+      
+   }
+   
+   public long getTimestamp() 
+   {
+	  // TODO Return the time when the last resource that Seam is interested in was modified (any resource visited by the above methods)
+      return Long.MAX_VALUE;
+   }
+
+   public DeploymentStrategy getDeploymentStrategy() 
+   {
+	  return deploymentStrategy;
+   }
+   
+   private static String classFilenameFromClassName(String className)
+   {
+      return className.substring(0).replace('.', '/') + ".class";
+  }
+}


Property changes on: projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vfs/SeamResourceDiscovery.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the jboss-cvs-commits mailing list