本文整理汇总了Java中org.aopalliance.aop.Advice类的典型用法代码示例。如果您正苦于以下问题:Java Advice类的具体用法?Java Advice怎么用?Java Advice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Advice类属于org.aopalliance.aop包,在下文中一共展示了Advice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:26,代码来源:PublishingServiceFactory.java
示例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));
}
}
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:AbstractServiceProxyCreator.java
示例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);
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:23,代码来源:OsgiServiceProxyEqualityTest.java
示例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);
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:20,代码来源:OsgiServiceProxyEqualityTest.java
示例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();
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:AspectJAwareAdvisorAutoProxyCreator.java
示例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;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:DeclareParentsAdvisor.java
示例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);
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:DefaultAdvisorAdapterRegistry.java
示例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()]);
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:DefaultAdvisorAdapterRegistry.java
示例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));
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:AdvisedSupport.java
示例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;
}
开发者ID:cadeeper,项目名称:my-spring,代码行数:24,代码来源:DefaultAdvisorAutoProxyCreator.java
示例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;
}
}
}
开发者ID:leiyong0326,项目名称:phone,代码行数:26,代码来源:AopProxyUtils.java
示例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;
}
开发者ID:leiyong0326,项目名称:phone,代码行数:26,代码来源:AopProxyUtils.java
示例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;
}
开发者ID:txazo,项目名称:spring,代码行数:24,代码来源:DeclareParentsAdvisor.java
示例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);
}
开发者ID:infobip,项目名称:infobip-bean-validation,代码行数:10,代码来源:CustomMethodValidationPostProcessor.java
示例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());
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:ServiceProxyTst.java
示例16: createCardinalityAdvice
import org.aopalliance.aop.Advice; //导入依赖的package包/类
private Advice createCardinalityAdvice(Class<?> clazz) {
ClassLoader classLoader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundleContext.getBundle());
ServiceDynamicInterceptor interceptor = new ServiceDynamicInterceptor(bundleContext, null,
OsgiFilterUtils.createFilter(OsgiFilterUtils.unifyFilter(clazz, null)), classLoader);
// fast retry
interceptor.setMandatoryService(true);
interceptor.afterPropertiesSet();
interceptor.getRetryTemplate().reset(1);
return interceptor;
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:ServiceProxyTst.java
示例17: createServiceProxy
import org.aopalliance.aop.Advice; //导入依赖的package包/类
public ProxyPlusCallback createServiceProxy(ServiceReference reference) {
List advices = new ArrayList(4);
// 1. the ServiceReference-like mixin
Advice mixin = new ImportedOsgiServiceProxyAdvice(reference);
advices.add(mixin);
// 2. publication of bundleContext (if there is any)
// TODO: make this configurable (so it can be disabled)
advices.add(invokerBundleContextAdvice);
// 3. TCCL handling (if there is any)
Advice tcclAdvice = determineTCCLAdvice(reference);
if (tcclAdvice != null)
advices.add(tcclAdvice);
// 4. add the infrastructure proxy
// but first create the dispatcher since we need
ServiceInvoker dispatcherInterceptor = createDispatcherInterceptor(reference);
Advice infrastructureMixin = new InfrastructureOsgiProxyAdvice(dispatcherInterceptor);
advices.add(infrastructureMixin);
advices.add(dispatcherInterceptor);
return new ProxyPlusCallback(ProxyUtils.createProxy(getInterfaces(reference), null, classLoader, bundleContext,
advices), dispatcherInterceptor);
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:29,代码来源:AbstractServiceProxyCreator.java
示例18: createServiceProviderTCCLAdvice
import org.aopalliance.aop.Advice; //导入依赖的package包/类
Advice createServiceProviderTCCLAdvice(ServiceReference reference) {
Bundle bundle = reference.getBundle();
// if reference is dead already, it's impossible to provide the service
// class loader
if (bundle == null)
return null;
return new ServiceTCCLInterceptor(ClassLoaderFactory.getBundleClassLoaderFor(bundle));
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:10,代码来源:StaticServiceProxyCreator.java
示例19: createProxy
import org.aopalliance.aop.Advice; //导入依赖的package包/类
public static Object createProxy(Class<?>[] classes, Object target, final ClassLoader classLoader,
BundleContext bundleContext, Advice[] advices) {
final ProxyFactory factory = new ProxyFactory();
ClassUtils.configureFactoryForClass(factory, classes);
for (int i = 0; i < advices.length; i++) {
factory.addAdvice(advices[i]);
}
if (target != null)
factory.setTarget(target);
// no need to add optimize since it means implicit usage of CGLib always
// which is determined automatically anyway
// factory.setOptimize(true);
factory.setFrozen(true);
factory.setOpaque(true);
boolean isSecurityOn = (System.getSecurityManager() != null);
try {
if (isSecurityOn) {
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
return factory.getProxy(classLoader);
}
});
} else {
return factory.getProxy(classLoader);
}
} catch (NoClassDefFoundError ncdfe) {
DebugUtils.debugClassLoadingThrowable(ncdfe, bundleContext.getBundle(), classes);
throw ncdfe;
}
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:36,代码来源:ProxyUtils.java
示例20: createProxy
import org.aopalliance.aop.Advice; //导入依赖的package包/类
private Object createProxy(Object target, Class<?> intf, Advice[] advices) {
ProxyFactory factory = new ProxyFactory();
factory.addInterface(intf);
if (advices != null)
for (int i = 0; i < advices.length; i++) {
factory.addAdvice(advices[0]);
}
factory.setTarget(target);
return factory.getProxy();
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:OsgiServiceProxyEqualityTest.java
注:本文中的org.aopalliance.aop.Advice类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论