📄 jbpmconfiguration.java
字号:
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Stack;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.configuration.ObjectFactory;
import org.jbpm.configuration.ObjectFactoryImpl;
import org.jbpm.configuration.ObjectFactoryParser;
import org.jbpm.persistence.db.DbPersistenceServiceFactory;
import org.jbpm.svc.ServiceFactory;
import org.jbpm.svc.Services;
import org.jbpm.util.ClassLoaderUtil;
/**
* configuration of one jBPM instance.
*
* <p>During process execution, jBPM might need to use some services.
* A JbpmConfiguration contains the knowledge on how to create those services.
* </p>
*
* <p>A JbpmConfiguration is a thread safe object and serves as a factory for
* {@link org.jbpm.JbpmContext}s, which means one JbpmConfiguration
* can be used to create {@link org.jbpm.JbpmContext}s for all threads.
* The single JbpmConfiguration can be maintained in a static member or
* in the JNDI tree if that is available.
* </p>
*
* <p>A JbpmConfiguration can be obtained in following ways:
* <ul>
* <li>from a resource (by default <code>jbpm.cfg.xml</code> is used):
* <pre> JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
* </pre>
* or
* <pre> String myXmlResource = "...";
* JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(myXmlResource);</pre>
* </li>
* <li>from an XML string:
* <pre> JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
* "<jbpm-configuration>" +
* ...
* "</jbpm-configuration>"
* );
* </pre>
* </li>
* <li>By specifying a custom implementation of an object factory. This can be
* used to specify a JbpmConfiguration in other bean-style notations such as
* used by JBoss Microcontainer or Spring.
* <pre> ObjectFactory of = new <i>MyCustomObjectFactory</i>();
* JbpmConfiguration.Configs.setDefaultObjectFactory(of);
* JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
* </pre>
* </li>
* </ul>
* </p>
*
* <p>JbpmConfigurations can be configured using a spring-like XML notation
* (in relax ng compact notation):
* </p>
*
* <pre>
* datatypes xs = "http://www.w3.org/2001/XMLSchema-datatypes"
*
* start = element beans { element object* }
*
* object = {
* jbpm-context |
* bean |
* ref |
* map |
* list |
* string |
* int |
* long |
* float |
* double |
* char |
* bool |
* true |
* false |
* null
* }
*
* jbpm-context = element jbpm-context {
* ( attribute name {xsd:string},
* service*,
* save-operations?
* )
* }
*
* service = element service {
* ( attribute name {xsd:string},
* ( attribute factory {xsd:string} ) |
* ( factory )
* )
* }
*
* factory = element factory {
* ( bean |
* ref
* )
* }
*
* save-operations = element save-operations {
* ( save-operation* )
* }
*
* save-operation = element save-operation {
* ( ( attribute class {xsd:string} ) |
* ( bean |
* ref
* )
* )
* }
*
* bean = element bean {
* ( attribute ref-name {xsd:string} ) |
* ( attribute name {xsd:string}?,
* attribute class {xsd:string}?,
* attribute singleton { "true" | "false" }?,
* constructor*,
* field*,
* property*
* )
* }
*
* ref = element ref {
* ( attribute bean (xsd:string) )
* }
*
* constructor = element constructor {
* attribute class {xsd:string}?,
* ( attribute factory {xsd:string},
* attribute method {xsd:string}
* )?,
* parameter*
* }
*
* parameter = element parameter {
* attribute class {xsd:string},
* object
* }
*
* field = element field {
* attribute name {xsd:string},
* object
* }
*
* property = element property {
* ( attribute name {xsd:string} |
* attribute setter {xsd:string}
* ),
* object
* }
*
* map = element map {
* entry*
* }
*
* entry = element entry {
* key,
* value
* }
*
* key = element key {
* object
* }
*
* value = element value {
* object
* }
*
* list = element list {
* object*
* }
*
* string = element string {xsd:string}
* int = element integer {xsd:integer}
* long = element long {xsd:long}
* float = element float {xsd:string}
* double = element string {xsd:double}
* char = element char {xsd:character}
* bool = element bool { "true" | "false" }
* true = element true {}
* false = element false {}
* null = element null {}
* </pre>
* </p>
*
* <p>
* Other configuration properties
* <table>
* <tr>
* <td>jbpm.msg.wait.timout</td><td></td>
* </tr>
* <tr>
* <td>jbpm.files.dir</td><td></td>
* </tr>
* <tr>
* <td>jbpm.types</td><td></td>
* </tr>
* </table>
* </p>
*/
public class JbpmConfiguration implements Serializable {
private static final long serialVersionUID = 1L;
static ObjectFactory defaultObjectFactory = null;
static Map instances = new HashMap();
/**
* resets static members for test isolation.
*/
static void reset() {
defaultObjectFactory = null;
instances = new HashMap();
}
ObjectFactory objectFactory = null;
static ThreadLocal jbpmConfigurationsStacks = new ThreadLocal();
ThreadLocal jbpmContextStacks = new ThreadLocal();
public JbpmConfiguration(ObjectFactory objectFactory) {
this.objectFactory = objectFactory;
}
public static JbpmConfiguration getInstance() {
return getInstance(null);
}
public static JbpmConfiguration getInstance(String resource) {
JbpmConfiguration instance = null;
synchronized(instances) {
if (resource==null) {
resource = "jbpm.cfg.xml";
}
instance = (JbpmConfiguration) instances.get(resource);
if (instance==null) {
if (defaultObjectFactory!=null) {
log.debug("creating jbpm configuration from given default object factory '"+defaultObjectFactory+"'");
instance = new JbpmConfiguration(defaultObjectFactory);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -