Search in sources :

Example 1 with InterfaceMaker

use of org.springframework.cglib.proxy.InterfaceMaker in project spring-framework by spring-projects.

the class ScriptFactoryPostProcessor method createConfigInterface.

/**
	 * Create a config interface for the given bean definition, defining setter
	 * methods for the defined property values as well as an init method and
	 * a destroy method (if defined).
	 * <p>This implementation creates the interface via CGLIB's InterfaceMaker,
	 * determining the property types from the given interfaces (as far as possible).
	 * @param bd the bean definition (property values etc) to create a
	 * config interface for
	 * @param interfaces the interfaces to check against (might define
	 * getters corresponding to the setters we're supposed to generate)
	 * @return the config interface
	 * @see org.springframework.cglib.proxy.InterfaceMaker
	 * @see org.springframework.beans.BeanUtils#findPropertyType
	 */
protected Class<?> createConfigInterface(BeanDefinition bd, Class<?>[] interfaces) {
    InterfaceMaker maker = new InterfaceMaker();
    PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues();
    for (PropertyValue pv : pvs) {
        String propertyName = pv.getName();
        Class<?> propertyType = BeanUtils.findPropertyType(propertyName, interfaces);
        String setterName = "set" + StringUtils.capitalize(propertyName);
        Signature signature = new Signature(setterName, Type.VOID_TYPE, new Type[] { Type.getType(propertyType) });
        maker.add(signature, new Type[0]);
    }
    if (bd instanceof AbstractBeanDefinition) {
        AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
        if (abd.getInitMethodName() != null) {
            Signature signature = new Signature(abd.getInitMethodName(), Type.VOID_TYPE, new Type[0]);
            maker.add(signature, new Type[0]);
        }
        if (StringUtils.hasText(abd.getDestroyMethodName())) {
            Signature signature = new Signature(abd.getDestroyMethodName(), Type.VOID_TYPE, new Type[0]);
            maker.add(signature, new Type[0]);
        }
    }
    return maker.create();
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) InterfaceMaker(org.springframework.cglib.proxy.InterfaceMaker) Signature(org.springframework.cglib.core.Signature) PropertyValue(org.springframework.beans.PropertyValue)

Aggregations

PropertyValue (org.springframework.beans.PropertyValue)1 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)1 Signature (org.springframework.cglib.core.Signature)1 InterfaceMaker (org.springframework.cglib.proxy.InterfaceMaker)1