當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。