use of org.springframework.aop.scope.ScopedObject in project camunda-bpm-platform by camunda.
the class ProcessScope method createDirtyCheckingProxy.
private Object createDirtyCheckingProxy(final String name, final Object scopedObject) throws Throwable {
ProxyFactory proxyFactoryBean = new ProxyFactory(scopedObject);
proxyFactoryBean.setProxyTargetClass(this.proxyTargetClass);
proxyFactoryBean.addAdvice(new MethodInterceptor() {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Object result = methodInvocation.proceed();
persistVariable(name, scopedObject);
return result;
}
});
return proxyFactoryBean.getProxy(this.classLoader);
}
use of org.springframework.aop.scope.ScopedObject in project spring-framework by spring-projects.
the class ScopingTests method testScopedProxyConfiguration.
@Test
public void testScopedProxyConfiguration() throws Exception {
TestBean singleton = (TestBean) ctx.getBean("singletonWithScopedInterfaceDep");
ITestBean spouse = singleton.getSpouse();
boolean condition = spouse instanceof ScopedObject;
assertThat(condition).as("scoped bean is not wrapped by the scoped-proxy").isTrue();
String beanName = "scopedProxyInterface";
String scopedBeanName = "scopedTarget." + beanName;
// get hidden bean
assertThat(spouse.getName()).isEqualTo(flag);
ITestBean spouseFromBF = (ITestBean) ctx.getBean(scopedBeanName);
assertThat(spouseFromBF.getName()).isEqualTo(spouse.getName());
// the scope proxy has kicked in
assertThat(spouseFromBF).isNotSameAs(spouse);
// create a new bean
customScope.createNewScope = true;
// get the bean again from the BF
spouseFromBF = (ITestBean) ctx.getBean(scopedBeanName);
// make sure the name has been updated
assertThat(spouseFromBF.getName()).isSameAs(spouse.getName());
assertThat(spouseFromBF).isNotSameAs(spouse);
// get the bean again
spouseFromBF = (ITestBean) ctx.getBean(scopedBeanName);
assertThat(spouseFromBF.getName()).isSameAs(spouse.getName());
}
use of org.springframework.aop.scope.ScopedObject in project spring-framework by spring-projects.
the class ScopingTests method testRawScopes.
@Test
public void testRawScopes() throws Exception {
String beanName = "scopedProxyInterface";
// get hidden bean
Object bean = ctx.getBean("scopedTarget." + beanName);
boolean condition = bean instanceof ScopedObject;
assertThat(condition).isFalse();
}
use of org.springframework.aop.scope.ScopedObject in project spring-framework by spring-projects.
the class ScopingTests method testScopedProxyConfigurationWithClasses.
@Test
public void testScopedProxyConfigurationWithClasses() throws Exception {
TestBean singleton = (TestBean) ctx.getBean("singletonWithScopedClassDep");
ITestBean spouse = singleton.getSpouse();
boolean condition = spouse instanceof ScopedObject;
assertThat(condition).as("scoped bean is not wrapped by the scoped-proxy").isTrue();
String beanName = "scopedProxyClass";
String scopedBeanName = "scopedTarget." + beanName;
// get hidden bean
assertThat(spouse.getName()).isEqualTo(flag);
TestBean spouseFromBF = (TestBean) ctx.getBean(scopedBeanName);
assertThat(spouseFromBF.getName()).isEqualTo(spouse.getName());
// the scope proxy has kicked in
assertThat(spouseFromBF).isNotSameAs(spouse);
// create a new bean
customScope.createNewScope = true;
flag = "boo";
// get the bean again from the BF
spouseFromBF = (TestBean) ctx.getBean(scopedBeanName);
// make sure the name has been updated
assertThat(spouseFromBF.getName()).isSameAs(spouse.getName());
assertThat(spouseFromBF).isNotSameAs(spouse);
// get the bean again
spouseFromBF = (TestBean) ctx.getBean(scopedBeanName);
assertThat(spouseFromBF.getName()).isSameAs(spouse.getName());
}
use of org.springframework.aop.scope.ScopedObject in project camunda-bpm-platform by camunda.
the class ProcessScope method get.
public Object get(String name, ObjectFactory<?> objectFactory) {
ExecutionEntity executionEntity = null;
try {
logger.fine("returning scoped object having beanName '" + name + "' for conversation ID '" + this.getConversationId() + "'. ");
ProcessInstance processInstance = Context.getExecutionContext().getProcessInstance();
executionEntity = (ExecutionEntity) processInstance;
Object scopedObject = executionEntity.getVariable(name);
if (scopedObject == null) {
scopedObject = objectFactory.getObject();
if (scopedObject instanceof ScopedObject) {
ScopedObject sc = (ScopedObject) scopedObject;
scopedObject = sc.getTargetObject();
logger.fine("de-referencing " + ScopedObject.class.getName() + "#targetObject before persisting variable");
}
persistVariable(name, scopedObject);
}
return createDirtyCheckingProxy(name, scopedObject);
} catch (Throwable th) {
logger.warning("couldn't return value from process scope! " + ExceptionUtils.getFullStackTrace(th));
} finally {
if (executionEntity != null) {
logger.fine("set variable '" + name + "' on executionEntity# " + executionEntity.getId());
}
}
return null;
}
Aggregations