本文整理汇总了Java中org.springframework.aop.scope.ScopedObject类的典型用法代码示例。如果您正苦于以下问题:Java ScopedObject类的具体用法?Java ScopedObject怎么用?Java ScopedObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScopedObject类属于org.springframework.aop.scope包,在下文中一共展示了ScopedObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interceptorWithPlainObject
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Test
public void interceptorWithPlainObject() throws Exception {
final Object realObject = new Object();
ScopedObject scoped = new ScopedObject() {
@Override
public Object getTargetObject() {
return realObject;
}
@Override
public void removeFromScope() {
// do nothing
}
};
// default contract is to return null for default behavior
assertNull(interceptor.getEntityName(realObject));
assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped));
}
示例2: interceptorWithCglibProxy
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Test
public void interceptorWithCglibProxy() throws Exception {
final Object realObject = new Object();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(realObject);
proxyFactory.setProxyTargetClass(true);
final Object proxy = proxyFactory.getProxy();
ScopedObject scoped = new ScopedObject() {
@Override
public Object getTargetObject() {
return proxy;
}
@Override
public void removeFromScope() {
// do nothing
}
};
assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped));
}
示例3: testInterceptorWithPlainObject
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
public void testInterceptorWithPlainObject() throws Exception {
ScopedBeanInterceptor interceptor = new ScopedBeanInterceptor();
final Object realObject = new Object();
ScopedObject scoped = new ScopedObject() {
@Override
public Object getTargetObject() {
return realObject;
}
@Override
public void removeFromScope() {
// do nothing
}
};
// default contract is to return null for default behavior
assertEquals(null, interceptor.getEntityName(realObject));
assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped));
}
示例4: testInterceptorWithCglibProxy
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
public void testInterceptorWithCglibProxy() throws Exception {
ScopedBeanInterceptor interceptor = new ScopedBeanInterceptor();
final Object realObject = new Object();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(realObject);
proxyFactory.setProxyTargetClass(true);
final Object proxy = proxyFactory.getProxy();
ScopedObject scoped = new ScopedObject() {
@Override
public Object getTargetObject() {
return proxy;
}
@Override
public void removeFromScope() {
// do nothing
}
};
assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped));
}
示例5: testThreadScope
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Test
public void testThreadScope() throws Exception {
// verify that set/get works in normal case
threadedService.setValue(VALUE_FIRST);
Assert.assertEquals(VALUE_FIRST, threadedService.getValue());
// assure bean is not treated as prototype
ThreadedService ts = applicationContext.getBean(BEAN_NAME, ThreadedService.class);
Assert.assertEquals(VALUE_FIRST, ts.getValue());
Thread thread = new Thread(new Runnable() {
public void run() {
// we are in the thread, now create the autowired class and test:
testInOtherThread();
}
});
thread.start();
thread.join();
// now verify that we can clear the thread data
Assert.assertEquals(VALUE_FIRST, threadedService.getValue());
((ScopedObject)threadedService).removeFromScope();
Assert.assertNull(threadedService.getValue());
}
示例6: unwrapIfNecessary
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
public static Object unwrapIfNecessary(Object resource) {
if (resource instanceof ScopedObject) {
return ((ScopedObject) resource).getTargetObject();
}
else {
return resource;
}
}
示例7: getEntityName
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Override
public String getEntityName(Object entity) {
if (entity instanceof ScopedObject) {
// Determine underlying object's type.
Object targetObject = ((ScopedObject) entity).getTargetObject();
return AopUtils.getTargetClass(targetObject).getName();
}
// Any other object: delegate to the default implementation.
return super.getEntityName(entity);
}
示例8: scopedProxyTargetMarkedAsNonAutowireCandidate
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Test
public void scopedProxyTargetMarkedAsNonAutowireCandidate() {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor(bpp);
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ScopedProxyConfigurationClass.class));
beanFactory.registerBeanDefinition("consumer", new RootBeanDefinition(ScopedProxyConsumer.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean;
assertTrue(injected instanceof ScopedObject);
assertSame(beanFactory.getBean("scopedClass"), injected);
assertSame(beanFactory.getBean(ITestBean.class), injected);
}
示例9: testRawScopes
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Test
public void testRawScopes() throws Exception {
String beanName = "scopedProxyInterface";
// get hidden bean
Object bean = ctx.getBean("scopedTarget." + beanName);
assertFalse(bean instanceof ScopedObject);
}
示例10: testScopedProxyConfiguration
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Test
public void testScopedProxyConfiguration() throws Exception {
TestBean singleton = (TestBean) ctx.getBean("singletonWithScopedInterfaceDep");
ITestBean spouse = singleton.getSpouse();
assertTrue("scoped bean is not wrapped by the scoped-proxy", spouse instanceof ScopedObject);
String beanName = "scopedProxyInterface";
String scopedBeanName = "scopedTarget." + beanName;
// get hidden bean
assertEquals(flag, spouse.getName());
ITestBean spouseFromBF = (ITestBean) ctx.getBean(scopedBeanName);
assertEquals(spouse.getName(), spouseFromBF.getName());
// the scope proxy has kicked in
assertNotSame(spouse, spouseFromBF);
// 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
assertSame(spouse.getName(), spouseFromBF.getName());
assertNotSame(spouse, spouseFromBF);
// get the bean again
spouseFromBF = (ITestBean) ctx.getBean(scopedBeanName);
assertSame(spouse.getName(), spouseFromBF.getName());
}
示例11: get
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
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;
}
示例12: testScopedProxyConfigurationWithClasses
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Test
public void testScopedProxyConfigurationWithClasses() throws Exception {
TestBean singleton = (TestBean) ctx.getBean("singletonWithScopedClassDep");
ITestBean spouse = singleton.getSpouse();
assertTrue("scoped bean is not wrapped by the scoped-proxy", spouse instanceof ScopedObject);
String beanName = "scopedProxyClass";
String scopedBeanName = "scopedTarget." + beanName;
// get hidden bean
assertEquals(flag, spouse.getName());
TestBean spouseFromBF = (TestBean) ctx.getBean(scopedBeanName);
assertEquals(spouse.getName(), spouseFromBF.getName());
// the scope proxy has kicked in
assertNotSame(spouse, spouseFromBF);
// 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
assertSame(spouse.getName(), spouseFromBF.getName());
assertNotSame(spouse, spouseFromBF);
// get the bean again
spouseFromBF = (TestBean) ctx.getBean(scopedBeanName);
assertSame(spouse.getName(), spouseFromBF.getName());
}
示例13: get
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
ExecutionEntity executionEntity = null;
try {
logger.debug("returning scoped object having beanName '{}' for conversation ID '{}'.", name, 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.debug("de-referencing {}#targetObject before persisting variable", ScopedObject.class.getName());
}
persistVariable(name, scopedObject);
}
return createDirtyCheckingProxy(name, scopedObject);
} catch (Throwable th) {
logger.warn("couldn't return value from process scope! {}", ExceptionUtils.getFullStackTrace(th));
} finally {
if (executionEntity != null) {
logger.debug("set variable '{}' on executionEntity#{}", name, executionEntity.getId());
}
}
return null;
}
示例14: isScopedObjectGetTargetObject
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
private boolean isScopedObjectGetTargetObject(Method method) {
return method.getDeclaringClass().equals(ScopedObject.class)
&& method.getName().equals("getTargetObject")
&& method.getParameterTypes().length == 0;
}
示例15: testSingletonScopedFactoryMethod
import org.springframework.aop.scope.ScopedObject; //导入依赖的package包/类
public void testSingletonScopedFactoryMethod() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
context.getBeanFactory().registerScope("request", new SimpleMapScope());
scanner.scan(BASE_PACKAGE);
context.registerBeanDefinition("clientBean", new RootBeanDefinition(QualifiedClientBean.class));
context.refresh();
FactoryMethodComponent fmc = context.getBean("factoryMethodComponent", FactoryMethodComponent.class);
assertFalse(fmc.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR));
TestBean tb = (TestBean)context.getBean("publicInstance"); //2
assertEquals("publicInstance", tb.getName());
TestBean tb2 = (TestBean)context.getBean("publicInstance"); //2
assertEquals("publicInstance", tb2.getName());
assertSame(tb2, tb);
tb = (TestBean)context.getBean("protectedInstance"); //3
assertEquals("protectedInstance", tb.getName());
assertSame(tb, context.getBean("protectedInstance"));
assertEquals("0", tb.getCountry());
tb2 = context.getBean("protectedInstance", TestBean.class); //3
assertEquals("protectedInstance", tb2.getName());
assertSame(tb2, tb);
tb = context.getBean("privateInstance", TestBean.class); //4
assertEquals("privateInstance", tb.getName());
assertEquals(1, tb.getAge());
tb2 = context.getBean("privateInstance", TestBean.class); //4
assertEquals(2, tb2.getAge());
assertNotSame(tb2, tb);
Object bean = context.getBean("requestScopedInstance"); //5
assertTrue(AopUtils.isCglibProxy(bean));
assertTrue(bean instanceof ScopedObject);
QualifiedClientBean clientBean = context.getBean("clientBean", QualifiedClientBean.class);
assertSame(clientBean.testBean, context.getBean("publicInstance"));
assertSame(clientBean.dependencyBean, context.getBean("dependencyBean"));
}