List of usage examples for org.springframework.asm Type getType
public static Type getType(final Method method)
From source file:org.iff.infra.util.spring.script.ScriptFactoryPostProcessor.java
/** * 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).//from ww w . j a v a 2 s . co m * <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 (abd.getDestroyMethodName() != null) { Signature signature = new Signature(abd.getDestroyMethodName(), Type.VOID_TYPE, new Type[0]); maker.add(signature, new Type[0]); } } return maker.create(); }
From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java
@Override public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) { String annotationType = Type.getType(asmTypeDescriptor).getClassName(); AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader); this.attributes.put(attributeName, nestedAttributes); return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader); }
From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java
protected Object getEnumValue(String asmTypeDescriptor, String attributeValue) { Object valueToUse = attributeValue; try {/*from ww w.j a v a 2 s .co m*/ Class<?> enumType = ClassUtils.forName(Type.getType(asmTypeDescriptor).getClassName(), this.classLoader); Field enumConstant = ReflectionUtils.findField(enumType, attributeValue); if (enumConstant != null) { ReflectionUtils.makeAccessible(enumConstant); valueToUse = enumConstant.get(null); } } catch (ClassNotFoundException | NoClassDefFoundError ex) { logger.debug("Failed to classload enum type while reading annotation metadata", ex); } catch (IllegalAccessException | AccessControlException ex) { logger.debug("Could not access enum value while reading annotation metadata", ex); } return valueToUse; }
From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) { String annotationType = Type.getType(asmTypeDescriptor).getClassName(); AnnotationAttributes nestedAttributes = new AnnotationAttributes(); this.attributes.put(attributeName, nestedAttributes); return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader); }
From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java
public void visitEnum(String attributeName, String asmTypeDescriptor, String attributeValue) { Object valueToUse = attributeValue; try {// w ww. ja v a 2s .co m Class<?> enumType = this.classLoader.loadClass(Type.getType(asmTypeDescriptor).getClassName()); Field enumConstant = ReflectionUtils.findField(enumType, attributeValue); if (enumConstant != null) { valueToUse = enumConstant.get(null); } } catch (ClassNotFoundException ex) { this.logger.debug("Failed to classload enum type while reading annotation metadata", ex); } catch (IllegalAccessException ex) { this.logger.warn("Could not access enum value while reading annotation metadata", ex); } this.attributes.put(attributeName, valueToUse); }
From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java
@Override public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) { String annotationType = Type.getType(asmTypeDescriptor).getClassName(); AnnotationAttributes nestedAttributes = new AnnotationAttributes(); this.allNestedAttributes.add(nestedAttributes); return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader); }
From source file:org.springframework.scripting.support.ScriptFactoryPostProcessor.java
/** * 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).//from www . j a v a 2 s . c o m * <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, @Nullable 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(); }