本文整理匯總了Java中org.aopalliance.aop.Advice類的典型用法代碼示例。如果您正苦於以下問題:Java Advice類的具體用法?Java Advice怎麽用?Java Advice使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Advice類屬於org.aopalliance.aop包,在下文中一共展示了Advice類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCLLProxy
import org.aopalliance.aop.Advice; //導入依賴的package包/類
/**
* Proxy the target object with an interceptor that manages the context classloader. This should be applied only if
* such management is needed. Additionally, this method uses a cache to prevent multiple proxies to be created for
* the same object.
*
* @param target
* @return
*/
private Object createCLLProxy(final Object target) {
try {
return ProxyUtils.createProxy(classes, target, aopClassLoader, bundleContext,
new Advice[] { new ServiceTCCLInterceptor(classLoader) });
} catch (Throwable th) {
log.error("Cannot create TCCL managed proxy; falling back to the naked object", th);
if (th instanceof NoClassDefFoundError) {
NoClassDefFoundError ncdfe = (NoClassDefFoundError) th;
if (log.isWarnEnabled()) {
DebugUtils.debugClassLoadingThrowable(ncdfe, bundleContext.getBundle(), classes);
}
throw ncdfe;
}
}
return target;
}
示例2: determineTCCLAdvice
import org.aopalliance.aop.Advice; //導入依賴的package包/類
private Advice determineTCCLAdvice(ServiceReference reference) {
try {
switch (iccl) {
case CLIENT:
return clientTCCLAdvice;
case SERVICE_PROVIDER:
return createServiceProviderTCCLAdvice(reference);
case UNMANAGED:
// do nothing
return null;
default:
return null;
}
} finally {
if (log.isTraceEnabled()) {
log.trace(iccl + " TCCL used for invoking " + OsgiStringUtils.nullSafeToString(reference));
}
}
}
示例3: testMultipleInterceptorEquality
import org.aopalliance.aop.Advice; //導入依賴的package包/類
public void testMultipleInterceptorEquality() throws Exception {
target = new Polygon();
Advice interceptorA1 = createInterceptorWOServiceRequired();
Advice interceptorA2 = new LocalBundleContextAdvice(bundleContext);
Advice interceptorA3 = new ServiceTCCLInterceptor(null);
Advice interceptorB1 = createInterceptorWOServiceRequired();
Advice interceptorB2 = new LocalBundleContextAdvice(bundleContext);
Advice interceptorB3 = new ServiceTCCLInterceptor(null);
Object proxyA = createProxy(target, Shape.class, new Advice[] { interceptorA1, interceptorA2, interceptorA3 });
Object proxyB = createProxy(target, Shape.class, new Advice[] { interceptorB1, interceptorB2, interceptorB3 });
assertFalse(proxyA == proxyB);
assertEquals(interceptorA1, interceptorB1);
assertEquals(interceptorA2, interceptorB2);
assertEquals(interceptorA3, interceptorB3);
assertEquals(proxyA, proxyB);
}
示例4: testDifferentProxySetupButTargetHasEquals
import org.aopalliance.aop.Advice; //導入依賴的package包/類
public void testDifferentProxySetupButTargetHasEquals() throws Exception {
target = new Implementor();
Advice interceptorA1 = new LocalBundleContextAdvice(bundleContext);
Advice interceptorB1 = new ServiceTCCLInterceptor(null);
InterfaceWithEquals proxyA = (InterfaceWithEquals) createProxy(target, InterfaceWithEquals.class,
new Advice[] { interceptorA1 });
InterfaceWithEquals proxyB = (InterfaceWithEquals) createProxy(target, InterfaceWithEquals.class,
new Advice[] { interceptorB1 });
assertFalse(proxyA == proxyB);
assertFalse("interceptors should not be equal", interceptorA1.equals(interceptorB1));
assertEquals(((InterfaceWithEquals) target).doSmth(), proxyA.doSmth());
assertEquals(((InterfaceWithEquals) target).doSmth(), proxyB.doSmth());
assertEquals(proxyA, proxyB);
}
示例5: toString
import org.aopalliance.aop.Advice; //導入依賴的package包/類
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Advice advice = this.advisor.getAdvice();
sb.append(ClassUtils.getShortName(advice.getClass()));
sb.append(": ");
if (this.advisor instanceof Ordered) {
sb.append("order ").append(((Ordered) this.advisor).getOrder()).append(", ");
}
if (advice instanceof AbstractAspectJAdvice) {
AbstractAspectJAdvice ajAdvice = (AbstractAspectJAdvice) advice;
sb.append(ajAdvice.getAspectName());
sb.append(", declaration order ");
sb.append(ajAdvice.getDeclarationOrder());
}
return sb.toString();
}
示例6: DeclareParentsAdvisor
import org.aopalliance.aop.Advice; //導入依賴的package包/類
/**
* Private constructor to share common code between impl-based delegate and reference-based delegate
* (cannot use method such as init() to share common code, due the the use of final fields)
* @param interfaceType static field defining the introduction
* @param typePattern type pattern the introduction is restricted to
* @param implementationClass implementation class
* @param advice delegation advice
*/
private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> implementationClass, Advice advice) {
this.introducedInterface = interfaceType;
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern);
// Excludes methods implemented.
ClassFilter exclusion = new ClassFilter() {
@Override
public boolean matches(Class<?> clazz) {
return !(introducedInterface.isAssignableFrom(clazz));
}
};
this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion);
this.advice = advice;
}
示例7: wrap
import org.aopalliance.aop.Advice; //導入依賴的package包/類
@Override
public Advisor wrap(Object adviceObject) throws UnknownAdviceTypeException {
if (adviceObject instanceof Advisor) {
return (Advisor) adviceObject;
}
if (!(adviceObject instanceof Advice)) {
throw new UnknownAdviceTypeException(adviceObject);
}
Advice advice = (Advice) adviceObject;
if (advice instanceof MethodInterceptor) {
// So well-known it doesn't even need an adapter.
return new DefaultPointcutAdvisor(advice);
}
for (AdvisorAdapter adapter : this.adapters) {
// Check that it is supported.
if (adapter.supportsAdvice(advice)) {
return new DefaultPointcutAdvisor(advice);
}
}
throw new UnknownAdviceTypeException(advice);
}
示例8: getInterceptors
import org.aopalliance.aop.Advice; //導入依賴的package包/類
@Override
public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException {
List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(3);
Advice advice = advisor.getAdvice();
if (advice instanceof MethodInterceptor) {
interceptors.add((MethodInterceptor) advice);
}
for (AdvisorAdapter adapter : this.adapters) {
if (adapter.supportsAdvice(advice)) {
interceptors.add(adapter.getInterceptor(advisor));
}
}
if (interceptors.isEmpty()) {
throw new UnknownAdviceTypeException(advisor.getAdvice());
}
return interceptors.toArray(new MethodInterceptor[interceptors.size()]);
}
示例9: addAdvice
import org.aopalliance.aop.Advice; //導入依賴的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));
}
}
示例10: postProcessAfterInitialization
import org.aopalliance.aop.Advice; //導入依賴的package包/類
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws Exception {
if (Advice.class.isAssignableFrom(bean.getClass()) || Pointcut.class.isAssignableFrom(bean.getClass())
|| Advisor.class.isAssignableFrom(bean.getClass())
|| MethodInterceptor.class.isAssignableFrom(bean.getClass())) {
return bean;
}
List<DefaultPointcutAdvisor> defaultPointcutAdvisors = beanFactory
.getBeansForType(DefaultPointcutAdvisor.class);
for (DefaultPointcutAdvisor advisor : defaultPointcutAdvisors) {
if (advisor.getPointcut().getClassFilter().matches(bean.getClass())) {
ProxyFactory advisedSupport = new ProxyFactory();
advisedSupport.setMethodInterceptor((MethodInterceptor) advisor.getAdvice());
advisedSupport.setMethodMatcher(advisor.getPointcut().getmethodMatcher());
advisedSupport
.setTargetSource(new TargetSource(bean.getClass(), bean.getClass().getInterfaces(), bean));
return advisedSupport.getProxy();
}
}
return null;
}
示例11: removeAdvisor
import org.aopalliance.aop.Advice; //導入依賴的package包/類
private static void removeAdvisor(Object proxy, Class<? extends Advice> adviceClass) {
if(!AopUtils.isAopProxy(proxy)) {
return;
}
ProxyFactory proxyFactory = null;
if(AopUtils.isJdkDynamicProxy(proxy)) {
proxyFactory = findJdkDynamicProxyFactory(proxy);
}
if(AopUtils.isCglibProxy(proxy)) {
proxyFactory = findCglibProxyFactory(proxy);
}
Advisor[] advisors = proxyFactory.getAdvisors();
if(advisors == null || advisors.length == 0) {
return;
}
for(Advisor advisor : advisors) {
if(adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
proxyFactory.removeAdvisor(advisor);
break;
}
}
}
示例12: hasAdvice
import org.aopalliance.aop.Advice; //導入依賴的package包/類
private static boolean hasAdvice(Object proxy, Class<? extends Advice> adviceClass) {
if(!AopUtils.isAopProxy(proxy)) {
return false;
}
ProxyFactory proxyFactory = null;
if(AopUtils.isJdkDynamicProxy(proxy)) {
proxyFactory = findJdkDynamicProxyFactory(proxy);
}
if(AopUtils.isCglibProxy(proxy)) {
proxyFactory = findCglibProxyFactory(proxy);
}
Advisor[] advisors = proxyFactory.getAdvisors();
if(advisors == null || advisors.length == 0) {
return false;
}
for(Advisor advisor : advisors) {
if(adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
return true;
}
}
return false;
}
示例13: DeclareParentsAdvisor
import org.aopalliance.aop.Advice; //導入依賴的package包/類
/**
* Private constructor to share common code between impl-based delegate and reference-based delegate
* (cannot use method such as init() to share common code, due the use of final fields)
* @param interfaceType static field defining the introduction
* @param typePattern type pattern the introduction is restricted to
* @param implementationClass implementation class
* @param advice delegation advice
*/
private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> implementationClass, Advice advice) {
this.introducedInterface = interfaceType;
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern);
// Excludes methods implemented.
ClassFilter exclusion = new ClassFilter() {
@Override
public boolean matches(Class<?> clazz) {
return !(introducedInterface.isAssignableFrom(clazz));
}
};
this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion);
this.advice = advice;
}
示例14: createMethodValidationAdvice
import org.aopalliance.aop.Advice; //導入依賴的package包/類
@Override
protected Advice createMethodValidationAdvice(Validator validator) {
if (validator == null) {
return new CustomMethodValidationInterceptor(constraintViolationExceptionMapper);
}
return new CustomMethodValidationInterceptor(validator, constraintViolationExceptionMapper);
}
示例15: createProxy
import org.aopalliance.aop.Advice; //導入依賴的package包/類
private Object createProxy(final Class<?> clazz, Advice cardinalityInterceptor) {
ProxyFactory factory = new ProxyFactory();
factory.setProxyTargetClass(true);
factory.setOptimize(true);
factory.setTargetClass(clazz);
factory.addAdvice(cardinalityInterceptor);
factory.setFrozen(true);
return factory.getProxy(ProxyFactory.class.getClassLoader());
}