[jbpm-commits] JBoss JBPM SVN: r6332 - in jbpm4/trunk: modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed May 12 06:54:02 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-05-12 06:54:01 -0400 (Wed, 12 May 2010)
New Revision: 6332

Modified:
   jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentClassLoader.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/IoUtil.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/ImageTest.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionStartFormTest.java
   jbpm4/trunk/qa/jdbc/mysql.properties
Log:
JBPM-2703: let IoUtil throw IOExceptions to improve exception handling
update mysql properties in quality lab

Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/DbHelper.java	2010-05-12 10:54:01 UTC (rev 6332)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.db;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -51,24 +52,29 @@
   public static void executeSqlResource(String resource, Session session) {
     InputStream stream = Upgrade.class.getClassLoader().getResourceAsStream(resource);
     if (stream == null) {
-      throw new JbpmException("resource "+resource+" does not exist");
+      throw new JbpmException("resource not found: " + resource);
     }
 
-    byte[] bytes = IoUtil.readBytes(stream);
-    String fileContents = new String(bytes);
-    List<String> commands = extractCommands(fileContents);
-    
-    log.info("--- Executing DB Commands -------------------------");
-    for (String command: commands) {
-      log.info(command);
-      try {
-        int result = session.createSQLQuery(command).executeUpdate();
-        log.info("--- Result: "+result+" --------------------------");
-      } catch (Exception e) {
-        e.printStackTrace();
-        log.info("-----------------------------------------------");
+    try {
+      byte[] bytes = IoUtil.readBytes(stream);
+      String fileContents = new String(bytes);
+      List<String> commands = extractCommands(fileContents);
+      
+      log.info("--- Executing DB Commands -------------------------");
+      for (String command: commands) {
+        log.info(command);
+        try {
+          int result = session.createSQLQuery(command).executeUpdate();
+          log.info("--- Result: "+result+" --------------------------");
+        } catch (Exception e) {
+          e.printStackTrace();
+          log.info("-----------------------------------------------");
+        }
       }
     }
+    catch (IOException e) {
+      throw new JbpmException("could not read resource: " + resource, e);
+    }
   }
 
   public static List<String> extractCommands(String fileContents) {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java	2010-05-12 10:54:01 UTC (rev 6332)
@@ -21,29 +21,36 @@
  */
 package org.jbpm.pvm.internal.cmd;
 
+import java.io.IOException;
 import java.io.InputStream;
 
+import org.jbpm.api.JbpmException;
 import org.jbpm.api.cmd.Command;
 import org.jbpm.api.cmd.Environment;
 import org.jbpm.pvm.internal.session.RepositorySession;
 import org.jbpm.pvm.internal.util.IoUtil;
 
-
 /**
  * @author Tom Baeyens
  */
 public class UpdateDeploymentResourceCmd implements Command<Void> {
 
   private static final long serialVersionUID = 1L;
-  
+
   protected String deploymentId;
   protected String resourceName;
   protected byte[] bytes;
 
-  public UpdateDeploymentResourceCmd(String deploymentId, String resourceName, InputStream inputStream) {
+  public UpdateDeploymentResourceCmd(String deploymentId, String resourceName,
+    InputStream inputStream) {
     this.deploymentId = deploymentId;
     this.resourceName = resourceName;
-    this.bytes = IoUtil.readBytes(inputStream);
+    try {
+      bytes = IoUtil.readBytes(inputStream);
+    }
+    catch (IOException e) {
+      throw new JbpmException("could not read resource: " + resourceName, e);
+    }
   }
 
   public Void execute(Environment environment) throws Exception {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentClassLoader.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentClassLoader.java	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentClassLoader.java	2010-05-12 10:54:01 UTC (rev 6332)
@@ -32,29 +32,29 @@
 import org.jbpm.api.JbpmException;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
 import org.jbpm.pvm.internal.session.RepositorySession;
-import org.jbpm.pvm.internal.util.IoUtil;
 
-
 /**
  * @author Tom Baeyens
  */
 public class DeploymentClassLoader extends ClassLoader {
 
-  private String deploymentId = null;
+  private final String deploymentId;
 
-  public DeploymentClassLoader(ClassLoader parent, String deploymentId ) {
+  public DeploymentClassLoader(ClassLoader parent, String deploymentId) {
     super(parent);
     this.deploymentId = deploymentId;
   }
 
+  @Override
   public URL findResource(String name) {
     URL url = null;
     byte[] bytes = getDeployment().getBytes(name);
-    if (bytes!=null) {
-      InputStream inputStream = new ByteArrayInputStream(bytes);
+    if (bytes != null) {
       try {
-        url = new URL(null, "jbpm://"+deploymentId+"/"+name, new BytesUrlStreamHandler(inputStream));
-      } catch (MalformedURLException e) {
+        url =
+          new URL(null, "jbpm://" + deploymentId + "/" + name, new BytesUrlStreamHandler(bytes));
+      }
+      catch (MalformedURLException e) {
         throw new JbpmException("couldn't create url", e);
       }
     }
@@ -62,63 +62,74 @@
   }
 
   protected DeploymentImpl getDeployment() {
-    RepositorySession repositorySession = EnvironmentImpl.getFromCurrent(RepositorySession.class);
+    RepositorySession repositorySession =
+      EnvironmentImpl.getFromCurrent(RepositorySession.class);
     return repositorySession.getDeployment(deploymentId);
   }
-  
-  public static class BytesUrlStreamHandler extends URLStreamHandler {
-    InputStream inputStream;
-    public BytesUrlStreamHandler(InputStream inputStream) {
-      this.inputStream = inputStream;
+
+  private static class BytesUrlStreamHandler extends URLStreamHandler {
+
+    private final byte[] bytes;
+
+    public BytesUrlStreamHandler(byte[] bytes) {
+      this.bytes = bytes;
     }
+
+    @Override
     protected URLConnection openConnection(URL u) throws IOException {
-      return new BytesUrlConnection(inputStream, u);
+      return new BytesUrlConnection(bytes, u);
     }
   }
 
-  public static class BytesUrlConnection extends URLConnection {
-    InputStream inputStream;
-    public BytesUrlConnection(InputStream inputStream, URL url) {
+  private static class BytesUrlConnection extends URLConnection {
+
+    private final byte[] bytes;
+
+    public BytesUrlConnection(byte[] bytes, URL url) {
       super(url);
-      this.inputStream = inputStream;
+      this.bytes = bytes;
     }
+
+    @Override
     public void connect() throws IOException {
     }
+
+    @Override
     public InputStream getInputStream() throws IOException {
-      return inputStream;
+      return new ByteArrayInputStream(bytes);
     }
   }
 
-  public Class findClass(String name) throws ClassNotFoundException {
-    Class clazz = null;
+  @Override
+  public Class<?> findClass(String name) throws ClassNotFoundException {
+    // find class bytecode
+    String fileName = name.replace('.', '/') + ".class";
+    byte[] bytecode = getDeployment().getBytes(fileName);
+    if (bytecode == null) {
+      throw new ClassNotFoundException(name);
+    }
 
-    String fileName = name.replace( '.', '/' ) + ".class";
-    byte[] bytes = getDeployment().getBytes(fileName);
-    if (bytes!=null) {
-      try {
-        InputStream inputStream = new ByteArrayInputStream(bytes);
-        byte[] classBytes = IoUtil.readBytes(inputStream);
-        clazz = defineClass(name, classBytes, 0, classBytes.length);
+    // define class
+    Class<?> clazz = defineClass(name, bytecode, 0, bytecode.length);
 
-        // Add the package information
-        final int packageIndex = name.lastIndexOf('.');
-        if (packageIndex != -1) {
-          final String packageName = name.substring(0, packageIndex);
-          final Package classPackage = getPackage(packageName);
-          if (classPackage == null) {
-            definePackage(packageName, null, null, null, null, null, null, null);
-          }
+    // define package, if not defined already
+    int packageIndex = name.lastIndexOf('.');
+    if (packageIndex != -1) {
+      String packageName = name.substring(0, packageIndex);
+      Package classPackage = getPackage(packageName);
+      if (classPackage == null) {
+        Package myPackage = getClass().getPackage();
+        if (myPackage != null) {
+          definePackage(packageName, myPackage.getSpecificationTitle(),
+            myPackage.getSpecificationVersion(), myPackage.getSpecificationVendor(),
+            myPackage.getImplementationTitle(), myPackage.getImplementationVersion(),
+            myPackage.getImplementationVendor(), null);
         }
-
-      } catch (JbpmException e) {
-        clazz = null;
+        else {
+          definePackage(packageName, null, null, null, null, null, null, null);
+        }
       }
     }
-
-    if (clazz==null) {
-      throw new ClassNotFoundException("class '"+name+"' could not be found in deployment "+deploymentId);
-    }
-
     return clazz;
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java	2010-05-12 10:54:01 UTC (rev 6332)
@@ -25,7 +25,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectStreamException;
-import java.io.Serializable;
 import java.net.URL;
 import java.util.Collections;
 import java.util.HashMap;
@@ -53,19 +52,18 @@
 import org.jbpm.pvm.internal.util.IoUtil;
 import org.jbpm.pvm.internal.xml.ProblemList;
 
-
 /**
  * @author Tom Baeyens
  */
-public class DeploymentImpl extends ProblemList implements NewDeployment, Serializable {
-  
+public class DeploymentImpl extends ProblemList implements NewDeployment {
+
   private static final long serialVersionUID = 1L;
 
   public static final String KEY_PROCESS_LANGUAGE_ID = "langid";
   public static final String KEY_PROCESS_DEFINITION_ID = "pdid";
   public static final String KEY_PROCESS_DEFINITION_KEY = "pdkey";
   public static final String KEY_PROCESS_DEFINITION_VERSION = "pdversion";
-  
+
   protected long dbid;
   protected String name;
   protected long timestamp;
@@ -82,15 +80,16 @@
   public DeploymentImpl(CommandService commandService) {
     this.commandService = commandService;
   }
-  
+
+  @Override
   public String toString() {
-    return "deployment("+dbid+")";
+    return "deployment(" + dbid + ")";
   }
-  
+
   public String deploy() {
     return commandService.execute(new DeployCmd(this));
   }
-  
+
   public NewDeployment addResourceFromClasspath(String resourceName) {
     addResourceFromStreamInput(resourceName, new ResourceStreamInput(resourceName));
     return this;
@@ -100,19 +99,20 @@
     addResourceFromStreamInput(resourceName, new StringStreamInput(text));
     return this;
   }
-  
+
   public NewDeployment addResourcesFromZipInputStream(ZipInputStream zipInputStream) {
     try {
       ZipEntry zipEntry = zipInputStream.getNextEntry();
-      while(zipEntry!=null) {
+      while (zipEntry != null) {
         String entryName = zipEntry.getName();
         byte[] bytes = IoUtil.readBytes(zipInputStream);
-        if (bytes!=null) {
+        if (bytes != null) {
           addResourceFromStreamInput(entryName, new ByteArrayStreamInput(bytes));
         }
         zipEntry = zipInputStream.getNextEntry();
       }
-    } catch (Exception e) {
+    }
+    catch (IOException e) {
       throw new JbpmException("couldn't read zip archive", e);
     }
     return this;
@@ -134,7 +134,7 @@
   }
 
   public NewDeployment addResourceFromStreamInput(String name, StreamInput streamInput) {
-    if (resources==null) {
+    if (resources == null) {
       resources = new HashMap<String, Lob>();
     }
     byte[] bytes = null;
@@ -142,43 +142,43 @@
       InputStream inputStream = streamInput.openStream();
       bytes = IoUtil.readBytes(inputStream);
       inputStream.close();
-    } catch (IOException e) {
-      throw new JbpmException("couldn't read from "+streamInput, e);
     }
-    
-    // Since this method is probably called outside an environment block, we 
+    catch (IOException e) {
+      throw new JbpmException("couldn't read from " + name, e);
+    }
+
+    // Since this method is probably called outside an environment block, we
     // need to generate the dbid of the Lob later (during the actual deployment).
-    Lob lob = new Lob(bytes, false); 
+    Lob lob = new Lob(bytes, false);
     resources.put(name, lob);
-    
+
     return this;
   }
 
   public Set<String> getResourceNames() {
-    if (resources==null) {
+    if (resources == null) {
       return Collections.emptySet();
     }
     return resources.keySet();
   }
-  
+
   /**
-   * This method should be called before saving the deployment. It will assign a
-   * generated dbid to the resource Lobs.
+   * This method should be called before saving the deployment. It will assign a generated dbid
+   * to the resource Lobs.
    * 
-   * Note: when using a database, this method must be called within an
-   * environment block!
+   * Note: when using a database, this method must be called within an environment block!
    */
   public void initResourceLobDbids() {
     for (Lob resource : resources.values()) {
       long resourceDbid = DbidGenerator.getDbidGenerator().getNextId();
-      resource.setDbid(resourceDbid);      
+      resource.setDbid(resourceDbid);
     }
   }
-  
+
   public byte[] getBytes(String resourceName) {
-    if (resources!=null) {
+    if (resources != null) {
       Lob lob = resources.get(resourceName);
-      if (lob!=null) {
+      if (lob != null) {
         return lob.extractBytes();
       }
     }
@@ -186,18 +186,18 @@
   }
 
   public void addObject(String objectName, Object object) {
-    if (objects==null) {
+    if (objects == null) {
       objects = new HashMap<String, Object>();
     }
     objects.put(objectName, object);
   }
-  
+
   // object properties ////////////////////////////////////////////////////////
-  
+
   public void setProcessDefinitionId(String processDefinitionName, String processDefinitionId) {
     setObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_ID, processDefinitionId);
   }
-  
+
   public String getProcessDefinitionId(String processDefinitionName) {
     return (String) getObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_ID);
   }
@@ -210,14 +210,15 @@
     return (String) getObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_KEY);
   }
 
-  public void setProcessDefinitionVersion(String processDefinitionName, Long processDefinitionVersion) {
+  public void setProcessDefinitionVersion(String processDefinitionName,
+    Long processDefinitionVersion) {
     setObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_VERSION, processDefinitionVersion);
   }
-  
+
   public Long getProcessDefinitionVersion(String processDefinitionName) {
     return (Long) getObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_VERSION);
   }
-  
+
   public String getProcessLanguageId(String processDefinitionName) {
     return (String) getObjectProperty(processDefinitionName, KEY_PROCESS_LANGUAGE_ID);
   }
@@ -227,7 +228,7 @@
   }
 
   public void setObjectProperty(String objectName, String key, Object value) {
-    if (objectProperties==null) {
+    if (objectProperties == null) {
       objectProperties = new HashSet<DeploymentProperty>();
     }
     DeploymentProperty deploymentProperty = new DeploymentProperty(this, objectName, key);
@@ -239,7 +240,7 @@
     if (objectProperties != null) {
       for (DeploymentProperty deploymentProperty : objectProperties) {
         if (deploymentProperty.getObjectName().equals(objectName)
-            && deploymentProperty.getKey().equals(key)) {
+          && deploymentProperty.getKey().equals(key)) {
           Object value = deploymentProperty.getValue();
           objectProperties.remove(deploymentProperty);
           return value;
@@ -250,11 +251,10 @@
   }
 
   public Object getObjectProperty(String objectName, String key) {
-    if (objectProperties!=null) {
-      for (DeploymentProperty deploymentProperty: objectProperties) {
-        if ( (deploymentProperty.getObjectName().equals(objectName))
-             && (deploymentProperty.getKey().equals(key))
-           ) {
+    if (objectProperties != null) {
+      for (DeploymentProperty deploymentProperty : objectProperties) {
+        if (deploymentProperty.getObjectName().equals(objectName)
+          && deploymentProperty.getKey().equals(key)) {
           return deploymentProperty.getValue();
         }
       }
@@ -264,8 +264,8 @@
 
   public Set<String> getProcessDefinitionIds() {
     Set<String> processDefinitionIds = new HashSet<String>();
-    if (objectProperties!=null) {
-      for (DeploymentProperty deploymentProperty: objectProperties) {
+    if (objectProperties != null) {
+      for (DeploymentProperty deploymentProperty : objectProperties) {
         if (KEY_PROCESS_DEFINITION_ID.equals(deploymentProperty.getKey())) {
           String processDefinitionId = deploymentProperty.getStringValue();
           processDefinitionIds.add(processDefinitionId);
@@ -276,26 +276,26 @@
   }
 
   public boolean hasObjectProperties(String objectName) {
-    if (objectProperties!=null) {
-      for (DeploymentProperty deploymentProperty: objectProperties) {
-        if ( deploymentProperty.getObjectName().equals(objectName)
-             && KEY_PROCESS_DEFINITION_ID.equals(deploymentProperty.getKey())
-           ) {
+    if (objectProperties != null) {
+      for (DeploymentProperty deploymentProperty : objectProperties) {
+        if (deploymentProperty.getObjectName().equals(objectName)
+          && KEY_PROCESS_DEFINITION_ID.equals(deploymentProperty.getKey())) {
           return true;
         }
       }
     }
     return false;
   }
-  
+
   public void suspend() {
     if (isSuspended()) {
       throw new JbpmException("deployment is already suspended");
     }
-    
+
     state = Deployment.STATE_SUSPENDED;
 
-    RepositorySessionImpl repositorySession = EnvironmentImpl.getFromCurrent(RepositorySessionImpl.class);
+    RepositorySessionImpl repositorySession = EnvironmentImpl
+      .getFromCurrent(RepositorySessionImpl.class);
     repositorySession.cascadeDeploymentSuspend(this);
 
     RepositoryCache repositoryCache = EnvironmentImpl.getFromCurrent(RepositoryCache.class);
@@ -306,18 +306,19 @@
     if (!isSuspended()) {
       throw new JbpmException("deployment is not suspended");
     }
-    
+
     state = Deployment.STATE_ACTIVE;
-    
-    RepositorySessionImpl repositorySession = EnvironmentImpl.getFromCurrent(RepositorySessionImpl.class);
+
+    RepositorySessionImpl repositorySession = EnvironmentImpl
+      .getFromCurrent(RepositorySessionImpl.class);
     repositorySession.cascadeDeploymentResume(this);
-    
+
     RepositoryCache repositoryCache = EnvironmentImpl.getFromCurrent(RepositoryCache.class);
     repositoryCache.remove(Long.toString(dbid));
   }
-  
+
   public boolean isSuspended() {
-    return Deployment.STATE_SUSPENDED.equals(state); 
+    return Deployment.STATE_SUSPENDED.equals(state);
   }
 
   protected Object writeReplace() throws ObjectStreamException {
@@ -326,11 +327,11 @@
   }
 
   // customized getters and setters ///////////////////////////////////////////
-  
+
   public String getId() {
     return Long.toString(dbid);
   }
-  
+
   // getters and setters //////////////////////////////////////////////////////
 
   public long getDbid() {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java	2010-05-12 10:54:01 UTC (rev 6332)
@@ -30,30 +30,30 @@
  * Helper class responsible for providing classes while deserializing variables.
  * 
  * @author Maciej Swiderski swiderski.maciej at gmail.com
- *
  */
 public class DeploymentObjectInputStream extends ObjectInputStream {
 
-  private String deploymentId;
-  
-  public DeploymentObjectInputStream(InputStream stream, String deploymentId) throws IOException {
+  private final String deploymentId;
+
+  public DeploymentObjectInputStream(InputStream stream, String deploymentId)
+    throws IOException {
     super(stream);
     this.deploymentId = deploymentId;
   }
 
   @Override
-  protected Class< ? > resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
-    
+  protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException,
+    ClassNotFoundException {
+    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
     try {
-      Class< ? > clazz = Class.forName(desc.getName(), true, Thread.currentThread().getContextClassLoader());
-      return clazz;
-    } catch (ClassNotFoundException e) {
-      //trying to get it from deployment
-      DeploymentClassLoader cl = new DeploymentClassLoader(Thread.currentThread().getContextClassLoader(), deploymentId);
-      return Class.forName(desc.getName(), true, cl);
+      return Class.forName(desc.getName(), false, contextClassLoader);
     }
+    catch (ClassNotFoundException e) {
+      // trying to get it from deployment
+      ClassLoader deploymentClassLoader =
+        new DeploymentClassLoader(contextClassLoader, deploymentId);
+      return Class.forName(desc.getName(), false, deploymentClassLoader);
+    }
   }
-  
-  
 
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/IoUtil.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/IoUtil.java	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/IoUtil.java	2010-05-12 10:54:01 UTC (rev 6332)
@@ -26,41 +26,32 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.jbpm.api.JbpmException;
+public class IoUtil {
 
-public abstract class IoUtil {
-
   public static final int BUFFERSIZE = 4096;
 
-  public static byte[] readBytes(InputStream inputStream) {
-    byte[] bytes = null;
-    if (inputStream==null) {
-      throw new JbpmException("inputStream is null");
-    }
+  private IoUtil() {
+    // prevent instantiation
+  }
+
+  public static byte[] readBytes(InputStream inputStream) throws IOException {
+    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     try {
-      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       transfer(inputStream, outputStream);
-      bytes = outputStream.toByteArray();
-      outputStream.close();
-      return bytes;
-    } catch (IOException e) {
-      throw new JbpmException("couldn't read bytes from inputStream", e);
     }
+    finally {
+      inputStream.close();
+    }
+    return outputStream.toByteArray();
   }
-  
-  public static int transfer(InputStream in, OutputStream out) {
-    int total = 0;
+
+  public static long transfer(InputStream in, OutputStream out) throws IOException {
+    long total = 0;
     byte[] buffer = new byte[BUFFERSIZE];
-    try {
-      int bytesRead = in.read( buffer );
-      while ( bytesRead != -1 ) {
-        out.write( buffer, 0, bytesRead );
-        total += bytesRead;
-        bytesRead = in.read( buffer );
-      }
-      return total;
-    } catch (IOException e) {
-      throw new JbpmException("couldn't write bytes to output stream", e);
+    for (int count; (count = in.read(buffer)) != -1;) {
+      out.write(buffer, 0, count);
+      total += count;
     }
+    return total;
   }
 }

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/ImageTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/ImageTest.java	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/ImageTest.java	2010-05-12 10:54:01 UTC (rev 6332)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.test.deploy;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
 
@@ -28,35 +29,37 @@
 import org.jbpm.pvm.internal.util.IoUtil;
 import org.jbpm.test.JbpmTestCase;
 
-
 /**
  * @author Tom Baeyens
  */
 public class ImageTest extends JbpmTestCase {
 
-  public void testImage() {
+  public void testImage() throws IOException {
     String deploymentId = repositoryService
-        .createDeployment()
-        .addResourceFromClasspath("org/jbpm/test/deploy/ImageTest.jpdl.xml")
-        .addResourceFromClasspath("org/jbpm/test/deploy/ImageTest.png")
-        .deploy();
-    
+      .createDeployment()
+      .addResourceFromClasspath("org/jbpm/test/deploy/ImageTest.jpdl.xml")
+      .addResourceFromClasspath("org/jbpm/test/deploy/ImageTest.png")
+      .deploy();
+
     ProcessDefinition processDefinition = repositoryService
-        .createProcessDefinitionQuery()
-        .processDefinitionKey("ImageTest")
-        .uniqueResult();
-    
+      .createProcessDefinitionQuery()
+      .processDefinitionKey("ImageTest")
+      .uniqueResult();
+
     String imageResourceName = processDefinition.getImageResourceName();
     assertEquals("org/jbpm/test/deploy/ImageTest.png", imageResourceName);
-    
-    InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), imageResourceName);
+
+    InputStream inputStream = repositoryService.getResourceAsStream(processDefinition
+      .getDeploymentId(), imageResourceName);
     byte[] imageBytes = IoUtil.readBytes(inputStream);
-    
-    inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jbpm/test/deploy/ImageTest.png");
+
+    inputStream = Thread
+      .currentThread()
+      .getContextClassLoader()
+      .getResourceAsStream("org/jbpm/test/deploy/ImageTest.png");
     byte[] expectedImageBytes = IoUtil.readBytes(inputStream);
-    
     assertTrue(Arrays.equals(expectedImageBytes, imageBytes));
-    
+
     repositoryService.deleteDeploymentCascade(deploymentId);
   }
 }

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionStartFormTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionStartFormTest.java	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionStartFormTest.java	2010-05-12 10:54:01 UTC (rev 6332)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.test.process;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -29,82 +30,70 @@
 import org.jbpm.pvm.internal.util.IoUtil;
 import org.jbpm.test.JbpmTestCase;
 
-
 /**
  * @author Tom Baeyens
  */
 public class ProcessDefinitionStartFormTest extends JbpmTestCase {
-  
-  public void testFormInUnnamedStartActivity() {
-    String deploymentDbid =
-      repositoryService.createDeployment()
-          .addResourceFromString("xmlstring.jpdl.xml",       
-            "<process name='make print'>" +
-            "  <start form='org/jbpm/test/process/ProcessDefinitionStartForm.form' />" +
-            "</process>"
-          )
-          .addResourceFromClasspath("org/jbpm/test/process/ProcessDefinitionStartForm.form")       
-          .deploy();
 
+  public void testFormInUnnamedStartActivity() throws IOException {
+    String deploymentDbid = repositoryService
+      .createDeployment()
+      .addResourceFromString("xmlstring.jpdl.xml", "<process name='make print'>"
+        + "  <start form='org/jbpm/test/process/ProcessDefinitionStartForm.form' />"
+        + "</process>")
+      .addResourceFromClasspath("org/jbpm/test/process/ProcessDefinitionStartForm.form")
+      .deploy();
     registerDeployment(deploymentDbid);
 
-    ProcessDefinition processDefinition = 
-      repositoryService
-        .createProcessDefinitionQuery()
-        .processDefinitionName("make print")
-        .uniqueResult();
-    
+    ProcessDefinition processDefinition = repositoryService
+      .createProcessDefinitionQuery()
+      .processDefinitionName("make print")
+      .uniqueResult();
     String processDefinitionId = processDefinition.getId();
-    
-    List<String> startActivityNames = repositoryService.getStartActivityNames(processDefinitionId );
+
+    List<String> startActivityNames = repositoryService
+      .getStartActivityNames(processDefinitionId);
     List<String> expectedStartActivityNames = new ArrayList<String>();
     expectedStartActivityNames.add(null);
-    
     assertEquals(expectedStartActivityNames, startActivityNames);
 
-    String startFormResourceName = repositoryService.getStartFormResourceName(processDefinitionId, null);
-    
+    String startFormResourceName = repositoryService
+      .getStartFormResourceName(processDefinitionId, null);
     assertEquals("org/jbpm/test/process/ProcessDefinitionStartForm.form", startFormResourceName);
-    
-    InputStream formInputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), startFormResourceName);
-    
-    String formContents = new String(IoUtil.readBytes(formInputStream));
-    assertEquals("start task form", formContents);
+
+    InputStream formInputStream = repositoryService.getResourceAsStream(processDefinition
+      .getDeploymentId(), startFormResourceName);
+    assertEquals("start task form", new String(IoUtil.readBytes(formInputStream)));
   }
 
-  public void testFormInNamedStartActivity() {
-    String deploymentDbid =
-      repositoryService.createDeployment()
-          .addResourceFromString("xmlstring.jpdl.xml",       
-            "<process name='make print'>" +
-            "  <start name='start' form='org/jbpm/test/process/ProcessDefinitionStartForm.form' />" +
-            "</process>"
-          )
-          .addResourceFromClasspath("org/jbpm/test/process/ProcessDefinitionStartForm.form")       
-          .deploy();
-
+  public void testFormInNamedStartActivity() throws IOException {
+    String deploymentDbid = repositoryService
+      .createDeployment()
+      .addResourceFromString("xmlstring.jpdl.xml", "<process name='make print'>"
+        + "  <start name='start' form='org/jbpm/test/process/ProcessDefinitionStartForm.form' />"
+        + "</process>")
+      .addResourceFromClasspath("org/jbpm/test/process/ProcessDefinitionStartForm.form")
+      .deploy();
     registerDeployment(deploymentDbid);
 
-    ProcessDefinition processDefinition = 
-      repositoryService
-        .createProcessDefinitionQuery()
-        .processDefinitionName("make print")
-        .uniqueResult();
-    
+    ProcessDefinition processDefinition = repositoryService
+      .createProcessDefinitionQuery()
+      .processDefinitionName("make print")
+      .uniqueResult();
     String processDefinitionId = processDefinition.getId();
-    
-    List<String> startActivityNames = repositoryService.getStartActivityNames(processDefinitionId );
+
+    List<String> startActivityNames = repositoryService
+      .getStartActivityNames(processDefinitionId);
     List<String> expectedStartActivityNames = new ArrayList<String>();
     expectedStartActivityNames.add("start");
-    
     assertEquals(expectedStartActivityNames, startActivityNames);
 
-    String startFormResourceName = repositoryService.getStartFormResourceName(processDefinitionId, "start");
-    
+    String startFormResourceName = repositoryService
+      .getStartFormResourceName(processDefinitionId, "start");
     assertEquals("org/jbpm/test/process/ProcessDefinitionStartForm.form", startFormResourceName);
-    
-    InputStream formInputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), startFormResourceName);
-    
+
+    InputStream formInputStream = repositoryService.getResourceAsStream(processDefinition
+      .getDeploymentId(), startFormResourceName);
     String formContents = new String(IoUtil.readBytes(formInputStream));
     assertEquals("start task form", formContents);
   }

Modified: jbpm4/trunk/qa/jdbc/mysql.properties
===================================================================
--- jbpm4/trunk/qa/jdbc/mysql.properties	2010-05-12 09:52:59 UTC (rev 6331)
+++ jbpm4/trunk/qa/jdbc/mysql.properties	2010-05-12 10:54:01 UTC (rev 6332)
@@ -1,4 +1,4 @@
 jdbc.driver=com.mysql.jdbc.Driver
-jdbc.url=jdbc:mysql://dev02.qa.atl.jboss.com:3306/pvm1
+jdbc.url=jdbc:mysql://vmg02.mw.lab.eng.bos.redhat.com:3306/pvm1
 jdbc.username=pvm1
 jdbc.password=pvm1



More information about the jbpm-commits mailing list