合并bean定义

@param target a {@link org.springframework.beans.factory.config.BeanDefinition} object.
@param source a
{@link org.beangle.inject.spring.config.context.spring.ReconfigBeanDefinitionHolder}
object.
@return a {@link java.lang.String} object.
432445
protected String mergeDefinition(BeanDefinition target, ReconfigBeanDefinitionHolder source) {
    if (null == target.getBeanClassName()) {
      logger.warn("ingore bean definition {} for without class", source.getBeanName());
      return null;
    }
    // 当类型变化后,删除原有配置
    if (null != source.getBeanDefinition().getBeanClassName()
        && !source.getBeanDefinition().getBeanClassName().equals(target.getBeanClassName())) {
      target.setBeanClassName(source.getBeanDefinition().getBeanClassName());
      for (PropertyValue pv : target.getPropertyValues().getPropertyValues()) {
        target.getPropertyValues().removePropertyValue(pv);
      }
      target.getConstructorArgumentValues().clear();
    }
    MutablePropertyValues pvs = source.getBeanDefinition().getPropertyValues();
    for (PropertyValue pv : pvs.getPropertyValueList()) {
      String name = pv.getName();
      target.getPropertyValues().addPropertyValue(name, pv.getValue());
      logger.debug("config {}.{} = {}", new Object[] { source.getBeanName(), name, pv.getValue() });
    }
    logger.debug("Reconfig bean {} ", source.getBeanName());
    return source.getBeanName();
  }
961013
public void mapping(Object src, Object target) throws BeanMappingException {
        boolean first = ContextObjectHolder.getInstance().enter();
        boolean isBeanMappingSupportScript = BeanMappingEnvironment.isBeanMappingSupportScript();
        BeanMappingParam param = new BeanMappingParam();
        param.setSrcRef(src);
        param.setTargetRef(target);
        param.setConfig(this.config);
        List<ValueProcess> vps = BeanMappingEnvironment.getBeanMappingVps();
        param.setProcesses(vps);

        // 执行mapping处理
        try {
            BeanMappingExecutor.execute(param);
        } finally {
            if (first) {// 第一个进入的负责清空数据，可能存在递归调用处理
                ContextObjectHolder.getInstance().clear();
                if (isBeanMappingSupportScript) {
                    ScriptHelper.getInstance().getScriptExecutor().disposeFunctions();// 清空记录
                }
            }
        }
    }
785656
protected final DefinitionBinder bind(String beanName, Class<?> clazz) {
    Assert.notNull(beanName);
    Assert.notNull(clazz);
    return config.bind(beanName, clazz);
  }
476558
@Override
  public <S, T> Convert<S, T> converter(Class<S> source, Class<T> target)
  {
    ConvertFrom<S> convertType = getOrCreate(source);
    
    return convertType.converter(target);
  }
855627
public <S, T> FromUnmarshaller<S, T> findUnmarshaller(Class<S> source, Class<T> target) {
		return findUnmarshaller(new ConverterKey<S,T>(source, target, DefaultBinding.class));
	}
1044812
public static void merge(String source, String target) throws IOException{
        final AtomicLong count = new AtomicLong();
        final AtomicLong lines = new AtomicLong();
        try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(target),"utf-8"))){
            Files.walkFileTree(Paths.get(source), new SimpleFileVisitor<Path>(){

                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        LOGGER.info("处理文件："+file);
                        try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file.toFile()),"utf-8"));){
                            String line;
                            while( (line = reader.readLine()) != null ){
                                count.addAndGet(line.length());
                                lines.incrementAndGet();
                                writer.write(line+"\n");
                            }
                        }
                        return FileVisitResult.CONTINUE;
                    }
                    
                });
        }
        LOGGER.info("语料库行数："+lines.get());
        LOGGER.info("语料库字符数目："+count.get());
    }
293254
public static void copy(Object src, Object target) throws BeanMappingException {
        BeanCopy copy = BeanCopy.create(src.getClass(), target.getClass());
        copy.copy(src, target);
    }
