本文整理汇总了Java中org.springframework.aop.support.DefaultIntroductionAdvisor类的典型用法代码示例。如果您正苦于以下问题:Java DefaultIntroductionAdvisor类的具体用法?Java DefaultIntroductionAdvisor怎么用?Java DefaultIntroductionAdvisor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultIntroductionAdvisor类属于org.springframework.aop.support包,在下文中一共展示了DefaultIntroductionAdvisor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Helper method to create a {@link PermissionCheckedValue} from an existing <code>Object</code>.
*
* @param object the <code>Object</code> to proxy
* @return a <code>Object</code> of the same type but including the
* {@link PermissionCheckedValue} interface
*/
@SuppressWarnings("unchecked")
public static final <T extends Object> T create(T object)
{
// Create the mixin
DelegatingIntroductionInterceptor mixin = new PermissionCheckedValueMixin();
// Create the advisor
IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckedValue.class);
// Proxy
ProxyFactory pf = new ProxyFactory(object);
pf.addAdvisor(advisor);
Object proxiedObject = pf.getProxy();
// Done
return (T) proxiedObject;
}
示例2: create
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Helper method to create a {@link PermissionCheckedCollection} from an existing <code>Collection</code>
*
* @param <TT> the type of the <code>Collection</code>
* @param collection the <code>Collection</code> to proxy
* @param isCutOff <tt>true</tt> if permission checking was cut off before completion
* @param sizeUnchecked number of entries from the original collection that were not checked
* @param sizeOriginal number of entries in the original, pre-checked collection
* @return a <code>Collection</code> of the same type but including the
* {@link PermissionCheckedCollection} interface
*/
@SuppressWarnings("unchecked")
public static final <TT> Collection<TT> create(
Collection<TT> collection,
boolean isCutOff, int sizeUnchecked, int sizeOriginal)
{
// Create the mixin
DelegatingIntroductionInterceptor mixin = new PermissionCheckedCollectionMixin<Integer>(
isCutOff,
sizeUnchecked,
sizeOriginal
);
// Create the advisor
IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckedCollection.class);
// Proxy
ProxyFactory pf = new ProxyFactory(collection);
pf.addAdvisor(advisor);
Object proxiedObject = pf.getProxy();
// Done
return (Collection<TT>) proxiedObject;
}
示例3: create
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Helper method to create a {@link PermissionCheckCollection} from an existing <code>Collection</code>
*
* @param <TT> the type of the <code>Collection</code>
* @param collection the <code>Collection</code> to proxy
* @param targetResultCount the desired number of results or default to the collection size
* @param cutOffAfterTimeMs the number of milliseconds to wait before cut-off or zero to use the system default
* time-based cut-off.
* @param cutOffAfterCount the number of permission checks to process before cut-off or zero to use the system default
* count-based cut-off.
* @return a <code>Collection</code> of the same type but including the
* {@link PermissionCheckCollection} interface
*/
@SuppressWarnings("unchecked")
public static final <TT> Collection<TT> create(
Collection<TT> collection,
int targetResultCount, long cutOffAfterTimeMs, int cutOffAfterCount)
{
if (targetResultCount <= 0)
{
targetResultCount = collection.size();
}
// Create the mixin
DelegatingIntroductionInterceptor mixin = new PermissionCheckCollectionMixin<Integer>(
targetResultCount,
cutOffAfterTimeMs,
cutOffAfterCount);
// Create the advisor
IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckCollection.class);
// Proxy
ProxyFactory pf = new ProxyFactory(collection);
pf.addAdvisor(advisor);
Object proxiedObject = pf.getProxy();
// Done
return (Collection<TT>) proxiedObject;
}
示例4: addAdvice
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Cannot add introductions this way unless the advice implements IntroductionInfo.
*/
@Override
public void addAdvice(int pos, Advice advice) throws AopConfigException {
Assert.notNull(advice, "Advice must not be null");
if (advice instanceof IntroductionInfo) {
// We don't need an IntroductionAdvisor for this kind of introduction:
// It's fully self-describing.
addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice));
}
else if (advice instanceof DynamicIntroductionAdvice) {
// We need an IntroductionAdvisor for this kind of introduction.
throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor");
}
else {
addAdvisor(pos, new DefaultPointcutAdvisor(advice));
}
}
示例5: DynamicAsyncInterfaceBean
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
public DynamicAsyncInterfaceBean() {
ProxyFactory pf = new ProxyFactory(new HashMap<>());
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
if (Future.class.equals(invocation.getMethod().getReturnType())) {
return new AsyncResult<String>(invocation.getArguments()[0].toString());
}
return null;
}
});
advisor.addInterface(AsyncInterface.class);
pf.addAdvisor(advisor);
this.proxy = (AsyncInterface) pf.getProxy();
}
示例6: DynamicAsyncMethodsInterfaceBean
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
public DynamicAsyncMethodsInterfaceBean() {
ProxyFactory pf = new ProxyFactory(new HashMap<>());
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
if (Future.class.equals(invocation.getMethod().getReturnType())) {
return new AsyncResult<String>(invocation.getArguments()[0].toString());
}
return null;
}
});
advisor.addInterface(AsyncMethodsInterface.class);
pf.addAdvisor(advisor);
this.proxy = (AsyncMethodsInterface) pf.getProxy();
}
示例7: testRejectsBogusDynamicIntroductionAdviceWithNoAdapter
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
@Test
public void testRejectsBogusDynamicIntroductionAdviceWithNoAdapter() throws Throwable {
TestBean target = new TestBean();
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
pc.addAdvisor(new DefaultIntroductionAdvisor(new DummyIntroductionAdviceImpl(), Comparable.class));
try {
// TODO May fail on either call: may want to tighten up definition
ITestBean proxied = (ITestBean) createProxy(pc);
proxied.getName();
fail("Bogus introduction");
}
catch (Exception ex) {
// TODO used to catch UnknownAdviceTypeException, but
// with CGLIB some errors are in proxy creation and are wrapped
// in aspect exception. Error message is still fine.
//assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
}
}
示例8: testCannotAddIntroductionAdviceWithUnimplementedInterface
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Check that the introduction advice isn't allowed to introduce interfaces
* that are unsupported by the IntroductionInterceptor.
*/
@Test
public void testCannotAddIntroductionAdviceWithUnimplementedInterface() throws Throwable {
TestBean target = new TestBean();
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
try {
pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), ITestBean.class));
fail("Shouldn't be able to add introduction advice introducing an unimplemented interface");
}
catch (IllegalArgumentException ex) {
//assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
}
// Check it still works: proxy factory state shouldn't have been corrupted
ITestBean proxied = (ITestBean) createProxy(pc);
assertEquals(target.getAge(), proxied.getAge());
}
示例9: testCannotAddIntroductionAdviceToIntroduceClass
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Should only be able to introduce interfaces, not classes.
*/
@Test
public void testCannotAddIntroductionAdviceToIntroduceClass() throws Throwable {
TestBean target = new TestBean();
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
try {
pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), TestBean.class));
fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface");
}
catch (IllegalArgumentException ex) {
assertTrue(ex.getMessage().indexOf("interface") > -1);
}
// Check it still works: proxy factory state shouldn't have been corrupted
ITestBean proxied = (ITestBean) createProxy(pc);
assertEquals(target.getAge(), proxied.getAge());
}
示例10: testUseAsHashKey
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
@Test
public void testUseAsHashKey() {
TestBean target1 = new TestBean();
ProxyFactory pf1 = new ProxyFactory(target1);
pf1.addAdvice(new NopInterceptor());
ITestBean proxy1 = (ITestBean) createProxy(pf1);
TestBean target2 = new TestBean();
ProxyFactory pf2 = new ProxyFactory(target2);
pf2.addAdvisor(new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor()));
ITestBean proxy2 = (ITestBean) createProxy(pf2);
HashMap<ITestBean, Object> h = new HashMap<ITestBean, Object>();
Object value1 = "foo";
Object value2 = "bar";
assertNull(h.get(proxy1));
h.put(proxy1, value1);
h.put(proxy2, value2);
assertEquals(h.get(proxy1), value1);
assertEquals(h.get(proxy2), value2);
}
示例11: addAdvice
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Cannot add introductions this way unless the advice implements IntroductionInfo.
*/
public void addAdvice(int pos, Advice advice) throws AopConfigException {
Assert.notNull(advice, "Advice must not be null");
if (advice instanceof IntroductionInfo) {
// We don't need an IntroductionAdvisor for this kind of introduction:
// It's fully self-describing.
addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice));
}
else if (advice instanceof DynamicIntroductionAdvice) {
// We need an IntroductionAdvisor for this kind of introduction.
throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor");
}
else {
addAdvisor(pos, new DefaultPointcutAdvisor(advice));
}
}
示例12: testGetsAllInterfaces
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
@Test
public void testGetsAllInterfaces() throws Exception {
// Extend to get new interface
class TestBeanSubclass extends TestBean implements Comparable<Object> {
@Override
public int compareTo(Object arg0) {
throw new UnsupportedOperationException("compareTo");
}
}
TestBeanSubclass raw = new TestBeanSubclass();
ProxyFactory factory = new ProxyFactory(raw);
//System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
assertEquals("Found correct number of interfaces", 5, factory.getProxiedInterfaces().length);
ITestBean tb = (ITestBean) factory.getProxy();
assertThat("Picked up secondary interface", tb, instanceOf(IOther.class));
raw.setAge(25);
assertTrue(tb.getAge() == raw.getAge());
long t = 555555L;
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
assertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);
TimeStamped ts = (TimeStamped) factory.getProxy();
assertTrue(ts.getTimeStamp() == t);
// Shouldn't fail;
((IOther) ts).absquatulate();
}
示例13: testIntroductionThrowsUncheckedException
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Note that an introduction can't throw an unexpected checked exception,
* as it's constained by the interface.
*/
@Test
public void testIntroductionThrowsUncheckedException() throws Throwable {
TestBean target = new TestBean();
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
@SuppressWarnings("serial")
class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped {
/**
* @see test.util.TimeStamped#getTimeStamp()
*/
@Override
public long getTimeStamp() {
throw new UnsupportedOperationException();
}
}
pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi()));
TimeStamped ts = (TimeStamped) createProxy(pc);
try {
ts.getTimeStamp();
fail("Should throw UnsupportedOperationException");
}
catch (UnsupportedOperationException ex) {
}
}
示例14: getPoolingConfigMixin
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Return an IntroductionAdvisor that providing a mixin
* exposing statistics about the pool maintained by this object.
*/
public DefaultIntroductionAdvisor getPoolingConfigMixin() {
DelegatingIntroductionInterceptor dii = new DelegatingIntroductionInterceptor(this);
return new DefaultIntroductionAdvisor(dii, PoolingConfig.class);
}
示例15: getStatsMixin
import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
* Return an introduction advisor mixin that allows the AOP proxy to be
* cast to ThreadLocalInvokerStats.
*/
public IntroductionAdvisor getStatsMixin() {
DelegatingIntroductionInterceptor dii = new DelegatingIntroductionInterceptor(this);
return new DefaultIntroductionAdvisor(dii, ThreadLocalTargetSourceStats.class);
}