本文整理汇总了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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
});
}
示例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));
}
示例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()");
}