1303210
@SuppressWarnings({ "unchecked", "rawtypes" })
    public static Object convert(Object source, Class<?> target) throws ConversionException {
        if (target == null) {
            throw new ConversionException("Unable to perform conversion, target was null");
        }
        if (source == null) {
            if (target.isPrimitive()) {
                throw new ConversionException(String.format("Unable to convert null to primitive value of %s", target));
            }
            return source;
        } else if ((source instanceof Float && ((Float) source).isNaN()) || (source instanceof Double && ((Double) source).isNaN())) {
            // Don't convert NaN values
            return source;
        }
        //		if (BaseConnection.class.isAssignableFrom(source.getClass()) && !target.equals(IConnection.class)) {
        //			log.debug("Conversion failure - source: {} target: {}", source.getClass(), target);
        //			throw new ConversionException("Source is not assignable and target is not equal to IConnection");
        //		}
        if (target.isInstance(source)) {
            return source;
        }
        if (target.isAssignableFrom(source.getClass())) {
            return source;
        }
        if (target.isArray()) {
            return convertToArray(source, target);
        }
        if (target.equals(String.class)) {
            return source.toString();
        }
        if (target.isPrimitive()) {
            return convertToWrappedPrimitive(source, primitiveMap.get(target));
        }
        if (wrapperMap.containsKey(target)) {
            return convertToWrappedPrimitive(source, target);
        }
        if (target.equals(Map.class)) {
            return convertBeanToMap(source);
        }
        if (target.equals(List.class) || target.equals(Collection.class)) {
            if (source.getClass().equals(LinkedHashMap.class)) {
                return convertMapToList((LinkedHashMap<?, ?>) source);
            } else if (source.getClass().isArray()) {
                return convertArrayToList((Object[]) source);
            }
        }
        if (target.equals(Set.class) && source.getClass().isArray()) {
            return convertArrayToSet((Object[]) source);
        }
        if (target.equals(Set.class) && source instanceof List) {
            return new HashSet((List) source);
        }
        if (source instanceof Map) {
            return convertMapToBean((Map) source, target);
        }
        throw new ConversionException(String.format("Unable to preform conversion from %s to %s", source, target));
    }
701663
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry definitionRegistry)
      throws BeansException {
    // 自动注册
    BindRegistry registry = new SpringBindRegistry(definitionRegistry);
    Map<String, BeanDefinition> newDefinitions = registerModules(registry);
    // should register after all beans
    registerBuildins(registry);
    // 再配置
    reconfig(definitionRegistry, registry);
    lifecycle(registry, definitionRegistry);
    autowire(newDefinitions, registry);
  }
1299619
public <T> DynamicJdbcMapper<T> newMapper(final TypeReference<T> target) {
        return newMapper(target.getType());
    }
78
public void populate(Object target, Map properties) throws BeanMappingException {
        BeanMappingParam param = new BeanMappingParam();
        param.setSrcRef(properties);
        param.setTargetRef(target);
        param.setConfig(this.populateConfig);
        param.setProcesses(BeanMappingEnvironment.getBeanMapVps());
        // 执行mapping处理
        BeanMappingExecutor.execute(param);
    }
266003
public BeanMappingObject getBeanMappingObject(Class src, Class target) {
        return getFromRepository(src, target, this.repository);
    }
618999
public Object transformObject(TransformationDescription description, Object source, Object target)
        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        checkNeededValues(description);
        Class<?> sourceClass = modelRegistry.loadModel(description.getSourceModel());
        Class<?> targetClass = modelRegistry.loadModel(description.getTargetModel());
        if (!sourceClass.isAssignableFrom(source.getClass())) {
            throw new IllegalArgumentException("The given source object does not match the given description");
        }
        this.source = source;
        if (target == null) {
            this.target = targetClass.newInstance();
        } else {
            this.target = target;
        }
        for (TransformationStep step : description.getTransformingSteps()) {
            performTransformationStep(step);
        }
        return this.target;
    }
622141
public static void populate(Object target, Map properties) throws BeanMappingException {
        BeanMap map = BeanMap.create(target.getClass());
        map.populate(target, properties);
    }
1322190
@Override
    public Set<BeanDefinitionHolder> doScan(String... basePackages) {
        Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);

        if (beanDefinitions.isEmpty()) {
            logger.warn("No MyBatis mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration.");
        } else {
            processBeanDefinitions(beanDefinitions);
        }

        return beanDefinitions;
    }
548069
public static void mapping(Object src, Object target) throws BeanMappingException {
        BeanMapping mapping = BeanMapping.create(src.getClass(), target.getClass());
        mapping.mapping(src, target);
    }
246161
protected Map<String, Object> updateMap(Map<String, Object> target, Map<String, Object> source) {
        Map<String, Object> resultMap = new HashMap<String, Object>(target);

        String keyWOClassName = null;

        for (String sourceKey : source.keySet()) {
            keyWOClassName = InputUtils.removeClassName(sourceKey);

            if (target.containsKey(sourceKey) == true) {
                resultMap.put(sourceKey, source.get(sourceKey));
            } else if (target.containsKey(keyWOClassName) == true) {
                resultMap.put(keyWOClassName, source.get(keyWOClassName));
            }
        }

        return resultMap;
    }