當前位置: 首頁>>代碼示例>>Java>>正文


Java AopUtils.getTargetClass方法代碼示例

本文整理匯總了Java中org.springframework.aop.support.AopUtils.getTargetClass方法的典型用法代碼示例。如果您正苦於以下問題:Java AopUtils.getTargetClass方法的具體用法?Java AopUtils.getTargetClass怎麽用?Java AopUtils.getTargetClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.aop.support.AopUtils的用法示例。


在下文中一共展示了AopUtils.getTargetClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: findAnnotation

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
SchedulerLock findAnnotation(ScheduledMethodRunnable task) {
    Method method = task.getMethod();
    SchedulerLock annotation = findAnnotation(method);
    if (annotation != null) {
        return annotation;
    } else {
        // Try to find annotation on proxied class
        Class<?> targetClass = AopUtils.getTargetClass(task.getTarget());
        if (targetClass != null && !task.getTarget().getClass().equals(targetClass)) {
            try {
                Method methodOnTarget = targetClass
                    .getMethod(method.getName(), method.getParameterTypes());
                return findAnnotation(methodOnTarget);
            } catch (NoSuchMethodException e) {
                return null;
            }
        } else {
            return null;
        }
    }
}
 
開發者ID:lukas-krecan,項目名稱:ShedLock,代碼行數:22,代碼來源:SpringLockConfigurationExtractor.java

示例8: newJob

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Override
public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) throws SchedulerException {
    Preconditions.checkNotNull(applicationContext, "applicationContext cannot be null, should call setApplicationContext first.");
    Job job = null;
    try {
        for (Job each : applicationContext.getBeansOfType(Job.class).values()) {
            if (AopUtils.getTargetClass(each) == bundle.getJobDetail().getJobClass()) {
                job = each;
                break;
            }
        }
        if (null == job) {
            throw new NoSuchBeanDefinitionException("");
        }
    } catch (final BeansException ex) {
        log.info("Elastic job: cannot found bean for class: '{}'. This job is not managed for spring.", bundle.getJobDetail().getJobClass().getCanonicalName());
        return super.newJob(bundle, scheduler);
    }
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.putAll(scheduler.getContext());
    jobDataMap.putAll(bundle.getJobDetail().getJobDataMap());
    jobDataMap.putAll(bundle.getTrigger().getJobDataMap());
    Job target = (Job) AopTargetUtils.getTarget(job);
    setBeanProps(target, jobDataMap);
    return target;
}
 
開發者ID:artoderk,項目名稱:elastic-jobx,代碼行數:27,代碼來源:SpringJobFactory.java

示例9: getMainCommand

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private Object getMainCommand(Collection<Object> candidates) {
    Object mainCommand = null;
    for (Object candidate : candidates) {
        Class<?> clazz = AopUtils.getTargetClass(candidate);
        Method method = ReflectionUtils.findMethod(Command.class, "name");
        if (clazz.isAnnotationPresent(Command.class)
                && method != null
                && clazz.getAnnotation(Command.class).name().equals(method.getDefaultValue())) {
            mainCommand = candidate;
            break;
        }
    }
    if (mainCommand == null) {
        mainCommand = new PicocliCommand() {};
    }
    return mainCommand;
}
 
開發者ID:kakawait,項目名稱:picocli-spring-boot-starter,代碼行數:18,代碼來源:PicocliAutoConfiguration.java

示例10: isTransactionalApplicationEventListener

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private static boolean isTransactionalApplicationEventListener(ApplicationListener<?> listener) {

		Class<?> targetClass = AopUtils.getTargetClass(listener);

		if (!ApplicationListenerMethodAdapter.class.isAssignableFrom(targetClass)) {
			return false;
		}

		Field field = ReflectionUtils.findField(ApplicationListenerMethodAdapter.class, "method");
		ReflectionUtils.makeAccessible(field);
		Method method = (Method) ReflectionUtils.getField(field, listener);

		return AnnotatedElementUtils.hasAnnotation(method, TransactionalEventListener.class);
	}
 
開發者ID:olivergierke,項目名稱:spring-domain-events,代碼行數:15,代碼來源:PersistentApplicationEventMulticaster.java

示例11: getServiceClass

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Override
protected Class getServiceClass(T ref) {
    if (AopUtils.isAopProxy(ref)) {
        return AopUtils.getTargetClass(ref);
    }
    return super.getServiceClass(ref);
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:8,代碼來源:ServiceBean.java

示例12: loadSshdShellCommands

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private void loadSshdShellCommands(Map<String, Map<String, CommandExecutableDetails>> sshdShellCommandsMap,
        Object obj) throws SecurityException, NoSuchMethodException, InterruptedException {
    Class<?> clazz = AopUtils.isAopProxy(obj) ? AopUtils.getTargetClass(obj) : obj.getClass();
    SshdShellCommand annotation = AnnotationUtils.findAnnotation(clazz, SshdShellCommand.class);
    Map<String, CommandExecutableDetails> map = getSupplierMap(annotation, sshdShellCommandsMap);
    loadSshdShellCommandSuppliers(clazz, annotation, map, obj);
}
 
開發者ID:anand1st,項目名稱:sshd-shell-spring-boot,代碼行數:8,代碼來源:SshdShellAutoConfiguration.java

示例13: invoke

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
	// Work out the target class: may be {@code null}.
	// The TransactionAttributeSource should be passed the target class
	// as well as the method, which may be from an interface.
	Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);

	// Adapt to TransactionAspectSupport's invokeWithinTransaction...
	return invokeWithinTransaction(invocation.getMethod(), targetClass, new InvocationCallback() {
		@Override
		public Object proceedWithInvocation() throws Throwable {
			return invocation.proceed();
		}
	});
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:TransactionInterceptor.java

示例14: supportsEventType

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	Class<?> declaredEventType = resolveDeclaredEventType(this.delegate.getClass());
	if (declaredEventType == null || declaredEventType.equals(ApplicationEvent.class)) {
		Class<?> targetClass = AopUtils.getTargetClass(this.delegate);
		if (targetClass != this.delegate.getClass()) {
			declaredEventType = resolveDeclaredEventType(targetClass);
		}
	}
	return (declaredEventType == null || declaredEventType.isAssignableFrom(eventType));
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:GenericApplicationListenerAdapter.java

示例15: testPostProcessAfterInitialization

import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Test
public void testPostProcessAfterInitialization() throws IOException, NoSuchMethodException {
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
	TestSteps steps = context.getBean(TestSteps.class);

	Class<?> wrapped = AopUtils.getTargetClass(steps);
	Method method = wrapped.getMethod("anotherStep", String.class);

	Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
	Collection<StepImplementation> givens = givenBeanIndex.values();

	List<StepImplementation> matches = Lists.newArrayList();
	for (StepImplementation given : givens) {
		Method givenMethod = given.getMethod();
		if (givenMethod.equals(method)) {
			matches.add(given);
		}
	}

	int count = matches.size();
	assertEquals(count, 1, "wrong number of GivenStep objects registered for TestSteps.anotherStep()");

	StepImplementation match = matches.get(0);
	Pattern pattern = match.getPattern();
	Matcher matcher = pattern.matcher("another \"(.+)\" here");
	assertTrue(matcher.find(), "expected Pattern to match Gherkin regular expression");
	assertEquals(matcher.groupCount(), 1, "wrong number of parameters captured for TestSteps.anotherStep()");
}
 
開發者ID:qas-guru,項目名稱:martini-core,代碼行數:29,代碼來源:StepsAnnotationProcessorTest.java


注:本文中的org.springframework.aop.support.AopUtils.getTargetClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。