⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jbpmconfiguration.java

📁 一个java工作流引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.jbpm;

import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import org.apache.commons.logging.*;
import org.jbpm.model.definition.impl.*;
import org.jbpm.persistence.*;
import org.jbpm.util.log.*;

/**
 * manages all configurations for jbpm including hibernate.
 * 
 * <p>To configure jBpm properly choose one of following 4 configuration mechanisms : 
 * <ul>
 *   <li>put a jbpm.properties in location where the classloader of this class can
 *       find it as a resource (with getResourceAsStream).
 *   </li>
 *   <li>call {@link #configure(Properties)} before the the method
 *       {@link #getInstance()} is called. 
 *   </li>
 *   <li>call {@link #configure(ClassLoader,String)} before the the method
 *       {@link #getInstance()} is called. 
 *   </li>
 *   <li>for creating multiple, differrent configured jbpm instances
 *       within the same JVM (same classloader), you can use the constructors
 *       of JbpmConfiguration and ServiceLocator yourself and don't do any 
 *       static initializations or configurations.
 *   </li>
 * </ul>
 * </p>
 * 
 * <p>Configuration parameters :
 * <font face="arial narrow,verdana" size="-1">
 * <table border="1" cellpadding="8" width="680">
 *   <tr>
 *     <th width="150">property</th>
 *     <th width="130">values</th>
 *     <th width="300">description</th>
 *     <th width="100">default value</th>
 *   </tr>
 *   <tr>
 *     <td>hibernate.*</td>
 *     <td>@see <a href="http://www.hibernate.org/hib_docs/reference/html/session-configuration.html#session-configuration-s5">the hibernate docs</a></td>
 *     <td>also the hiberate configs are done directly in the jbpm config file</td>
 *     <td>jbpm's default hibernate configuration is an in-memory hsqldb database which is ideal for testing purposes</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.create.tables</td>
 *     <td>{ true | false }</td>
 *     <td>If set to true, jbpm will create the the JBPM_ tables at startup if they are not present.</td>
 *     <td>true</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.create.tables.log</td>
 *     <td>{ true | false }</td>
 *     <td>Specifies if the ddl that is generated for the creation of the tables is logged to standard out.</td>
 *     <td>false</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.persistence.session.factory</td>
 *     <td>{ jdbc | ejb-container | the class-name of a class that implements org. jbpm. persistence. PersistenceSessionFactory }</td>
 *     <td>Specifies how jbpm should handles transactions.  'jdbc' means that the transactions on the JDBC connection are used.
 *         'ejb-container' will use the distributed transaction manager of the container (through the ejb-SessionContext).
 *     </td>
 *     <td>standard</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.file.mgr</td>
 *     <td>{ database | filesystem | the class-name of a class that implements org. jbpm. persistence. FileMgr }</td>
 *     <td>Specifies how jbpm should store files (e.g. the class-files in a process archive).  This
 *         configuration is added because some database drivers (like e.g. oracle) aren't good at handling 
 *         binary data.</td>
 *     <td>database</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.check.actors</td>
 *     <td>{ true | false }</td>
 *     <td>If set to true, jBpm will check that service method invocations that operate on 
 *         a token are done by the actor that is assigned to the token.  When this property is
 *         set and the actors differ, a AuthroizationException will be thrown.</td>
 *     <td>false</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.id.generator</td>
 *     <td>{ non-clusterable | the class-name of a class that implements org. jbpm. persistence. IdGenerator }</td>
 *     <td>The IdGenerator will be used to create ids for the jbpm persistable objects.</td>
 *     <td>org. jbpm. persistence. hibernate. NonClusterableIdGenerator</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.log.stdout</td>
 *     <td>{on|off}</td>
 *     <td>Configures commons logging to use standard output.  When set to 
 *         off, jbpm does not configure the commons logging.</td>
 *     <td>on</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.log.default</td>
 *     <td>{ trace | debug | info | warn | error | fatal }</td>
 *     <td>Specifies the default log level.</td>
 *     <td>error</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.log.package.* (where * represents any package name)</td>
 *     <td>{ trace | debug | info | warn | error | fatal }</td>
 *     <td>overwrites the jbpm default log level with the given value</td>
 *     <td>jbpm. log. package. org. jbpm= debug</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.scheduler.wait.period</td>
 *     <td>long</td>
 *     <td>the number of milliseconds to wait between scheduler polls</td>
 *     <td>5000</td>
 *   </tr>
 *   <tr>
 *     <td>jbpm.execute.actions</td>
 *     <td>{ true | false }</td>
 *     <td>If set to true, jBpm will execute the specified action handlers. This could be
 *         set to false e.g. for testing purposes to avoid execution of business processes.</td>
 *     <td>true</td>
 *   </tr>
 * </table>
 * </font>
 * </p> 
 * 
 * <p>The user of the jBpm-API's must make sure that method {@link #configure(Properties)}
 * is called before the service locator is used.
 * </p>
 */
