当前位置: 首页>>代码示例>>Java>>正文


Java Advice类代码示例

本文整理汇总了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;
}
 
开发者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


注:本文中的org.aopalliance.aop.Advice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。