[seam-commits] Seam SVN: r10646 - in modules/trunk/bpm/src/main/java/org/jboss/seam/bpm: util and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Apr 27 05:00:42 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-04-27 05:00:42 -0400 (Mon, 27 Apr 2009)
New Revision: 10646

Added:
   modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/
   modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/FileDescriptor.java
   modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/Resources.java
Removed:
   modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/package-info.java
Modified:
   modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/Actor.java
   modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/BusinessProcessInterceptor.java
   modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/Jbpm.java
Log:
added util classes, some cleanup

Modified: modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/Actor.java
===================================================================
--- modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/Actor.java	2009-04-27 04:15:21 UTC (rev 10645)
+++ modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/Actor.java	2009-04-27 09:00:42 UTC (rev 10646)
@@ -86,14 +86,6 @@
    {
       return groupActorIds;
    }
-   public static Actor instance()
-   {
-      if ( !Contexts.isSessionContextActive() )
-      {
-         throw new IllegalStateException("No active session context");
-      }
-      return (Actor) Component.getInstance(Actor.class);
-   }
    
    @Override
    public String toString()

Modified: modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/BusinessProcessInterceptor.java
===================================================================
--- modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/BusinessProcessInterceptor.java	2009-04-27 04:15:21 UTC (rev 10645)
+++ modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/BusinessProcessInterceptor.java	2009-04-27 09:00:42 UTC (rev 10646)
@@ -21,8 +21,8 @@
 import org.jboss.seam.core.Init;
 import org.jboss.seam.intercept.AbstractInterceptor;
 import org.jboss.seam.intercept.InvocationContext;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
 import org.jboss.seam.util.Strings;
 import org.jboss.seam.web.Parameters;
 

Modified: modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/Jbpm.java
===================================================================
--- modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/Jbpm.java	2009-04-27 04:15:21 UTC (rev 10645)
+++ modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/Jbpm.java	2009-04-27 09:00:42 UTC (rev 10646)
@@ -11,6 +11,7 @@
 import java.util.Set;
 
 import javax.annotation.Named;
+import javax.annotation.PreDestroy;
 import javax.context.ApplicationScoped;
 import javax.inject.Initializer;
 import javax.naming.NamingException;
@@ -74,7 +75,7 @@
       UserCodeInterceptorConfig.setUserCodeInterceptor( new SeamUserCodeInterceptor() );
    }
 
-   @Destroy
+   @PreDestroy
    public void shutdown()
    {
       if (jbpmConfiguration!=null) 
@@ -310,19 +311,6 @@
       return processDefinitions!=null && processDefinitions.length>0;
    }
    
