Project

General

Profile

Download (856 Bytes) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm;
10

    
11
import org.springframework.aop.framework.Advised;
12
import org.springframework.aop.support.AopUtils;
13

    
14
/**
15
 * @author a.kohlbecker
16
 * @since Feb 23, 2018
17
 */
18
public class SpringProxyBeanHelper {
19

    
20
    @SuppressWarnings({"unchecked"})
21
    public static <T> T getTargetObject(Object proxy, Class<T> targetClass) throws Exception {
22
      if (AopUtils.isJdkDynamicProxy(proxy)) {
23
        return (T) ((Advised)proxy).getTargetSource().getTarget();
24
      } else {
25
        return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class
26
      }
27
    }
28
}
    (1-1/1)