将原始类型的参数值转换成目标类型的对等参数值
<p>Function: cast</p>
<p>Description: </p>

@param targetField
@param targetObject
@param originValue
@return
@author acexy@thankjava.com
@date 2016年1月11日 上午11:07:37
@version 1.0
480115
public static Object cast(Field targetField, Object targetObject, Object originValue) {
        return createValueCore(targetField, targetField.getType(), targetObject, originValue);
    }
583059
public static void setValue(ModelNode target, ModelType type, Object propValue) {

        if (type.equals(ModelType.STRING)) {
            target.set((String) propValue);
        } else if (type.equals(ModelType.INT)) {
            target.set((Integer) propValue);
        } else if (type.equals(ModelType.DOUBLE)) {
            target.set((Double) propValue);
        } else if (type.equals(ModelType.LONG)) {
            // in some cases the server returns the wrong model type for numeric values
            // i.e the description affords a ModelType.LONG, but a ModelType.INTEGER is returned
            try {
                target.set((Long) propValue);
            } catch (Throwable e) { // ClassCastException
                target.set(Integer.valueOf((Integer) propValue));
            }
        } else if (type.equals(ModelType.BIG_DECIMAL)) {
            // in some cases the server returns the wrong model type for numeric values
            // i.e the description affords a ModelType.LONG, but a ModelType.INTEGER is returned
            try {
                target.set((BigDecimal) propValue);
            } catch (Throwable e) { // ClassCastException
                target.set(Double.valueOf((Double) propValue));
            }
        } else if (type.equals(ModelType.BOOLEAN)) {
            target.set((Boolean) propValue);
        } else if (type.equals(ModelType.LIST)) {
            target.setEmptyList();
            List list = (List) propValue;

            for (Object item : list) {
                target.add(String.valueOf(item));
            }
        } else {
            Log.warn("Type conversionnot supported for " + type);
            target.setEmptyObject();
        }

    }
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();// 清空记录
                }
            }
        }
    }
661234
public static <T extends Object> T setFieldValue(Object obj, Field field, T fieldValue) {
        Assert.notNull(obj, "obj不能为空");
        Assert.notNull(field, "field不能为空");

        try {
            field.set(obj, fieldValue);
        } catch (IllegalAccessException e) {
            String msg = StringUtils.format("类型[{0}]的字段[{1}]不允许设置", obj.getClass(),
                field.getName());
            log.error(msg);
            throw new ReflectException(msg, e);
        }
        return fieldValue;
    }
696953
public static void setFieldValue(final Object target, final String name, final Object value) {
		Field field = FieldUtils.getDeclaredField(target.getClass(), name, true);

		if (field == null) {
			throw new IllegalArgumentException("Could not find field [" + name + "] on target [" + target + ']');
		}

		try {
			field.set(target, value);
		} catch (IllegalAccessException e) {
			throw new ImpossibleException(e);
		}
	}
418042
public static void setFieldValue(final Class<?> source, final Object target, final String fieldName, final Object value) throws NoSuchFieldException
    {
        try
        {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
            {
                @Override
                public Void run() throws Exception
                {
                    Field field = source.getDeclaredField(fieldName);
                    if(!field.isAccessible())
                    {
                        field.setAccessible(true);
                    }
                    field.set(target, value);
                    return null;
                }
            });
        }
        // Unwrap
        catch (final PrivilegedActionException pae)
        {
            final Throwable t = pae.getCause();
            // Rethrow
            if (t instanceof NoSuchFieldException)
            {
                throw (NoSuchFieldException) t;
            }
            else
            {
                // No other checked Exception thrown by Class.getConstructor
                try
                {
                    throw (RuntimeException) t;
                }
                // Just in case we've really messed up
                catch (final ClassCastException cce)
                {
                    throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t);
                }
            }
        }
    }
942729
def convert(origin, target, type):
    
    _origin = origin.upper()
    if _origin == 'ROOTCODE':
        _origin = root_type_codes
    elif _origin == 'ROOTNAME':
        _origin = root_type_names
    elif _origin == 'ARRAY':
        _origin = python_codes
    elif _origin == 'NUMPY':
        _origin = numpy_codes
    else:
        raise ValueError("{0} is not a valid type".format(origin))

    _target = target.upper()
    if _target == 'ROOTCODE':
        _target = root_type_codes
    elif _target == 'ROOTNAME':
        _target = root_type_names
    elif _target == 'ARRAY':
        _target = python_codes
    elif _target == 'NUMPY':
        _target = numpy_codes
    else:
        raise ValueError("{0} is not a valid type".format(target))

    if type not in _origin:
        raise ValueError("{0} is not a valid {1} type".format(type, origin))

    return _target[_origin.index(type)]
1303719
public <T> T inject(Class<T> targetClass, T targetObject) {
		try {
			doInject(targetClass, targetObject);
			return targetObject;
		} catch (ReflectiveOperationException e) {
			throw new RuntimeException(e);
		}
	}
1153439
public static <S, T> Convert<S, T> to(Class<T> targetType, Position.Readable<S> sourcePosition) {
        return new Convert<>(sourcePosition, targetType);
    }
397969
public static <OriginObject, TargetObject> List<TargetObject> copyList(List<OriginObject> originObjects, Class<TargetObject> targetClass) {

        if (originObjects == null) {
            return null;
        }

        //参数不合法异常
        if (targetClass == null) {
            throw new IllegalArgumentException("targetClass can't be null");
        }
        List<TargetObject> targetObjects = new ArrayList<TargetObject>();
        for (OriginObject originObject : originObjects) {
            targetObjects.add(copy(originObject, targetClass));
        }
        return targetObjects;
    }
1122021
public static Object convertToUIInputValue(final ConverterFactory converterFactory,
            final InputComponent<?, ?> input, final Object value)
   {
      final Object result;
      Class<Object> sourceType = (Class<Object>) value.getClass();
      Class<Object> targetType = (Class<Object>) input.getValueType();
      if (!targetType.isAssignableFrom(sourceType))
      {
         if (input instanceof SelectComponent)
         {
            SelectComponent<?, Object> selectComponent = (SelectComponent<?, Object>) input;
            Iterable<Object> valueChoices = selectComponent.getValueChoices();
            final Converter<Object, ?> selectConverter;
            if (String.class.isAssignableFrom(sourceType))
            {
               selectConverter = getItemLabelConverter(converterFactory, selectComponent);
            }
            else
            {
               selectConverter = converterFactory.getConverter(targetType, sourceType);
            }
            Object chosenObj = null;
            if (valueChoices != null)
            {
               for (Object valueChoice : valueChoices)
               {
                  Object convertedObj = selectConverter.convert(valueChoice);
                  if (convertedObj.equals(value))
                  {
                     chosenObj = valueChoice;
                     break;
                  }
               }
            }
            result = chosenObj;
         }
         else
         {

            Converter<String, Object> valueConverter = (Converter<String, Object>) input.getValueConverter();
            if (valueConverter != null)
            {
               if (value instanceof String)
               {
                  result = valueConverter.convert((String) value);
               }
               else
               {
                  Converter<Object, String> stringConverter = converterFactory.getConverter(sourceType, String.class);
                  CompositeConverter compositeConverter = new CompositeConverter(stringConverter, valueConverter);
                  result = compositeConverter.convert(value);
               }

            }
            else
            {
               Converter<Object, Object> converter = converterFactory.getConverter(sourceType, targetType);
               result = converter.convert(value);
            }
         }
      }
      else
      {

         Converter<String, Object> valueConverter = (Converter<String, Object>) input.getValueConverter();
         if (valueConverter != null && value instanceof String)
         {
            result = valueConverter.convert((String) value);
         }
         else
         {
            // FORGE-2493: By setting the system property 'org.jboss.forge.ui.select_one_lenient_value' to true will
            // allow UISelectOne to set values outside of its value choices. (pre-2.20.0.Final behavior)
            if (input instanceof SelectComponent && !Boolean.getBoolean("org.jboss.forge.ui.select_one_lenient_value"))
            {
               SelectComponent<?, Object> selectComponent = (SelectComponent<?, Object>) input;
               Set<Object> valueChoices = Sets.toSet(selectComponent.getValueChoices());
               // Check if the value is contained in the valueChoices set
               if (valueChoices != null && valueChoices.contains(value))
               {
                  result = value;
               }
               else
               {
                  // equals()/hashCode may not have been implemented. Trying to compare from the String representation
                  Object chosenObj = null;
                  if (valueChoices != null)
                  {
                     Converter<Object, String> selectConverter = getItemLabelConverter(converterFactory,
                              selectComponent);
                     String valueLabel = selectConverter.convert(value);
                     for (Object valueChoice : valueChoices)
                     {
                        String convertedObj = selectConverter.convert(valueChoice);
                        if (convertedObj.equals(valueLabel))
                        {
                           chosenObj = valueChoice;
                           break;
                        }
                     }
                  }
                  result = chosenObj;
               }
            }
            else
            {
               result = value;
            }
         }
      }
      return result;
   }
963656
static Object createValueList(Field targetField,Class<?> targetFieldType,Object targetObject,Object originValue) {
		if(originValue == null){
			return null;
		}
		
		List<?> originList = (List<?>)originValue;
		if(originList.size() == 0){
			return null;
		}
		
		Class<?> proxyType = originList.get(0).getClass();

//		Type type = targetField.getGenericType();
//		Type[] types = (Type[]) ReflectUtil.getFieldVal(type, "actualTypeArguments");
//		System.out.println(types);
//		Class<?> proxyType = null;
//		try {
//			System.out.println(ReflectUtil.getFieldVal(types[0], "name").toString());
//			proxyType = Class.forName(ReflectUtil.getFieldVal(types[0], "name").toString());
//		} catch (ClassNotFoundException e) {
//			e.printStackTrace();
//			return null;
//		}
		
		
		List<Object> targetList = new ArrayList<Object>();
		
		for (Object object : originList) {
			targetList.add(ValueCast.createValueCore(targetField, proxyType, targetList, object));
		}
		return targetList;
		
	}
790061
public Object convert(Class<?> type, String origin) throws ConversionException {
        if (origin == null) {
            return convertNullValue(type);
        }

        Converter converter = find(type);
        try {
            return converter.convert(origin);
        } catch (Exception e) {
            throw new ConversionException(String.format("Could not convert string <%s> to type <%s>", origin, type), e);
        }
    }
152963
@SuppressWarnings({ "unchecked", "TryWithIdenticalCatches" })
  public static void writeField(
      @NonNull Object value, @NonNull Class<?> enclosingClass,
      @NonNull Object target, @NonNull String field) {
    try {
      Field f = enclosingClass.getDeclaredField(field);
      f.setAccessible(true);
      f.set(target, value);
    } catch (NoSuchFieldException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }
546918
public static Object getFieldValue(FieldMetadata fieldMetadata, Object target) {
    MethodHandle readMethod = fieldMetadata.getReadMethod();
    try {
      return readMethod.invoke(target);
    } catch (Throwable t) {
      throw new EntityManagerException(t.getMessage(), t);
    }
  }
248032
public static void set(Object target, Field field, Object value)
    {
        if (target != null)
        {
            if (!field.isAccessible())
            {
                field.setAccessible(true);
            }
            try
            {
                field.set(target, value);
            }
            catch (IllegalArgumentException iarg)
            {
                throw new PropertyAccessException(iarg);
            }
            catch (IllegalAccessException iacc)
            {
                throw new PropertyAccessException(iacc);
            }
        } // ignore if object is null;
    }
1108624
public static boolean isAssignable(Class<?> targetType, Class<?> sourceType) {
		if (null == targetType || null == sourceType) {
			return false;
		}

		// 对象类型
		if (targetType.isAssignableFrom(sourceType)) {
			return true;
		}

		// 基本类型
		if (targetType.isPrimitive()) {
			// 原始类型
			Class<?> resolvedPrimitive = BasicType.wrapperPrimitiveMap.get(sourceType);
			if (resolvedPrimitive != null && targetType.equals(resolvedPrimitive)) {
				return true;
			}
		} else {
			// 包装类型
			Class<?> resolvedWrapper = BasicType.primitiveWrapperMap.get(sourceType);
			if (resolvedWrapper != null && targetType.isAssignableFrom(resolvedWrapper)) {
				return true;
			}
		}
		return false;
	}