📄 jbpmconfiguration.java
字号:
} else {
try {
log.info("using jbpm configuration resource '"+resource+"'");
InputStream jbpmCfgXmlStream = ClassLoaderUtil.getStream(resource);
ObjectFactory objectFactory = parseObjectFactory(jbpmCfgXmlStream);
instance = new JbpmConfiguration(objectFactory);
} catch (RuntimeException e) {
throw new JbpmException("couldn't parse jbpm configuration from resource '"+resource+"'", e);
}
}
instances.put(resource, instance);
}
}
return instance;
}
protected static ObjectFactory parseObjectFactory(InputStream inputStream) {
log.debug("loading defaults in jbpm configuration");
ObjectFactoryParser objectFactoryParser = new ObjectFactoryParser();
ObjectFactoryImpl objectFactoryImpl = new ObjectFactoryImpl();
objectFactoryParser.parseElementsFromResource("org/jbpm/default.jbpm.cfg.xml", objectFactoryImpl);
if (inputStream!=null) {
log.debug("loading specific configuration...");
objectFactoryParser.parseElementsStream(inputStream, objectFactoryImpl);
}
return objectFactoryImpl;
}
/**
* create an ObjectFacotory from an XML string.
*/
public static JbpmConfiguration parseXmlString(String xml) {
log.debug("creating jbpm configuration from xml string");
InputStream inputStream = null;
if (xml!=null) {
inputStream = new ByteArrayInputStream(xml.getBytes());
}
ObjectFactory objectFactory = parseObjectFactory(inputStream);
return new JbpmConfiguration(objectFactory);
}
public static JbpmConfiguration parseInputStream(InputStream inputStream) {
ObjectFactory objectFactory = parseObjectFactory(inputStream);
log.debug("creating jbpm configuration from input stream");
return new JbpmConfiguration(objectFactory);
}
public static JbpmConfiguration parseResource(String resource) {
InputStream inputStream = null;
log.debug("creating jbpm configuration from resource '"+resource+"'");
if (resource!=null) {
inputStream = ClassLoaderUtil.getStream(resource);
}
ObjectFactory objectFactory = parseObjectFactory(inputStream);
return new JbpmConfiguration(objectFactory);
}
public JbpmContext createJbpmContext() {
return createJbpmContext(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
public JbpmContext createJbpmContext(String name) {
JbpmContext jbpmContext = (JbpmContext) objectFactory.createObject(name);
jbpmContext.jbpmConfiguration = this;
jbpmContextCreated(jbpmContext);
return jbpmContext;
}
public ServiceFactory getServiceFactory(String serviceName) {
return getServiceFactory(serviceName, JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
public ServiceFactory getServiceFactory(String serviceName, String jbpmContextName) {
ServiceFactory serviceFactory = null;
JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
try {
serviceFactory = jbpmContext.getServices().getServiceFactory(serviceName);
} finally {
jbpmContext.close();
}
return serviceFactory;
}
/**
* gives the jbpm domain model access to configuration information via the current JbpmContext.
*/
public abstract static class Configs {
public static ObjectFactory getObjectFactory() {
ObjectFactory objectFactory = null;
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if (jbpmContext!=null) {
objectFactory = jbpmContext.objectFactory;
} else {
objectFactory = getInstance().objectFactory;
}
return objectFactory;
}
public static void setDefaultObjectFactory(ObjectFactory objectFactory){
defaultObjectFactory = objectFactory;
}
public static boolean hasObject(String name) {
ObjectFactory objectFactory = getObjectFactory();
return objectFactory.hasObject(name);
}
public static synchronized Object getObject(String name) {
ObjectFactory objectFactory = getObjectFactory();
return objectFactory.createObject(name);
}
public static String getString(String name) {
return (String) getObject(name);
}
public static long getLong(String name) {
return ((Long)getObject(name)).longValue();
}
public static int getInt(String name) {
return ((Integer)getObject(name)).intValue();
}
public static boolean getBoolean(String name) {
return ((Boolean)getObject(name)).booleanValue();
}
}
public void createSchema() {
createSchema(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
public void createSchema(String jbpmContextName) {
JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
try {
Services services = jbpmContext.getServices();
DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
persistenceServiceFactory.createSchema();
} finally {
jbpmContext.close();
}
}
public void dropSchema() {
dropSchema(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
public void dropSchema(String jbpmContextName) {
JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
try {
Services services = jbpmContext.getServices();
DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
persistenceServiceFactory.dropSchema();
} finally {
jbpmContext.close();
}
}
public void close() {
close(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
public void close(String jbpmContextName) {
JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
try {
synchronized (instances) {
Iterator iter = instances.keySet().iterator();
while(iter.hasNext()) {
String resource = (String) iter.next();
if (this==instances.get(resource)) {
instances.remove(resource);
break;
}
}
}
Map serviceFactories = jbpmContext.getServices().getServiceFactories();
if (serviceFactories!=null) {
Iterator iter = serviceFactories.values().iterator();
while (iter.hasNext()) {
ServiceFactory serviceFactory = (ServiceFactory) iter.next();
serviceFactory.close();
}
}
} finally {
jbpmContext.close();
}
}
static JbpmConfiguration getCurrentJbpmConfiguration() {
JbpmConfiguration currentJbpmConfiguration = null;
Stack stack = getJbpmConfigurationStack();
if (! stack.isEmpty()) {
currentJbpmConfiguration = (JbpmConfiguration) stack.peek();
}
return currentJbpmConfiguration;
}
static synchronized Stack getJbpmConfigurationStack() {
Stack stack = (Stack) jbpmConfigurationsStacks.get();
if (stack==null) {
stack = new Stack();
jbpmConfigurationsStacks.set(stack);
}
return stack;
}
synchronized void pushJbpmConfiguration() {
getJbpmConfigurationStack().push(this);
}
synchronized void popJbpmConfiguration() {
getJbpmConfigurationStack().remove(this);
}
public JbpmContext getCurrentJbpmContext() {
JbpmContext currentJbpmContext = null;
Stack stack = getJbpmContextStack();
if (! stack.isEmpty()) {
currentJbpmContext = (JbpmContext) stack.peek();
}
return currentJbpmContext;
}
Stack getJbpmContextStack() {
Stack stack = (Stack) jbpmContextStacks.get();
if (stack==null) {
stack = new Stack();
jbpmContextStacks.set(stack);
}
return stack;
}
void pushJbpmContext(JbpmContext jbpmContext) {
getJbpmContextStack().push(jbpmContext);
}
void popJbpmContext(JbpmContext jbpmContext) {
Stack stack = getJbpmContextStack();
if (stack.isEmpty()) {
throw new JbpmException("closed JbpmContext more then once... check your try-finally's around JbpmContexts blocks");
}
JbpmContext popped = (JbpmContext) stack.pop();
if (jbpmContext!=popped) {
throw new JbpmException("closed JbpmContext in different order then they were created... check your try-finally's around JbpmContexts blocks");
}
}
void jbpmContextCreated(JbpmContext jbpmContext) {
pushJbpmConfiguration();
pushJbpmContext(jbpmContext);
}
void jbpmContextClosed(JbpmContext jbpmContext) {
popJbpmConfiguration();
popJbpmContext(jbpmContext);
}
private static Log log = LogFactory.getLog(JbpmConfiguration.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -