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


Java AopUtils类代码示例

本文整理汇总了Java中org.springframework.aop.support.AopUtils的典型用法代码示例。如果您正苦于以下问题:Java AopUtils类的具体用法?Java AopUtils怎么用?Java AopUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AopUtils类属于org.springframework.aop.support包,在下文中一共展示了AopUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postProcessAfterInitialization

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * The method scans all beans, that contain methods,
 * annotated as {@link ScheduledBeanMethod}
 */
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    Class<?> targetClass = AopUtils.getTargetClass(bean);

    Map<Method, Set<ScheduledBeanMethod>> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<Set<ScheduledBeanMethod>>) method -> {
                Set<ScheduledBeanMethod> scheduledMethods = AnnotatedElementUtils.getMergedRepeatableAnnotations(
                        method, ScheduledBeanMethod.class, ScheduledBeanMethods.class);
                return (!scheduledMethods.isEmpty() ? scheduledMethods : null);
            });

    for (Map.Entry<Method, Set<ScheduledBeanMethod>> entry : annotatedMethods.entrySet()) {
        scheduleAnnotatedMethods.add(new ScheduledMethodContext(beanName, entry.getKey(), entry.getValue()));
    }

    return bean;
}
 
开发者ID:aleksey-stukalov,项目名称:cuba-scheduler-annotation,代码行数:22,代码来源:ScheduledTaskLoader.java

示例2: getTargetObject

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
private static Object getTargetObject(Object proxy) {
	try {
		if (!AopUtils.isAopProxy(proxy)) {// 不是代理对象
			return proxy;
		}
		if (AopUtils.isCglibProxy(proxy)) {// cglib代理对象
			return getCglibProxyTargetObject(proxy);
		}
		if (AopUtils.isJdkDynamicProxy(proxy)) {// jdk动态代理
			return getJdkDynamicProxyTargetObject(proxy);
		}
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
	return null;
}
 
开发者ID:swxiao,项目名称:bubble2,代码行数:17,代码来源:BeanContextUtil.java

示例3: isMatchPackage

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
private boolean isMatchPackage(Object bean) {
    if (annotationPackages == null || annotationPackages.length == 0) {
        return true;
    }
    Class clazz = bean.getClass();
    if(isProxyBean(bean)){
        clazz = AopUtils.getTargetClass(bean);
    }
    String beanClassName = clazz.getName();
    for (String pkg : annotationPackages) {
        if (beanClassName.startsWith(pkg)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:17,代码来源:AnnotationBean.java

示例4: adaptMBeanIfPossible

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * Build an adapted MBean for the given bean instance, if possible.
 * <p>The default implementation builds a JMX 1.2 StandardMBean
 * for the target's MBean/MXBean interface in case of an AOP proxy,
 * delegating the interface's management operations to the proxy.
 * @param bean the original bean instance
 * @return the adapted MBean, or {@code null} if not possible
 */
@SuppressWarnings("unchecked")
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
	Class<?> targetClass = AopUtils.getTargetClass(bean);
	if (targetClass != bean.getClass()) {
		Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
		if (ifc != null) {
			if (!ifc.isInstance(bean)) {
				throw new NotCompliantMBeanException("Managed bean [" + bean +
						"] has a target class with an MXBean interface but does not expose it in the proxy");
			}
			return new StandardMBean(bean, ((Class<Object>) ifc), true);
		}
		else {
			ifc = JmxUtils.getMBeanInterface(targetClass);
			if (ifc != null) {
				if (!ifc.isInstance(bean)) {
					throw new NotCompliantMBeanException("Managed bean [" + bean +
							"] has a target class with an MBean interface but does not expose it in the proxy");
				}
				return new StandardMBean(bean, ((Class<Object>) ifc));
			}
		}
	}
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:MBeanExporter.java

示例5: getObjectName

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * Reads the {@code ObjectName} from the source-level metadata associated
 * with the managed resource's {@code Class}.
 */
@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
	Class<?> managedClass = AopUtils.getTargetClass(managedBean);
	ManagedResource mr = this.attributeSource.getManagedResource(managedClass);

	// Check that an object name has been specified.
	if (mr != null && StringUtils.hasText(mr.getObjectName())) {
		return ObjectNameManager.getInstance(mr.getObjectName());
	}
	else {
		try {
			return ObjectNameManager.getInstance(beanKey);
		}
		catch (MalformedObjectNameException ex) {
			String domain = this.defaultDomain;
			if (domain == null) {
				domain = ClassUtils.getPackageName(managedClass);
			}
			Hashtable<String, String> properties = new Hashtable<String, String>();
			properties.put("type", ClassUtils.getShortName(managedClass));
			properties.put("name", beanKey);
			return ObjectNameManager.getInstance(domain, properties);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:MetadataNamingStrategy.java

示例6: findDefinedEqualsAndHashCodeMethods

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * Finds any {@link #equals} or {@link #hashCode} method that may be defined
 * on the supplied set of interfaces.
 * @param proxiedInterfaces the interfaces to introspect
 */
private void findDefinedEqualsAndHashCodeMethods(Class<?>[] proxiedInterfaces) {
	for (Class<?> proxiedInterface : proxiedInterfaces) {
		Method[] methods = proxiedInterface.getDeclaredMethods();
		for (Method method : methods) {
			if (AopUtils.isEqualsMethod(method)) {
				this.equalsDefined = true;
			}
			if (AopUtils.isHashCodeMethod(method)) {
				this.hashCodeDefined = true;
			}
			if (this.equalsDefined && this.hashCodeDefined) {
				return;
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:JdkDynamicAopProxy.java

示例7: ultimateTargetClass

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * Determine the ultimate target class of the given bean instance, traversing
 * not only a top-level proxy but any number of nested proxies as well -
 * as long as possible without side effects, that is, just for singleton targets.
 * @param candidate the instance to check (might be an AOP proxy)
 * @return the target class (or the plain class of the given object as fallback;
 * never {@code null})
 * @see org.springframework.aop.TargetClassAware#getTargetClass()
 * @see Advised#getTargetSource()
 */
public static Class<?> ultimateTargetClass(Object candidate) {
	Assert.notNull(candidate, "Candidate object must not be null");
	Object current = candidate;
	Class<?> result = null;
	while (current instanceof TargetClassAware) {
		result = ((TargetClassAware) current).getTargetClass();
		Object nested = null;
		if (current instanceof Advised) {
			TargetSource targetSource = ((Advised) current).getTargetSource();
			if (targetSource instanceof SingletonTargetSource) {
				nested = ((SingletonTargetSource) targetSource).getTarget();
			}
		}
		current = nested;
	}
	if (result == null) {
		result = (AopUtils.isCglibProxy(candidate) ? candidate.getClass().getSuperclass() : candidate.getClass());
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:AopProxyUtils.java

示例8: parseFlowTx

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * 解析流程事务
 *
 * @param flowTx             流程事务
 * @param transactionManager 事务管理器
 * @return 流程事务执行器
 */
public static FlowTxExecutor parseFlowTx(Object flowTx, PlatformTransactionManager transactionManager) {
    // 获取目标class(应对AOP代理情况)
    Class<?> flowTxClass = AopUtils.getTargetClass(flowTx);
    logger.debug("解析流程事务:{}", ClassUtils.getQualifiedName(flowTxClass));
    FlowTx flowTxAnnotation = flowTxClass.getAnnotation(FlowTx.class);
    // 创建流程事务执行器
    FlowTxExecutor flowTxExecutor = new FlowTxExecutor(flowTxAnnotation.flow(), flowTx, transactionManager);
    for (Method method : flowTxClass.getDeclaredMethods()) {
        for (Class clazz : FlowTxExecutor.FLOW_TX_OPERATE_ANNOTATIONS) {
            if (method.isAnnotationPresent(clazz)) {
                // 设置流程事务操作执行器
                flowTxExecutor.setOperateExecutor(clazz, parseFlowTxOperate(method));
                break;
            }
        }
    }
    flowTxExecutor.validate();

    return flowTxExecutor;
}
 
开发者ID:zhongxunking,项目名称:bekit,代码行数:28,代码来源:FlowTxParser.java

示例9: parseProcessor

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * 解析处理器
 *
 * @param processor 处理器
 * @return 处理器执行器
 */
public static ProcessorExecutor parseProcessor(Object processor) {
    // 获取目标class(应对AOP代理情况)
    Class<?> processorClass = AopUtils.getTargetClass(processor);
    logger.debug("解析处理器:{}", ClassUtils.getQualifiedName(processorClass));
    // 获取处理器名称
    String processorName = processorClass.getAnnotation(Processor.class).name();
    if (StringUtils.isEmpty(processorName)) {
        processorName = ClassUtils.getShortNameAsProperty(processorClass);
    }
    // 创建处理器执行器
    ProcessorExecutor processorExecutor = new ProcessorExecutor(processorName, processor);
    for (Method method : processorClass.getDeclaredMethods()) {
        for (Class clazz : ProcessorExecutor.PROCESSOR_METHOD_ANNOTATIONS) {
            if (method.isAnnotationPresent(clazz)) {
                // 设置处理器方法执行器
                processorExecutor.setMethodExecutor(clazz, parseProcessorMethod(clazz, method));
                break;
            }
        }
    }
    processorExecutor.validate();

    return processorExecutor;
}
 
开发者ID:zhongxunking,项目名称:bekit,代码行数:31,代码来源:ProcessorParser.java

示例10: parseListener

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * 解析监听器
 *
 * @param listener 监听器
 * @return 监听器执行器
 */
public static ListenerExecutor parseListener(Object listener) {
    // 获取目标class(应对AOP代理情况)
    Class<?> listenerClass = AopUtils.getTargetClass(listener);
    logger.debug("解析监听器:{}", ClassUtils.getQualifiedName(listenerClass));
    // 此处得到的@Listener是已经经过@AliasFor属性别名进行属性同步后的结果
    Listener listenerAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenerClass, Listener.class);
    // 创建监听器执行器
    ListenerExecutor listenerExecutor = new ListenerExecutor(listener, listenerAnnotation.type(), listenerAnnotation.priority(), parseEventTypeResolver(listenerAnnotation.type()));
    for (Method method : listenerClass.getDeclaredMethods()) {
        Listen listenAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, Listen.class);
        if (listenAnnotation != null) {
            ListenExecutor listenExecutor = parseListen(listenAnnotation, method);
            listenerExecutor.addListenExecutor(listenExecutor);
        }
    }
    listenerExecutor.validate();

    return listenerExecutor;
}
 
开发者ID:zhongxunking,项目名称:bekit,代码行数:26,代码来源:ListenerParser.java

示例11: getCglibProxyTargetObject

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
private static Object getCglibProxyTargetObject(Object proxy) throws Exception {
	Field field = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0");
       field.setAccessible(true);
       Object dynamicAdvisedInterceptor = field.get(proxy);
       
       Field advised = dynamicAdvisedInterceptor.getClass().getDeclaredField("advised");
       advised.setAccessible(true);
       
       Object target = ((AdvisedSupport)advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget();

       if(!AopUtils.isAopProxy(target)){
		throw new EndRecursionException(target);
	}
	getCglibProxyTargetObject(target);
       return null;
}
 
开发者ID:Yanweichen,项目名称:SimpleProcessControl,代码行数:17,代码来源:AopTargetUtils.java

示例12: afterPropertiesSet

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * Is called by the Spring container after all properties have been set. <br>
 * It is implemented in order to initialize the beanClass field correctly and to make sure
 * that either the bean id or the bean itself have been set on this creator.
 * @see org.springframework.beans.factory.InitializingBean
 */
public void afterPropertiesSet()
{
    // make sure that either the bean or the beanId have been set correctly
    if (bean != null) {
        this.beanClass = bean.getClass();
    } else if (beanId != null) {
        this.beanClass = applicationContext.getType(beanId);
    } else {
        throw new FatalBeanException(
                "You should either set the bean property directly or set the beanId property");
    }

    // make sure to handle cglib proxies correctly
    if(AopUtils.isCglibProxyClass(this.beanClass)) {
        this.beanClass = this.beanClass.getSuperclass();
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:BeanCreator.java

示例13: postProcessAfterInitialization

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	try {
		Class<?> wrapped = AopUtils.getTargetClass(bean);
		if (!isSpring(wrapped)) {
			Class<?> declaring = AnnotationUtils.findAnnotationDeclaringClass(Steps.class, wrapped);
			if (null != declaring) {
				processStepsBean(beanName, wrapped);
			}
		}
		return bean;
	}
	catch (Exception e) {
		throw new FatalBeanException("unable to processAnnotationContainer @Steps beans", e);
	}
}
 
开发者ID:qas-guru,项目名称:martini-core,代码行数:17,代码来源:StepsAnnotationProcessor.java

示例14: support

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
public boolean support(Class<?> objectClass, Method method) {
	if (ContextHolder.getLoginUser() == null || appList.size() == 0) {
		return false;
	}
	String key = objectClass.getName() + "#" + method.getName();
	String value = parameterCache.get(key);
	if (StringUtils.isNotEmpty(value)) {
		return true;
	} else {
		for (String property : methodInterceptorList) {
			String[] propertyArray = property.split("#");
			if (propertyArray.length == 2) {
				Object object = applicationContext.getBean(propertyArray[0]);
				String tempKey = AopUtils.getTargetClass(object).getName() + "#" + propertyArray[1];
				if (key.equals(tempKey)) {
					parameterCache.put(key, property);
					return true;
				}
			}
		}
	}
	return false;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:24,代码来源:RefreshCacheMethodInterceptor.java

示例15: buildScheduledRunnable

import org.springframework.aop.support.AopUtils; //导入依赖的package包/类
/**
 * 封装ScheduledMethodRunnable对象
 */
private static ScheduledMethodRunnable buildScheduledRunnable(Object bean, String targetMethod, String params, String extKeySuffix, boolean onlyOne) throws Exception {

    Assert.notNull(bean, "target object must not be null");
    Assert.hasLength(targetMethod, "Method name must not be empty");

    Method method;
    ScheduledMethodRunnable scheduledMethodRunnable;
    Class<?> clazz;
    if (AopUtils.isAopProxy(bean)) {
        clazz = AopProxyUtils.ultimateTargetClass(bean);
    } else {
        clazz = bean.getClass();
    }
    if (params != null) {
        method = ReflectionUtils.findMethod(clazz, targetMethod, String.class);
    } else {
        method = ReflectionUtils.findMethod(clazz, targetMethod);
    }
    Assert.notNull(method, "can not find method named " + targetMethod);
    scheduledMethodRunnable = new ScheduledMethodRunnable(bean, method, params, extKeySuffix, onlyOne);
    return scheduledMethodRunnable;
}
 
开发者ID:liuht777,项目名称:uncode-scheduler,代码行数:26,代码来源:DynamicTaskManager.java


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