Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
开发团队
Flowable Engine
提交
664ce00f
F
Flowable Engine
项目概览
开发团队
/
Flowable Engine
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Flowable Engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
664ce00f
编写于
9月 06, 2010
作者:
T
tombaeyens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ACT-127 start restructuring the modules
上级
6f1ea38f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
680 addition
and
0 deletion
+680
-0
modules/activiti-pvm/src/test/java/org/activiti/examples/pvm/Automatic.java
...vm/src/test/java/org/activiti/examples/pvm/Automatic.java
+29
-0
modules/activiti-pvm/src/test/java/org/activiti/examples/pvm/Decision.java
...pvm/src/test/java/org/activiti/examples/pvm/Decision.java
+38
-0
modules/activiti-pvm/src/test/java/org/activiti/examples/pvm/PvmTest.java
...-pvm/src/test/java/org/activiti/examples/pvm/PvmTest.java
+121
-0
modules/activiti-pvm/src/test/java/org/activiti/examples/pvm/WaitState.java
...vm/src/test/java/org/activiti/examples/pvm/WaitState.java
+55
-0
modules/activiti-spring/src/main/java/org/activiti/spring/ApplicationContextElResolver.java
...ava/org/activiti/spring/ApplicationContextElResolver.java
+68
-0
modules/activiti-spring/src/main/java/org/activiti/spring/ProcessEngineFactoryBean.java
...in/java/org/activiti/spring/ProcessEngineFactoryBean.java
+198
-0
modules/activiti-spring/src/main/java/org/activiti/spring/SpringExpressionManager.java
...ain/java/org/activiti/spring/SpringExpressionManager.java
+53
-0
modules/activiti-spring/src/main/java/org/activiti/spring/SpringProcessEngineTestCase.java
...java/org/activiti/spring/SpringProcessEngineTestCase.java
+74
-0
modules/activiti-spring/src/main/java/org/activiti/spring/SpringTransactionInterceptor.java
...ava/org/activiti/spring/SpringTransactionInterceptor.java
+44
-0
未找到文件。
modules/activiti-pvm/src/test/java/org/activiti/examples/pvm/Automatic.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.examples.pvm
;
import
org.activiti.pvm.activity.ActivityBehavior
;
import
org.activiti.pvm.activity.ActivityExecution
;
import
org.activiti.pvm.process.PvmTransition
;
/**
* @author Tom Baeyens
*/
public
class
Automatic
implements
ActivityBehavior
{
public
void
execute
(
ActivityExecution
activityContext
)
throws
Exception
{
PvmTransition
defaultOutgoingTransition
=
activityContext
.
getActivity
().
getOutgoingTransitions
().
get
(
0
);
activityContext
.
take
(
defaultOutgoingTransition
);
}
}
modules/activiti-pvm/src/test/java/org/activiti/examples/pvm/Decision.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.examples.pvm
;
import
org.activiti.pvm.activity.ActivityBehavior
;
import
org.activiti.pvm.activity.ActivityExecution
;
import
org.activiti.pvm.process.PvmTransition
;
/**
* @author Tom Baeyens
*/
public
class
Decision
implements
ActivityBehavior
{
public
void
execute
(
ActivityExecution
execution
)
throws
Exception
{
PvmTransition
transition
=
null
;
String
creditRating
=
(
String
)
execution
.
getVariable
(
"creditRating"
);
if
(
creditRating
.
equals
(
"AAA+"
))
{
transition
=
execution
.
getActivity
().
findOutgoingTransition
(
"wow"
);
}
else
if
(
creditRating
.
equals
(
"Aaa-"
))
{
transition
=
execution
.
getActivity
().
findOutgoingTransition
(
"nice"
);
}
else
{
transition
=
execution
.
getActivity
().
findOutgoingTransition
(
"default"
);
}
execution
.
take
(
transition
);
}
}
modules/activiti-pvm/src/test/java/org/activiti/examples/pvm/PvmTest.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.examples.pvm
;
import
junit.framework.TestCase
;
import
org.activiti.pvm.ProcessDefinitionBuilder
;
import
org.activiti.pvm.process.PvmProcessDefinition
;
import
org.activiti.pvm.runtime.PvmExecution
;
import
org.activiti.pvm.runtime.PvmProcessInstance
;
/**
* @author Tom Baeyens
*/
public
class
PvmTest
extends
TestCase
{
public
void
testPvmWaitState
()
{
PvmProcessDefinition
processDefinition
=
new
ProcessDefinitionBuilder
()
.
createActivity
(
"a"
)
.
initial
()
.
behavior
(
new
WaitState
())
.
transition
(
"b"
)
.
endActivity
()
.
createActivity
(
"b"
)
.
behavior
(
new
WaitState
())
.
transition
(
"c"
)
.
endActivity
()
.
createActivity
(
"c"
)
.
behavior
(
new
WaitState
())
.
endActivity
()
.
buildProcessDefinition
();
PvmProcessInstance
processInstance
=
processDefinition
.
createProcessInstance
();
processInstance
.
start
();
PvmExecution
activityInstance
=
processInstance
.
findExecution
(
"a"
);
assertNotNull
(
activityInstance
);
activityInstance
.
signal
(
null
,
null
);
activityInstance
=
processInstance
.
findExecution
(
"b"
);
assertNotNull
(
activityInstance
);
activityInstance
.
signal
(
null
,
null
);
activityInstance
=
processInstance
.
findExecution
(
"c"
);
assertNotNull
(
activityInstance
);
}
public
void
testPvmAutomatic
()
{
PvmProcessDefinition
processDefinition
=
new
ProcessDefinitionBuilder
()
.
createActivity
(
"a"
)
.
initial
()
.
behavior
(
new
Automatic
())
.
transition
(
"b"
)
.
endActivity
()
.
createActivity
(
"b"
)
.
behavior
(
new
Automatic
())
.
transition
(
"c"
)
.
endActivity
()
.
createActivity
(
"c"
)
.
behavior
(
new
WaitState
())
.
endActivity
()
.
buildProcessDefinition
();
PvmProcessInstance
processInstance
=
processDefinition
.
createProcessInstance
();
processInstance
.
start
();
assertNotNull
(
processInstance
.
findExecution
(
"c"
));
}
public
void
testPvmDecision
()
{
PvmProcessDefinition
processDefinition
=
new
ProcessDefinitionBuilder
()
.
createActivity
(
"start"
)
.
initial
()
.
behavior
(
new
Automatic
())
.
transition
(
"checkCredit"
)
.
endActivity
()
.
createActivity
(
"checkCredit"
)
.
behavior
(
new
Decision
())
.
transition
(
"askDaughterOut"
,
"wow"
)
.
transition
(
"takeToGolf"
,
"nice"
)
.
transition
(
"ignore"
,
"default"
)
.
endActivity
()
.
createActivity
(
"takeToGolf"
)
.
behavior
(
new
WaitState
())
.
endActivity
()
.
createActivity
(
"askDaughterOut"
)
.
behavior
(
new
WaitState
())
.
endActivity
()
.
createActivity
(
"ignore"
)
.
behavior
(
new
WaitState
())
.
endActivity
()
.
buildProcessDefinition
();
PvmProcessInstance
processInstance
=
processDefinition
.
createProcessInstance
();
processInstance
.
setVariable
(
"creditRating"
,
"Aaa-"
);
processInstance
.
start
();
assertNotNull
(
processInstance
.
findExecution
(
"takeToGolf"
));
processInstance
=
processDefinition
.
createProcessInstance
();
processInstance
.
setVariable
(
"creditRating"
,
"AAA+"
);
processInstance
.
start
();
assertNotNull
(
processInstance
.
findExecution
(
"askDaughterOut"
));
processInstance
=
processDefinition
.
createProcessInstance
();
processInstance
.
setVariable
(
"creditRating"
,
"bb-"
);
processInstance
.
start
();
assertNotNull
(
processInstance
.
findExecution
(
"ignore"
));
}
}
modules/activiti-pvm/src/test/java/org/activiti/examples/pvm/WaitState.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.examples.pvm
;
import
org.activiti.pvm.activity.ActivityExecution
;
import
org.activiti.pvm.activity.SignallableActivityBehavior
;
import
org.activiti.pvm.process.PvmTransition
;
/**
* @author Tom Baeyens
*/
public
class
WaitState
implements
SignallableActivityBehavior
{
public
void
execute
(
ActivityExecution
execution
)
{
// By default, the execution will not propagate.
// So if no method like take(Transition) is called on execution
// then the activity will behave as a wait state. The execution is currently
// pointing to the activity. The original call to execution.start()
// or execution.event() will return. Then the execution object will
// remain pointing to the current activity until execution.event(Object) is called.
// That method will delegate to the method below.
}
public
void
signal
(
ActivityExecution
execution
,
String
signalName
,
Object
event
)
{
PvmTransition
transition
=
findTransition
(
execution
,
signalName
);
execution
.
take
(
transition
);
}
protected
PvmTransition
findTransition
(
ActivityExecution
execution
,
String
signalName
)
{
for
(
PvmTransition
transition:
execution
.
getActivity
().
getOutgoingTransitions
())
{
if
(
signalName
==
null
)
{
if
(
transition
.
getId
()==
null
)
{
return
transition
;
}
}
else
{
if
(
signalName
.
equals
(
transition
.
getId
()))
{
return
transition
;
}
}
}
throw
new
RuntimeException
(
"no transition for signalName '"
+
signalName
+
"' in WaitState '"
+
execution
.
getActivity
().
getId
()+
"'"
);
}
}
modules/activiti-spring/src/main/java/org/activiti/spring/ApplicationContextElResolver.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.spring
;
import
java.beans.FeatureDescriptor
;
import
java.util.Iterator
;
import
javax.el.ELContext
;
import
javax.el.ELResolver
;
import
org.springframework.context.ApplicationContext
;
/**
* @author Tom Baeyens
*/
public
class
ApplicationContextElResolver
extends
ELResolver
{
protected
ApplicationContext
applicationContext
;
public
ApplicationContextElResolver
(
ApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
}
public
Object
getValue
(
ELContext
context
,
Object
base
,
Object
property
)
{
if
(
base
==
null
)
{
// according to javadoc, can only be a String
String
key
=
(
String
)
property
;
if
(
applicationContext
.
containsBean
(
key
))
{
context
.
setPropertyResolved
(
true
);
return
applicationContext
.
getBean
(
key
);
}
}
return
null
;
}
public
boolean
isReadOnly
(
ELContext
context
,
Object
base
,
Object
property
)
{
return
true
;
}
public
void
setValue
(
ELContext
context
,
Object
base
,
Object
property
,
Object
value
)
{
}
public
Class
<
?
>
getCommonPropertyType
(
ELContext
context
,
Object
arg
)
{
return
Object
.
class
;
}
public
Iterator
<
FeatureDescriptor
>
getFeatureDescriptors
(
ELContext
context
,
Object
arg
)
{
return
null
;
}
public
Class
<
?
>
getType
(
ELContext
context
,
Object
arg1
,
Object
arg2
)
{
return
Object
.
class
;
}
}
modules/activiti-spring/src/main/java/org/activiti/spring/ProcessEngineFactoryBean.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.spring
;
import
java.io.IOException
;
import
java.util.zip.ZipInputStream
;
import
javax.sql.DataSource
;
import
org.activiti.engine.DbSchemaStrategy
;
import
org.activiti.engine.HistoryService
;
import
org.activiti.engine.IdentityService
;
import
org.activiti.engine.ProcessEngine
;
import
org.activiti.engine.RepositoryService
;
import
org.activiti.engine.impl.ProcessEngineImpl
;
import
org.activiti.engine.impl.cfg.IdGenerator
;
import
org.activiti.engine.impl.cfg.ProcessEngineConfiguration
;
import
org.activiti.engine.impl.interceptor.CommandExecutor
;
import
org.activiti.engine.impl.interceptor.DefaultCommandExecutor
;
import
org.activiti.engine.impl.jobexecutor.JobExecutor
;
import
org.activiti.engine.impl.variable.VariableTypes
;
import
org.activiti.engine.repository.DeploymentBuilder
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.beans.factory.FactoryBean
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.ContextResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.transaction.PlatformTransactionManager
;
/**
* @author Dave Syer
* @author Christian Stettler
* @author Tom Baeyens
*/
public
class
ProcessEngineFactoryBean
implements
FactoryBean
<
ProcessEngine
>,
DisposableBean
,
ApplicationContextAware
{
protected
ProcessEngineConfiguration
processEngineConfiguration
=
new
ProcessEngineConfiguration
();
protected
PlatformTransactionManager
transactionManager
;
protected
ApplicationContext
applicationContext
;
protected
String
deploymentName
=
"SpringAutoDeployment"
;
protected
Resource
[]
deploymentResources
=
new
Resource
[
0
];
protected
ProcessEngineImpl
processEngine
;
public
void
destroy
()
throws
Exception
{
if
(
processEngine
!=
null
)
{
processEngine
.
close
();
}
}
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
}
public
ProcessEngine
getObject
()
throws
Exception
{
initializeSpringTransactionInterceptor
();
initializeExpressionManager
();
processEngine
=
(
ProcessEngineImpl
)
processEngineConfiguration
.
buildProcessEngine
();
if
(
deploymentResources
.
length
>
0
)
{
autoDeployResources
();
}
return
processEngine
;
}
private
void
initializeSpringTransactionInterceptor
()
{
processEngineConfiguration
.
setLocalTransactions
(
transactionManager
==
null
);
if
(
transactionManager
!=
null
)
{
DefaultCommandExecutor
commandExecutor
=
(
DefaultCommandExecutor
)
processEngineConfiguration
.
getCommandExecutor
();
commandExecutor
.
addCommandInterceptor
(
new
SpringTransactionInterceptor
(
transactionManager
));
processEngineConfiguration
.
setCommandExecutor
(
commandExecutor
);
}
}
protected
void
initializeExpressionManager
()
{
processEngineConfiguration
.
setExpressionManager
(
new
SpringExpressionManager
(
applicationContext
));
}
public
Class
<
?
>
getObjectType
()
{
return
ProcessEngine
.
class
;
}
public
boolean
isSingleton
()
{
return
true
;
}
protected
void
autoDeployResources
()
throws
IOException
{
RepositoryService
repositoryService
=
processEngine
.
getRepositoryService
();
DeploymentBuilder
deploymentBuilder
=
repositoryService
.
createDeployment
()
.
enableDuplicateFiltering
()
.
name
(
deploymentName
);
for
(
Resource
resource
:
deploymentResources
)
{
String
resourceName
=
null
;
if
(
resource
instanceof
ContextResource
)
{
resourceName
=
((
ContextResource
)
resource
).
getPathWithinContext
();
}
else
if
(
resource
instanceof
ByteArrayResource
)
{
resourceName
=
resource
.
getDescription
();
}
else
{
try
{
resourceName
=
resource
.
getFile
().
getAbsolutePath
();
}
catch
(
IOException
e
)
{
resourceName
=
resource
.
getFilename
();
}
}
if
(
resourceName
.
endsWith
(
".bar"
)
||
resourceName
.
endsWith
(
".zip"
)
||
resourceName
.
endsWith
(
".jar"
)
)
{
deploymentBuilder
.
addZipInputStream
(
new
ZipInputStream
(
resource
.
getInputStream
()));
}
else
{
deploymentBuilder
.
addInputStream
(
resourceName
,
resource
.
getInputStream
());
}
}
deploymentBuilder
.
deploy
();
}
// getters and setters //////////////////////////////////////////////////////
public
void
setTransactionManager
(
PlatformTransactionManager
transactionManager
)
{
this
.
transactionManager
=
transactionManager
;
}
public
void
setDeploymentName
(
String
deploymentName
)
{
this
.
deploymentName
=
deploymentName
;
}
public
void
setDeploymentResources
(
Resource
[]
deploymentResources
)
{
this
.
deploymentResources
=
deploymentResources
;
}
public
void
setCommandExecutor
(
CommandExecutor
commandExecutor
)
{
processEngineConfiguration
.
setCommandExecutor
(
commandExecutor
);
}
public
void
setDataBaseName
(
String
dataBaseName
)
{
processEngineConfiguration
.
setDatabaseName
(
dataBaseName
);
}
public
void
setDataSource
(
DataSource
dataSource
)
{
processEngineConfiguration
.
setDataSource
(
dataSource
);
}
public
void
setDbSchemaStrategy
(
DbSchemaStrategy
dbSchemaStrategy
)
{
processEngineConfiguration
.
setDbSchemaStrategy
(
dbSchemaStrategy
);
}
public
void
setHistoricDataService
(
HistoryService
historicDataService
)
{
processEngineConfiguration
.
setHistoricDataService
(
historicDataService
);
}
public
void
setIdentityService
(
IdentityService
identityService
)
{
processEngineConfiguration
.
setIdentityService
(
identityService
);
}
public
void
setIdGenerator
(
IdGenerator
idGenerator
)
{
processEngineConfiguration
.
setIdGenerator
(
idGenerator
);
}
public
void
setJobExecutor
(
JobExecutor
jobExecutor
)
{
processEngineConfiguration
.
setJobExecutor
(
jobExecutor
);
}
public
void
setJobExecutorAutoActivate
(
boolean
jobExecutorAutoActivate
)
{
processEngineConfiguration
.
setJobExecutorAutoActivate
(
jobExecutorAutoActivate
);
}
public
void
setProcessEngineName
(
String
processEngineName
)
{
processEngineConfiguration
.
setProcessEngineName
(
processEngineName
);
}
public
void
setVariableTypes
(
VariableTypes
variableTypes
)
{
processEngineConfiguration
.
setVariableTypes
(
variableTypes
);
}
}
modules/activiti-spring/src/main/java/org/activiti/spring/SpringExpressionManager.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.spring
;
import
javax.el.ArrayELResolver
;
import
javax.el.BeanELResolver
;
import
javax.el.CompositeELResolver
;
import
javax.el.ELResolver
;
import
javax.el.ListELResolver
;
import
javax.el.MapELResolver
;
import
org.activiti.engine.impl.el.ExecutionVariableElResolver
;
import
org.activiti.engine.impl.el.ExpressionManager
;
import
org.activiti.pvm.impl.runtime.ExecutionImpl
;
import
org.springframework.context.ApplicationContext
;
/**
* @author Tom Baeyens
*/
public
class
SpringExpressionManager
extends
ExpressionManager
{
protected
ApplicationContext
applicationContext
;
public
SpringExpressionManager
(
ApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
}
@Override
protected
ELResolver
createElResolver
(
ExecutionImpl
execution
)
{
CompositeELResolver
compositeElResolver
=
new
CompositeELResolver
();
compositeElResolver
.
add
(
new
ExecutionVariableElResolver
(
execution
));
compositeElResolver
.
add
(
new
ApplicationContextElResolver
(
applicationContext
));
compositeElResolver
.
add
(
new
ArrayELResolver
());
compositeElResolver
.
add
(
new
ListELResolver
());
compositeElResolver
.
add
(
new
MapELResolver
());
compositeElResolver
.
add
(
new
BeanELResolver
());
return
compositeElResolver
;
}
}
modules/activiti-spring/src/main/java/org/activiti/spring/SpringProcessEngineTestCase.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.spring
;
import
java.io.InputStream
;
import
java.util.Map
;
import
java.util.logging.Logger
;
import
org.activiti.engine.ActivitiException
;
import
org.activiti.engine.ProcessEngine
;
import
org.activiti.engine.test.ProcessEngineTestCase
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
/**
* @author Tom Baeyens
*/
public
class
SpringProcessEngineTestCase
extends
ProcessEngineTestCase
{
private
static
Logger
log
=
Logger
.
getLogger
(
SpringProcessEngineTestCase
.
class
.
getName
());
protected
String
springApplicationContextConfigurationResource
;
protected
ApplicationContext
applicationContext
;
public
SpringProcessEngineTestCase
()
{
if
(
getResourceAsStream
(
"applicationContext.xml"
)!=
null
)
{
this
.
springApplicationContextConfigurationResource
=
"applicationContext.xml"
;
this
.
configurationResource
=
null
;
}
}
public
SpringProcessEngineTestCase
(
String
springApplicationContextConfigurationResource
)
{
this
.
springApplicationContextConfigurationResource
=
springApplicationContextConfigurationResource
;
this
.
configurationResource
=
null
;
}
InputStream
getResourceAsStream
(
String
resourceName
)
{
return
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
resourceName
);
}
protected
void
initializeProcessEngine
()
{
if
(
configurationResource
!=
null
)
{
super
.
initializeProcessEngine
();
}
else
if
(
springApplicationContextConfigurationResource
!=
null
)
{
log
.
fine
(
"==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE ========================================="
);
this
.
applicationContext
=
new
ClassPathXmlApplicationContext
(
springApplicationContextConfigurationResource
);
Map
<
String
,
ProcessEngine
>
beansOfType
=
applicationContext
.
getBeansOfType
(
ProcessEngine
.
class
);
if
(
(
beansOfType
==
null
)
||
(
beansOfType
.
isEmpty
())
)
{
throw
new
ActivitiException
(
"no "
+
ProcessEngine
.
class
.
getName
()+
" defined in the application context "
+
springApplicationContextConfigurationResource
);
}
processEngine
=
beansOfType
.
values
().
iterator
().
next
();
log
.
fine
(
"==== SPRING PROCESS ENGINE CREATED =================================================================="
);
}
}
}
modules/activiti-spring/src/main/java/org/activiti/spring/SpringTransactionInterceptor.java
0 → 100644
浏览文件 @
664ce00f
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.spring
;
import
org.activiti.engine.impl.interceptor.Command
;
import
org.activiti.engine.impl.interceptor.CommandExecutor
;
import
org.activiti.engine.impl.interceptor.CommandInterceptor
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.TransactionStatus
;
import
org.springframework.transaction.support.TransactionCallback
;
import
org.springframework.transaction.support.TransactionTemplate
;
/**
* @author Dave Syer
* @author Tom Baeyens
*/
public
class
SpringTransactionInterceptor
implements
CommandInterceptor
{
protected
PlatformTransactionManager
transactionManager
;
public
SpringTransactionInterceptor
(
PlatformTransactionManager
transactionManager
)
{
this
.
transactionManager
=
transactionManager
;
}
public
<
T
>
T
invoke
(
final
CommandExecutor
next
,
final
Command
<
T
>
command
)
{
@SuppressWarnings
(
"unchecked"
)
T
result
=
(
T
)
new
TransactionTemplate
(
transactionManager
).
execute
(
new
TransactionCallback
()
{
public
Object
doInTransaction
(
TransactionStatus
status
)
{
return
next
.
execute
(
command
);
}
});
return
result
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录