public class JbpmConfiguration {

  private static JbpmConfiguration instance = null;
  private Properties properties = null;
  private Map factoryClassNames = null;
  private Map factoryCache = null;
  
  public static final Properties defaults = new Properties();
  static {
    defaults.put( "jbpm.create.tables", "true" );
    defaults.put( "jbpm.create.tables.log", "false" );
    defaults.put( "jbpm.file.mgr", "database" );
    defaults.put( "jbpm.check.actors", "false" );
    defaults.put( "jbpm.id.generator", "non-clusterable" );
    defaults.put( "jbpm.persistence.session.factory", "jdbc" );
    defaults.put( "jbpm.log.stdout", "on" );
    defaults.put( "jbpm.log.default", "error" );
    defaults.put( "jbpm.log.package.org.jbpm", "debug" );
    defaults.put( "jbpm.scheduler.wait.period", "5000" );
    defaults.put( "jbpm.execute.actions", "true");
    defaults.put( "hibernate.dialect", "net.sf.hibernate.dialect.HSQLDialect" );
    defaults.put( "hibernate.connection.driver_class", "org.hsqldb.jdbcDriver" );
    defaults.put( "hibernate.connection.url", "jdbc:hsqldb:." );
    defaults.put( "hibernate.connection.username", "sa" );
    defaults.put( "hibernate.connection.password", "" );
  }

  private static final Map fileMgrAbbreviatedClassNames = new HashMap();
  private static final Map idGeneratorAbbreviatedClassNames = new HashMap();
  private static final Map persistenceSessionFactoryClassNames = new HashMap();
  static {
    fileMgrAbbreviatedClassNames.put( "filesystem", "org.jbpm.persistence.filemgr.FileSystemFileMgr" );
    fileMgrAbbreviatedClassNames.put( "database",   "org.jbpm.persistence.filemgr.DatabaseFileMgr" );

    idGeneratorAbbreviatedClassNames.put( "non-clusterable", "org.jbpm.persistence.hibernate.NonClusterableIdGenerator" );
    
    persistenceSessionFactoryClassNames.put( "jdbc",          "org.jbpm.persistence.hibernate.HibernateJdbcSessionFactory" );
    persistenceSessionFactoryClassNames.put( "ejb-container", "org.jbpm.ejb.impl.EjbContainerSessionFactory" );
  }
  
  
  /**
   * provides access to the jbpm-configuration-properties.
   * @throws ConfigurationException if jbpm was not yet configured.
   */
  public static JbpmConfiguration getInstance() {
    // if the JbpmConfiguration was already configured 
    if ( instance == null ) {
      try {
				// look if jbpm.properties can be found as a resource (=automatic configuration discovery)
				configure( JbpmConfiguration.class.getClassLoader(), "jbpm.properties" );
			} catch (ConfigurationException e) {
        throw new ConfigurationException( "jbpm was not configured properly.  @see javadocs of org.jbpm.JbpmConfiguration", e );
      }
    }
    return instance;
  }
  
  /**
   * configures jBpm from a resource on a classloader.
   */
  public static void configure( ClassLoader classLoader, String resource ) {
    if ( instance == null ) {
      InputStream is = classLoader.getResourceAsStream( resource );
      if ( is == null ) {
        throw new ConfigurationException( "resource '" + resource + "' could not be found for classloader '" + classLoader + "'" ); 
      }
      
      Properties properties = new Properties();
      try {
        // then add (overwrite) with the given configuration properties
        properties.load( is );
      } catch (IOException e) {
        throw new ConfigurationException( "IOException while loading JbpmConfiguration properties specified as resource '" + resource + "' for classloader '" + classLoader + "'" );
      }
      
      instance = new JbpmConfiguration( properties );
    }
  }
  
  /**
   * configures jBpm from Properties.
   * The configuration is calculated by creating a clone of the 
   * default properties and overwriting that clone with the given properties.
   */
  public static void configure( Properties jBpmConfigurationProperties ) {
    if ( instance == null ) {
      instance = new JbpmConfiguration( jBpmConfigurationProperties );
    } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -