private void initialize(){ this.valueField = reflectiveClass.getField(VALUE_FIELD_NAME); this.hasValueField = null != valueField; this.valueType = hasValueField ? valueField.getType() : null; } }
protected void injectApiBeans(App app, Api api) { Set<Object> controllers = new HashSet<>(); for(ApiRoute ar : api.getConfig().getApiRoutes()) { Route route = ar.getRoute(); //Inject ApiConfig & ApiMetadata. Object controller = route.getAction().getController(); if(null != controller && !controllers.contains(controller)) { controllers.add(controller); ReflectClass rc = ReflectClass.of(controller.getClass()); for(ReflectField rf : rc.getFields()) { if(rf.getType().equals(ApiConfig.class)) { rf.setValue(controller, api.getConfig()); break; } if(rf.getType().equals(ApiMetadata.class)) { rf.setValue(controller, api.getMetadata()); } } if(controller instanceof ApiInitializable) { ((ApiInitializable) controller).postApiInitialized(api); } } } controllers.clear(); }
@Override public void injectStatic(Class<?> cls) throws BeanException { BeanDefinitionBase bd = createBeanDefinition(cls); ReflectClass rc = ReflectClass.of(cls); BeanFactory factory = null != beanFactory ? beanFactory : this; for (ReflectField rf : rc.getFields()) { if (rf.isStatic() && rf.isAnnotationPresent(Inject.class)) { try { //skip when bean value already set. if (null != rf.getValue(null)) { continue; } Object injectedBean = resolveInjectValue(factory, bd, rf.getName(), rf.getType(), rf.getGenericType(), rf.getAnnotations()); if (null != injectedBean) { rf.setValue(null, injectedBean); } } catch (Exception e) { log.error("Error injecting static field '{}' in class '{}' : {}", rf.getName(), cls.getName(), e.getMessage()); throw e; } } } }
protected void validateField(BeanDefinition d, Object bean, ReflectField field) { if((field.isAnnotationPresent(NotNull.class) || field.isAnnotationPresent(M.class)) && null == field.getValue(bean)){ throw new BeanException("Field '" + field.getName() + "'(" + field.getType() + ") must not null in bean " + (null == d ? bean : d)); } if((field.isAnnotationPresent(NotEmpty.class) || field.isAnnotationPresent(R.class) ) && Objects2.isEmpty(field.getValue(bean))){ throw new BeanException("Field '" + field.getName() + "' must not empty in bean " + (null == d ? bean : d)); } }
if(Property.class.isAssignableFrom(field.getType())) { doBeanConfigure(bean, field, keyPrefix, field.getAnnotation(ConfigProperty.class)); continue;