/** * Return the actual bean class of the given bean instance. * This is the class exposed to description-style JMX properties. * <p>Default implementation returns the target class for an AOP proxy, * and the plain bean class else. * @param managedBean the bean instance (might be an AOP proxy) * @return the bean class to expose * @see org.springframework.aop.support.AopUtils#getTargetClass(Object) */ protected Class<?> getTargetClass(Object managedBean) { return AopUtils.getTargetClass(managedBean); }
/** * Determine the class to use for logging purposes. * @param target the target object to introspect * @return the target class for the given object * @see #setHideProxyClassNames */ protected Class<?> getClassForLogging(Object target) { return (this.hideProxyClassNames ? AopUtils.getTargetClass(target) : target.getClass()); }
/** * Return the actual bean class of the given bean instance. * This is the class exposed to description-style JMX properties. * <p>Default implementation returns the target class for an AOP proxy, * and the plain bean class else. * @param managedBean the bean instance (might be an AOP proxy) * @return the bean class to expose * @see org.springframework.aop.support.AopUtils#getTargetClass(Object) */ protected Class<?> getTargetClass(Object managedBean) { return AopUtils.getTargetClass(managedBean); }
@Override @Nullable public Object invoke(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, invocation::proceed); }
@Nullable private static ResolvableType resolveDeclaredEventType(ApplicationListener<ApplicationEvent> listener) { ResolvableType declaredEventType = resolveDeclaredEventType(listener.getClass()); if (declaredEventType == null || declaredEventType.isAssignableFrom(ApplicationEvent.class)) { Class<?> targetClass = AopUtils.getTargetClass(listener); if (targetClass != listener.getClass()) { declaredEventType = resolveDeclaredEventType(targetClass); } } return declaredEventType; }
@Override protected Class getServiceClass(T ref) { if (AopUtils.isAopProxy(ref)) { return AopUtils.getTargetClass(ref); } return super.getServiceClass(ref); }
@Override protected Class getServiceClass(T ref) { if (AopUtils.isAopProxy(ref)) { return AopUtils.getTargetClass(ref); } return super.getServiceClass(ref); }
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; }
@Override @Nullable public Object invoke(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, invocation::proceed); }
private boolean isDirectChannel(MessageChannel channel) { Class<?> targetClass = AopUtils.getTargetClass(channel); boolean directChannel = this.hasDirectChannelClass && DirectChannel.class.isAssignableFrom(targetClass); if (!directChannel) { return false; } if (this.directWithAttributesChannelClass == null) { return true; } return !isStreamSpecialDirectChannel(targetClass); }
@Nullable private static ResolvableType resolveDeclaredEventType(ApplicationListener<ApplicationEvent> listener) { ResolvableType declaredEventType = resolveDeclaredEventType(listener.getClass()); if (declaredEventType == null || declaredEventType.isAssignableFrom(ApplicationEvent.class)) { Class<?> targetClass = AopUtils.getTargetClass(listener); if (targetClass != listener.getClass()) { declaredEventType = resolveDeclaredEventType(targetClass); } } return declaredEventType; }
@Nullable public Object invoke(final MethodInvocation invocation) throws Throwable { Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null); Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass); final Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
/** * Find a <em>single</em> Method on the Class of the given candidate object * that contains the annotation type for which this resolver is searching. * * @param candidate the instance whose Class will be checked for the * annotation * * @return a single matching Method instance or <code>null</code> if the * candidate's Class contains no Methods with the specified annotation * * @throws IllegalArgumentException if more than one Method has the * specified annotation */ public Method findMethod(Object candidate) { Assert.notNull(candidate, "candidate object must not be null"); Class<?> targetClass = AopUtils.getTargetClass(candidate); if (targetClass == null) { targetClass = candidate.getClass(); } return this.findMethod(targetClass); }
/** * Reads the {@code ObjectName} from the source-level metadata associated * with the managed resource's {@code Class}. */ @Override public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException { Assert.state(this.attributeSource != null, "No JmxAttributeSource set"); 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 { Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified"); 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<>(); properties.put("type", ClassUtils.getShortName(managedClass)); properties.put("name", beanKey); return ObjectNameManager.getInstance(domain, properties); } } }
@Nullable protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException { Class<?> targetClass = AopUtils.getTargetClass(bean); if (targetClass != bean.getClass()) { Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
private static String getClassPart(MethodInvocation invocation) { // si guice et pas Spring, alors remplacer AopUtils.getTargetClass() par getMethod().getDeclaringClass() // http://ninomartinez.wordpress.com/2010/05/14/guice-caching-interceptors/ // (faire exemple avec un interceptor static) final Class<?> targetClass = AopUtils.getTargetClass(invocation.getThis()); final MonitoredWithSpring classAnnotation = targetClass .getAnnotation(MonitoredWithSpring.class); if (classAnnotation == null || classAnnotation.name() == null || classAnnotation.name().isEmpty()) { final Class<?> declaringClass = invocation.getMethod().getDeclaringClass(); final MonitoredWithSpring declaringClassAnnotation = declaringClass .getAnnotation(MonitoredWithSpring.class); if (declaringClassAnnotation == null || declaringClassAnnotation.name() == null || declaringClassAnnotation.name().isEmpty()) { return targetClass.getSimpleName(); } return declaringClassAnnotation.name(); } return classAnnotation.name(); }
handlerType = AopUtils.getTargetClass(handlerMethod.getBean());
/** * Reads the {@code ObjectName} from the source-level metadata associated * with the managed resource's {@code Class}. */ @Override public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException { Assert.state(this.attributeSource != null, "No JmxAttributeSource set"); 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 { Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified"); 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<>(); properties.put("type", ClassUtils.getShortName(managedClass)); properties.put("name", beanKey); return ObjectNameManager.getInstance(domain, properties); } } }
@Nullable protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException { Class<?> targetClass = AopUtils.getTargetClass(bean); if (targetClass != bean.getClass()) { Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
if (!advised.isFrozen() && isEligible(AopUtils.getTargetClass(bean))) {