mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@125603 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
102 lines
3.2 KiB
Java
102 lines
3.2 KiB
Java
package org.alfresco.repo.audit;
|
|
|
|
import java.lang.reflect.Method;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
import org.alfresco.service.Auditable;
|
|
import org.aopalliance.intercept.MethodInvocation;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.springframework.aop.ProxyMethodInvocation;
|
|
import org.springframework.beans.BeansException;
|
|
import org.springframework.beans.factory.BeanFactory;
|
|
import org.springframework.beans.factory.BeanFactoryAware;
|
|
import org.springframework.beans.factory.ListableBeanFactory;
|
|
|
|
/**
|
|
* Lookup the name of a bean that is being audited by {@link AuditMethodInterceptor}.
|
|
* <p>
|
|
* Originally used to look up public services annotated with {@code @PublicService},
|
|
* but has now been relaxed to be any bean that uses a proxy. For the method to be
|
|
* audited it still needs to be annotated with {@code @Auditable}.
|
|
*
|
|
* @author Andy Hind, David Ward, Alan Davis
|
|
*/
|
|
public class BeanIdentifierImpl implements BeanIdentifier, BeanFactoryAware
|
|
{
|
|
private static Log s_logger = LogFactory.getLog(BeanIdentifierImpl.class);
|
|
private static ThreadLocal<HashMap<Method, String>> methodToBeanMap =
|
|
new ThreadLocal<HashMap<Method, String>>();
|
|
|
|
private ListableBeanFactory beanFactory;
|
|
|
|
public BeanIdentifierImpl()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
|
|
{
|
|
this.beanFactory = (ListableBeanFactory)beanFactory;
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
* Cache service name look up.
|
|
*/
|
|
public String getBeanName(MethodInvocation mi)
|
|
{
|
|
return getName(mi);
|
|
}
|
|
|
|
private String getName(MethodInvocation mi) throws BeansException
|
|
{
|
|
if (methodToBeanMap.get() == null)
|
|
{
|
|
methodToBeanMap.set(new HashMap<Method, String>());
|
|
}
|
|
Method method = mi.getMethod();
|
|
String name = methodToBeanMap.get().get(method);
|
|
if (name == null)
|
|
{
|
|
name = getBeanNameImpl(mi);
|
|
methodToBeanMap.get().put(method, name);
|
|
}
|
|
else
|
|
{
|
|
if (s_logger.isDebugEnabled())
|
|
{
|
|
s_logger.debug("Cached look up for " + name + "." + method.getName());
|
|
}
|
|
}
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* Do the look up by interface type.
|
|
*
|
|
* @return Returns the name of the service or <tt>null</tt> if not found
|
|
*/
|
|
private String getBeanNameImpl(MethodInvocation mi) throws BeansException
|
|
{
|
|
if (mi instanceof ProxyMethodInvocation)
|
|
{
|
|
Object proxy = ((ProxyMethodInvocation) mi).getProxy();
|
|
Map beans = beanFactory.getBeansOfType(proxy.getClass());
|
|
Iterator iter = beans.entrySet().iterator();
|
|
while (iter.hasNext())
|
|
{
|
|
Map.Entry entry = (Map.Entry) iter.next();
|
|
String name = (String) entry.getKey();
|
|
if (proxy == entry.getValue() && !name.equals("DescriptorService"))
|
|
{
|
|
return name;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|