Search in sources :

Example 1 with TargetClassAware

use of org.springframework.aop.TargetClassAware in project opennms by OpenNMS.

the class DefaultForeignSourceService method getDetectorTypes.

/**
     * <p>getDetectorTypes</p>
     *
     * @return a {@link java.util.Map} object.
     */
@Override
public Map<String, String> getDetectorTypes() {
    if (m_detectors == null) {
        Map<String, String> detectors = new TreeMap<String, String>();
        for (ServiceDetector d : m_serviceRegistry.findProviders(ServiceDetector.class)) {
            String serviceName = d.getServiceName();
            if (serviceName == null) {
                serviceName = d.getClass().getSimpleName();
            }
            String className = d.getClass().getName();
            // NMS-8119: The class name may be changed when using proxy objects
            if (d instanceof TargetClassAware) {
                className = ((TargetClassAware) d).getTargetClass().getName();
            }
            detectors.put(serviceName, className);
        }
        m_detectors = new LinkedHashMap<String, String>();
        for (Entry<String, String> e : detectors.entrySet()) {
            m_detectors.put(e.getValue(), e.getKey());
        }
    }
    return m_detectors;
}
Also used : ServiceDetector(org.opennms.netmgt.provision.ServiceDetector) TargetClassAware(org.springframework.aop.TargetClassAware) TreeMap(java.util.TreeMap)

Example 2 with TargetClassAware

use of org.springframework.aop.TargetClassAware in project spring-framework by spring-projects.

the class AopProxyUtils method ultimateTargetClass.

/**
	 * 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 &mdash;
	 * 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 ultimate 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;
}
Also used : SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) TargetSource(org.springframework.aop.TargetSource) TargetClassAware(org.springframework.aop.TargetClassAware)

Aggregations

TargetClassAware (org.springframework.aop.TargetClassAware)2 TreeMap (java.util.TreeMap)1 ServiceDetector (org.opennms.netmgt.provision.ServiceDetector)1 TargetSource (org.springframework.aop.TargetSource)1 SingletonTargetSource (org.springframework.aop.target.SingletonTargetSource)1