-   public static Jbpm instance()
-   {
-      if ( !Contexts.isApplicationContextActive() )
-      {
-         throw new IllegalStateException("No application context active");
-      }
-      if ( !Init.instance().isJbpmInstalled() )
-      {
-         throw new IllegalStateException("jBPM support is not installed (use components.xml to install it)");
-      }
-      return (Jbpm) Component.getInstance(Jbpm.class, ScopeType.APPLICATION);
-   }
-
    protected String getJbpmConfigurationJndiName()
    {
       return jbpmConfigurationJndiName;

Deleted: modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/package-info.java
===================================================================
--- modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/package-info.java	2009-04-27 04:15:21 UTC (rev 10645)
+++ modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/package-info.java	2009-04-27 09:00:42 UTC (rev 10646)
@@ -1,17 +0,0 @@
-/**
- * A set of Seam components for business process management
- * via jBPM, including control of process and task instances,
- * rendering of task lists, and integration with jBPM.
- * 
- * The application may call components in this package
- * directly, or via EL, or may use them indirectly via
- * the annotations in org.jboss.seam.annotations.
- * 
- * @see org.jboss.seam.annotations.bpm
- */
- at Namespace(value="http://jboss.com/products/seam/bpm", prefix="org.jboss.seam.bpm")
- at AutoCreate
-package org.jboss.seam.bpm;
-
-import org.jboss.seam.annotations.AutoCreate;
-import org.jboss.seam.annotations.Namespace;

Added: modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/FileDescriptor.java
===================================================================
--- modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/FileDescriptor.java	                        (rev 0)
+++ modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/FileDescriptor.java	2009-04-27 09:00:42 UTC (rev 10646)
@@ -0,0 +1,74 @@
+package org.jboss.seam.bpm.util;
+
+import java.net.URL;
+
+import org.jboss.seam.contexts.ServletLifecycle;
+import org.jboss.seam.util.Resources;
+
+public class FileDescriptor
+{
+   
+   private String name;
+   private URL url;
+   
+   public FileDescriptor(String name, URL url)
+   {
+      this.name = name;
+      this.url = url;
+   }
+   
+   public FileDescriptor(String name, ClassLoader classLoader)
+   {
+      this.name = name;
+      if (name == null)
+      {
+         throw new NullPointerException("Name cannot be null, loading from " + classLoader);
+      }
+      this.url = classLoader.getResource(name);
+      if (url == null)
+      {
+         this.url = Resources.getResource(name, ServletLifecycle.getServletContext());
+      }
+      if (this.url == null)
+      {
+         throw new NullPointerException("Cannot find URL from classLoader for " + name + ", loading from " + classLoader);
+      }
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+   
+   public URL getUrl()
+   {
+      return url;
+   }
+   
+   @Override
+   public String toString()
+   {
+      return url.getPath();
+   }
+   
+   @Override
+   public boolean equals(Object other)
+   {
+      if (other instanceof FileDescriptor)
+      {
+         FileDescriptor that = (FileDescriptor) other;
+         return this.getUrl().equals(that.getUrl());
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+   @Override
+   public int hashCode()
+   {
+      return getUrl().hashCode();
+   }
+   
+}
\ No newline at end of file

Added: modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/Resources.java
===================================================================
--- modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/Resources.java	                        (rev 0)
+++ modules/trunk/bpm/src/main/java/org/jboss/seam/bpm/util/Resources.java	2009-04-27 09:00:42 UTC (rev 10646)
@@ -0,0 +1,177 @@
+package org.jboss.seam.bpm.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+public class Resources 
+{
+    private static final LogProvider log = Logging.getLogProvider(Resources.class);
+
+   public static InputStream getResourceAsStream(String resource, ServletContext servletContext) 
+   {
+      String stripped = resource.startsWith("/") ? 
+            resource.substring(1) : resource;
+   
+      InputStream stream = null; 
+
+      if (servletContext!=null) {
+         try {
+            stream = servletContext.getResourceAsStream(resource);
+            if (stream!=null) {
+                log.debug("Loaded resource from servlet context: " + resource);
+            }
+         } catch (Exception e) {       
+             //
+         }
+      }
+      
+      if (stream==null) {
+         stream = getResourceAsStream(resource, stripped);
+      }
+      
+      return stream;
+   }
+
+   public static URL getResource(String resource, ServletContext servletContext) 
+   {
+      if (!resource.startsWith("/"))
+      {
+         resource = "/" + resource;
+      }
+      
+      String stripped = resource.startsWith("/") ? 
+            resource.substring(1) : resource;
+   
+      URL url  = null; 
+
+      if (servletContext!=null)
+      {
+         try {
+            url = servletContext.getResource(resource);
+            log.debug("Loaded resource from servlet context: " + url);
+         } catch (Exception e) {
+             //
+         }
+      }
+      
+      if (url==null)
+      {
+        url = getResource(resource, stripped);
+      }
+      
+      return url;
+   }
+   
+   static InputStream getResourceAsStream(String resource, String stripped)
+   {
+      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+      InputStream stream = null;
+      if (classLoader!=null) {
+         stream = classLoader.getResourceAsStream(stripped);
+         if (stream !=null) {
+             log.debug("Loaded resource from context classloader: " + stripped);
+         }
+      }
+      
+      if (stream == null) {
+         stream = Seam.class.getResourceAsStream(resource);
+         if (stream !=null) {
+             log.debug("Loaded resource from Seam classloader: " + resource);
+         }
+      }
+      
+      if (stream == null) {
+         stream = Seam.class.getClassLoader().getResourceAsStream(stripped);
+         if (stream!=null) {
+             log.debug("Loaded resource from Seam classloader: " + stripped);
+         }
+      }
+      
+      return stream;
+   }
+   
+   static URL getResource(String resource, String stripped)
+   {
+       ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+       URL url = null;
+       if (classLoader!=null) {
+           url = classLoader.getResource(stripped);
+           if (url!=null) {
+               log.debug("Loaded resource from context classloader: " + url);
+           }
+       }
+
+       if (url == null) {
+           url = Seam.class.getResource(resource);
+           if (url!=null) {
+               log.debug("Loaded resource from Seam classloader: " + url);
+           }
+       }
+
+       if (url == null) {
+           url = Seam.class.getClassLoader().getResource(stripped);
+           if (url!=null) {
+               log.debug("Loaded resource from Seam classloader: " + url);
+           }           
+       }
+       
+       return url;
+   }
+
+   public static void closeStream(InputStream inputStream) {
+       if (inputStream == null) {
+           return;
+       }
+       
+       try {
+           inputStream.close();
+       } catch (IOException e) {
+          // 
+       }       
+   }
+   
+   public static File getRealFile(ServletContext servletContext, String path)
+   {
+      String realPath = servletContext.getRealPath(path);
+      if (realPath==null) //WebLogic!
+      {
+         try 
+         {
+            URL resourcePath = servletContext.getResource(path);
+            if ((resourcePath != null) && (resourcePath.getProtocol().equals("file"))) 
+            {
+               realPath = resourcePath.getPath();
+            }
+            else
+            {
+               log.warn("Unable to determine real path from servlet context for \"" + path + "\" path does not exist.");
+            }
+         }
+         catch (MalformedURLException e) 
+         {
+            log.warn("Unable to determine real path from servlet context for : " + path);
+            log.debug("Caused by MalformedURLException", e);
+         }
+
+      }
+      
+      if (realPath != null)
+      {
+         File file = new File(realPath);
+         if (file.exists())
+         {
+            return file;
+         }
+      }
+      return null;
+   }
+
+}
\ No newline at end of file




More information about the seam-commits mailing list