protected Validator createConstraintValidator(Annotation constraint, Class<?> valueType, ValidatedBy constraintAnnotation){ Class<? extends Validator> validatorClass = constraintAnnotation.validator(); ReflectClass rc = ReflectClass.of(validatorClass); ReflectConstructor constructor = rc.getConstructor(constraint.annotationType(),Class.class); if(null == constructor){ throw new IllegalStateException("Validator class '" + validatorClass.getName() + "' must define constructor (" + constraint.annotationType().getName() + ", java.lang.Class)"); } return constructor.newInstance(constraint,valueType); }
@SuppressWarnings("unchecked") public <T> T newInstance() throws ReflectException{ if(null == defaultConstructor){ throw new ReflectException(Strings.format("there is no default constructor available in class '{0}'",getName())); } if(defaultConstructorInner){ return (T)defaultConstructor.newInstance(Reflection.newInstance(clazz.getEnclosingClass())); }else{ if(null != accessor && accessor.canNewInstance()){ return (T)accessor.newInstance(); }else{ return (T)defaultConstructor.newInstance((Object[])null); } } }
protected Object doCreateProxy(BeanDefinitionBase pd, Class<?> type, Object bean){ Object proxy; if(ProxyBean.class.isAssignableFrom(pd.getBeanClass())) { proxy = doCreateBeanOnly(pd); ((ProxyBean)proxy).setTargetBean(bean); }else{ ReflectConstructor c = ReflectClass.of(pd.getBeanClass()).getConstructor(type); if(null == c) { throw new BeanCreationException("Can't create proxy '" + pd.getBeanClass() + "', No valid constructor"); } proxy = c.newInstance(bean); beforeBeanCreation(pd); processBeanCreation(pd, proxy); afterBeanCreation(pd); pd.setInited(true); } return proxy; }
protected Object newInstance(ConvertContext context, BeanType bt, Map<String, Object> map){ ReflectClass cls = bt.getReflectClass(); ConvertContext.ConcreteTypes types = null == context ? null : context.getConcreteTypes(); if(null != types) { Object instance = types.newInstance(context, bt.getBeanClass(), null, map); if(null != instance) { return instance; } } if(cls.isAbstract() || cls.isInterface()) { throw new ConvertException("Cannot new instance for abstract class or interface '" + bt.getBeanClass().getName() + "'"); }else if(cls.hasDefaultConstructor()){ return bt.newInstance(); }else{ ReflectConstructor c = cls.getConstructors()[0]; ReflectParameter[] ps = c.getParameters(); Object[] args = new Object[c.getParameters().length]; for(int i=0;i<args.length;i++){ ReflectParameter p = ps[i]; args[i] = Converts.convert(map.get(p.getName()), p.getType(), p.getGenericType(), context); } return c.newInstance(args); } }
return dc.newInstance(args); }else{ throw new BeanCreationException("Cannot create bean without default constructor, check the bean : " + bd);