Example usage for org.springframework.aop.framework ProxyFactory setFrozen

List of usage examples for org.springframework.aop.framework ProxyFactory setFrozen

Introduction

In this page you can find the example usage for org.springframework.aop.framework ProxyFactory setFrozen.

Prototype

public void setFrozen(boolean frozen) 

Source Link

Document

Set whether this config should be frozen.

Usage

From source file:org.sakaiproject.genericdao.springutil.CurrentClassLoaderBeanNameAutoProxyCreator.java

@SuppressWarnings("unchecked")
@Override/*w w w .ja v a  2  s .c o  m*/
protected Object createProxy(Class beanClass, String beanName, Object[] specificInterceptors,
        TargetSource targetSource) {
    if (spring12x) {
        ProxyFactory proxyFactory = new ProxyFactory();
        // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig.
        proxyFactory.copyFrom(this);

        if (!shouldProxyTargetClass(beanClass, beanName)) {
            // Must allow for introductions; can't just set interfaces to
            // the target's interfaces only.
            Class[] targetInterfaces = ClassUtils.getAllInterfacesForClass(beanClass);
            for (int i = 0; i < targetInterfaces.length; i++) {
                proxyFactory.addInterface(targetInterfaces[i]);
            }
        }

        Advisor[] advisors = buildAdvisors(beanName, specificInterceptors);
        for (int i = 0; i < advisors.length; i++) {
            proxyFactory.addAdvisor(advisors[i]);
        }

        proxyFactory.setTargetSource(targetSource);
        customizeProxyFactory(proxyFactory);

        proxyFactory.setFrozen(this.freezeProxy);
        return proxyFactory.getProxy(myClassLoader);
    } else {
        return super.createProxy(beanClass, beanName, specificInterceptors, targetSource);
    }
}

From source file:org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.java

/**
 * Create an AOP proxy for the given bean.
 * @param beanClass the class of the bean
 * @param beanName the name of the bean/*www . j  a va  2 s  .  c om*/
 * @param specificInterceptors the set of interceptors that is
 * specific to this bean (may be empty, but not null)
 * @param targetSource the TargetSource for the proxy,
 * already pre-configured to access the bean
 * @return the AOP proxy for the bean
 * @see #buildAdvisors
 */
protected Object createProxy(Class<?> beanClass, @Nullable String beanName,
        @Nullable Object[] specificInterceptors, TargetSource targetSource) {

    if (this.beanFactory instanceof ConfigurableListableBeanFactory) {
        AutoProxyUtils.exposeTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName,
                beanClass);
    }

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.copyFrom(this);

    if (!proxyFactory.isProxyTargetClass()) {
        if (shouldProxyTargetClass(beanClass, beanName)) {
            proxyFactory.setProxyTargetClass(true);
        } else {
            evaluateProxyInterfaces(beanClass, proxyFactory);
        }
    }

    Advisor[] advisors = buildAdvisors(beanName, specificInterceptors);
    proxyFactory.addAdvisors(advisors);
    proxyFactory.setTargetSource(targetSource);
    customizeProxyFactory(proxyFactory);

    proxyFactory.setFrozen(this.freezeProxy);
    if (advisorsPreFiltered()) {
        proxyFactory.setPreFiltered(true);
    }

    return proxyFactory.getProxy(getProxyClassLoader());
}

From source file:org.springframework.jmx.export.MBeanExporter.java

/**
 * Registers beans that are configured for lazy initialization with the
 * <code>MBeanServer<code> indirectly through a proxy.
 * @param beanName the name of the bean in the <code>BeanFactory</code>
 * @param beanKey the key associated with this bean in the beans map
 * @return the <code>ObjectName</code> under which the bean was registered
 * with the <code>MBeanServer</code>
 * @throws JMException an error in the underlying JMX infrastructure
 * @throws InvalidTargetObjectTypeException an error in the definition of the MBean resource
 *///  w w  w  . j a  va2s . co m
private ObjectName registerLazyInit(String beanName, String beanKey)
        throws JMException, InvalidTargetObjectTypeException {

    LazyInitTargetSource targetSource = new LazyInitTargetSource();
    targetSource.setTargetBeanName(beanName);
    targetSource.setBeanFactory(this.beanFactory);

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTargetSource(targetSource);
    proxyFactory.setProxyTargetClass(true);
    proxyFactory.setFrozen(true);

    Object proxy = proxyFactory.getProxy();
    ObjectName objectName = getObjectName(proxy, beanKey);
    if (logger.isDebugEnabled()) {
        logger.debug("Registering lazy-init MBean [" + objectName + "]");
    }

    ModelMBean mbean = createModelMBean();
    mbean.setModelMBeanInfo(getMBeanInfo(proxy, beanKey));
    mbean.setManagedResource(proxy, MR_TYPE_OBJECT_REFERENCE);

    return doRegister(mbean, objectName);
}