• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ReflectionException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.ibatis.reflection.ReflectionException的典型用法代码示例。如果您正苦于以下问题:Java ReflectionException类的具体用法?Java ReflectionException怎么用?Java ReflectionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ReflectionException类属于org.apache.ibatis.reflection包,在下文中一共展示了ReflectionException类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setFieldEnumValueByOrdinal

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
/**
 * 设置枚举类型的字段值
 *
 * @param target  the target object from which to get the field
 * @param field   the field to set
 * @param ordinal enum.ordinal
 * @throws Exception IllegalArgumentException, IllegalAccess
 */
@SuppressWarnings("rawtypes")
public static void setFieldEnumValueByOrdinal(Object target, Field field, int ordinal) throws Exception {
    if (field.getType().isEnum()) {
        if (!field.isAccessible()) {
            ReflectionUtils.makeAccessible(field);
        }
        Enum[] enumObjs = (Enum[]) (field.getType()).getEnumConstants();
        for (Enum enumObj : enumObjs) {
            if (enumObj.ordinal() == ordinal) {
                field.set(target, enumObj);
            }
        }
    } else {
        throw new ReflectionException(target.getClass().getName() + "." + field.getName()
                + ":field type is not Enum, can not convertToEnum");
    }
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:26,代码来源:EnumFieldReflectUtil.java


示例2: shouldInstantiateAndThrowAllCustomExceptions

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
@Test
public void shouldInstantiateAndThrowAllCustomExceptions() throws Exception {
  Class<?>[] exceptionTypes = {
      BindingException.class,
      CacheException.class,
      DataSourceException.class,
      ExecutorException.class,
      LogException.class,
      ParsingException.class,
      BuilderException.class,
      PluginException.class,
      ReflectionException.class,
      PersistenceException.class,
      SqlSessionException.class,
      TransactionException.class,
      TypeException.class, 
      ScriptingException.class
  };
  for (Class<?> exceptionType : exceptionTypes) {
    testExceptionConstructors(exceptionType);
  }

}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:24,代码来源:GeneralExceptionsTest.java


示例3: instantiatePropertyValue

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
public MetaObject instantiatePropertyValue(String name,
		PropertyTokenizer prop, ObjectFactory objectFactory) {
	MetaObject metaValue;
	Class<?> type = getSetterType(prop.getName());
	try {
		Object newObject = objectFactory.create(type);
		metaValue = MetaObject.forObject(newObject,
				metaObject.getObjectFactory(),
				metaObject.getObjectWrapperFactory());
		set(prop, newObject);
	} catch (Exception e) {
		throw new ReflectionException("Cannot set value of property '"
				+ name + "' because '" + name
				+ "' is null and cannot be instantiated on instance of "
				+ type.getName() + ". Cause:" + e.toString(), e);
	}
	return metaValue;
}
 
开发者ID:yinshipeng,项目名称:sosoapi-base,代码行数:19,代码来源:BeanWrapper.java


示例4: methodToProperty

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
public static String methodToProperty(String name) {
    //去掉get|set|is
  if (name.startsWith("is")) {
    name = name.substring(2);
  } else if (name.startsWith("get") || name.startsWith("set")) {
    name = name.substring(3);
  } else {
    throw new ReflectionException("Error parsing property name '" + name + "'.  Didn't start with 'is', 'get' or 'set'.");
  }

  //如果只有1个字母-->转为小写
  //如果大于1个字母,第二个字母非大写-->转为小写
  //String uRL -->String getuRL() {
  if (name.length() == 1 || (name.length() > 1 && !Character.isUpperCase(name.charAt(1)))) {
    name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
  }

  return name;
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:20,代码来源:PropertyNamer.java


示例5: getFieldEnumOrdinal

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
/**
 * 获取枚举类型的字段值-ordinal
 *
 * @param target the target object from which to get the field
 * @param field  the field to get
 * @return enum.ordinal
 * @throws Exception IllegalArgumentException, IllegalAccess
 */
@SuppressWarnings("rawtypes")
public static int getFieldEnumOrdinal(Object target, Field field) throws Exception {
    if (field.getType().isEnum()) {
        if (!field.isAccessible()) {
            ReflectionUtils.makeAccessible(field);
        }
        return ((Enum) field.get(target)).ordinal();
    } else {
        throw new ReflectionException(target.getClass().getName() + "." + field.getName()
                + ":field type is not Enum, can not convertToEnum");
    }
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:21,代码来源:EnumFieldReflectUtil.java


示例6: instantiateImmutable

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
/**
 * This function should send the arguments to the "of" static constructor method of
 * the immutable type.
 *
 * @param type
 * @param constructorArgTypes
 * @param constructorArgs
 * @param <T>
 * @return
 */
@SuppressWarnings("unchecked")
private <T> T instantiateImmutable(
        Class<T> type,
        List<Class<?>> constructorArgTypes,
        List<Object> constructorArgs) throws NoSuchMethodException {

    // Get the constructor method, throws NoSuchMethodException if not found
    Method method = type
            .getDeclaredMethod(
                    IMMUTABLE_CONSTRUCTOR_METHOD,
                    (Class[]) constructorArgTypes.toArray(new Class[constructorArgTypes.size()]));

    // Try to invoke the method, throws IllegalAccessException if it isn't public, and throws
    // InvocationTargetException if the constructor throws an error or the args are incorrect
    try {
        return (T) method.invoke(null, constructorArgs.toArray(new Object[constructorArgs.size()]));
    } catch (InvocationTargetException | IllegalAccessException ex) {

        String argTypes = constructorArgTypes
                .stream()
                .map(Class::getSimpleName)
                .collect(Collectors.joining(", "));

        String argValues = constructorArgs
                .stream()
                .map(String::valueOf)
                .collect(Collectors.joining(", "));

        throw new ReflectionException(
                "Error instantiating " + type.getSimpleName() + " with invalid types (" + argTypes +
                        ") or values (" + argValues + "). Cause: " + ex,
                ex);
    }
}
 
开发者ID:cvent,项目名称:dropwizard-mybatis,代码行数:45,代码来源:ImmutablesFactory.java


示例7: methodToProperty

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
public static String methodToProperty(String name) {
  if (name.startsWith("is")) {
    name = name.substring(2);
  } else if (name.startsWith("get") || name.startsWith("set")) {
    name = name.substring(3);
  } else {
    throw new ReflectionException("Error parsing property name '" + name + "'.  Didn't start with 'is', 'get' or 'set'.");
  }

  if (name.length() == 1 || (name.length() > 1 && !Character.isUpperCase(name.charAt(1)))) {
    name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
  }

  return name;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:16,代码来源:PropertyNamer.java


示例8: instantiateClass

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
<T> T instantiateClass(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  try {
    Constructor<T> constructor;
    if (constructorArgTypes == null || constructorArgs == null) {
      constructor = type.getDeclaredConstructor();
      if (!constructor.isAccessible()) {
        constructor.setAccessible(true);
      }
      return constructor.newInstance();
    }
    constructor = type.getDeclaredConstructor(constructorArgTypes.toArray(new Class[constructorArgTypes.size()]));
    if (!constructor.isAccessible()) {
      constructor.setAccessible(true);
    }
    return constructor.newInstance(constructorArgs.toArray(new Object[constructorArgs.size()]));
  } catch (Exception e) {
    StringBuilder argTypes = new StringBuilder();
    if (constructorArgTypes != null && !constructorArgTypes.isEmpty()) {
      for (Class<?> argType : constructorArgTypes) {
        argTypes.append(argType.getSimpleName());
        argTypes.append(",");
      }
      argTypes.deleteCharAt(argTypes.length() - 1); // remove trailing ,
    }
    StringBuilder argValues = new StringBuilder();
    if (constructorArgs != null && !constructorArgs.isEmpty()) {
      for (Object argValue : constructorArgs) {
        argValues.append(String.valueOf(argValue));
        argValues.append(",");
      }
      argValues.deleteCharAt(argValues.length() - 1); // remove trailing ,
    }
    throw new ReflectionException("Error instantiating " + type + " with invalid types (" + argTypes + ") or values (" + argValues + "). Cause: " + e, e);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:36,代码来源:DefaultObjectFactory.java


示例9: getCollectionValue

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
protected Object getCollectionValue(PropertyTokenizer prop, Object collection) {
  if (collection instanceof Map) {
    return ((Map) collection).get(prop.getIndex());
  } else {
    int i = Integer.parseInt(prop.getIndex());
    if (collection instanceof List) {
      return ((List) collection).get(i);
    } else if (collection instanceof Object[]) {
      return ((Object[]) collection)[i];
    } else if (collection instanceof char[]) {
      return ((char[]) collection)[i];
    } else if (collection instanceof boolean[]) {
      return ((boolean[]) collection)[i];
    } else if (collection instanceof byte[]) {
      return ((byte[]) collection)[i];
    } else if (collection instanceof double[]) {
      return ((double[]) collection)[i];
    } else if (collection instanceof float[]) {
      return ((float[]) collection)[i];
    } else if (collection instanceof int[]) {
      return ((int[]) collection)[i];
    } else if (collection instanceof long[]) {
      return ((long[]) collection)[i];
    } else if (collection instanceof short[]) {
      return ((short[]) collection)[i];
    } else {
      throw new ReflectionException("The '" + prop.getName() + "' property of " + collection + " is not a List or Array.");
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:31,代码来源:BaseWrapper.java


示例10: setCollectionValue

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
protected void setCollectionValue(PropertyTokenizer prop, Object collection, Object value) {
  if (collection instanceof Map) {
    ((Map) collection).put(prop.getIndex(), value);
  } else {
    int i = Integer.parseInt(prop.getIndex());
    if (collection instanceof List) {
      ((List) collection).set(i, value);
    } else if (collection instanceof Object[]) {
      ((Object[]) collection)[i] = value;
    } else if (collection instanceof char[]) {
      ((char[]) collection)[i] = (Character) value;
    } else if (collection instanceof boolean[]) {
      ((boolean[]) collection)[i] = (Boolean) value;
    } else if (collection instanceof byte[]) {
      ((byte[]) collection)[i] = (Byte) value;
    } else if (collection instanceof double[]) {
      ((double[]) collection)[i] = (Double) value;
    } else if (collection instanceof float[]) {
      ((float[]) collection)[i] = (Float) value;
    } else if (collection instanceof int[]) {
      ((int[]) collection)[i] = (Integer) value;
    } else if (collection instanceof long[]) {
      ((long[]) collection)[i] = (Long) value;
    } else if (collection instanceof short[]) {
      ((short[]) collection)[i] = (Short) value;
    } else {
      throw new ReflectionException("The '" + prop.getName() + "' property of " + collection + " is not a List or Array.");
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:31,代码来源:BaseWrapper.java


示例11: instantiatePropertyValue

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
@Override
public MetaObject instantiatePropertyValue(String name, PropertyTokenizer prop, ObjectFactory objectFactory) {
  MetaObject metaValue;
  Class<?> type = getSetterType(prop.getName());
  try {
    Object newObject = objectFactory.create(type);
    metaValue = MetaObject.forObject(newObject, metaObject.getObjectFactory(), metaObject.getObjectWrapperFactory(), metaObject.getReflectorFactory());
    set(prop, newObject);
  } catch (Exception e) {
    throw new ReflectionException("Cannot set value of property '" + name + "' because '" + name + "' is null and cannot be instantiated on instance of " + type.getName() + ". Cause:" + e.toString(), e);
  }
  return metaValue;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:14,代码来源:BeanWrapper.java


示例12: instantiateClassThrowsProperErrorMsg

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
@Test
public void instantiateClassThrowsProperErrorMsg() {
  DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory();
  try {
    defaultObjectFactory.instantiateClass(TestClass.class, Collections.<Class<?>>singletonList(String.class), Collections.<Object>singletonList("foo"));
    Assert.fail("Should have thrown ReflectionException");
  } catch (Exception e) {
    Assert.assertTrue("Should be ReflectionException", e instanceof ReflectionException);
    Assert.assertTrue("Should not have trailing commas in types list", e.getMessage().contains("(String)"));
    Assert.assertTrue("Should not have trailing commas in values list", e.getMessage().contains("(foo)"));
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:13,代码来源:DefaultObjectFactoryTest.java


示例13: instantiateClass

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
private <T> T instantiateClass(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
    try {
        Constructor<T> constructor;
        if (constructorArgTypes == null || constructorArgs == null) {
            constructor = type.getDeclaredConstructor();
            if (!constructor.isAccessible()) {
                constructor.setAccessible(true);
            }
            return constructor.newInstance();
        }
        constructor = type.getDeclaredConstructor(constructorArgTypes.toArray(new Class[constructorArgTypes.size()]));
        if (!constructor.isAccessible()) {
            constructor.setAccessible(true);
        }
        return constructor.newInstance(constructorArgs.toArray(new Object[constructorArgs.size()]));
    } catch (Exception e) {
        StringBuilder argTypes = new StringBuilder();
        if (constructorArgTypes != null) {
            for (Class<?> argType : constructorArgTypes) {
                argTypes.append(argType.getSimpleName());
                argTypes.append(",");
            }
        }
        StringBuilder argValues = new StringBuilder();
        if (constructorArgs != null) {
            for (Object argValue : constructorArgs) {
                argValues.append(String.valueOf(argValue));
                argValues.append(",");
            }
        }
        throw new ReflectionException("Error instantiating " + type + " with invalid types (" + argTypes + ") or values (" + argValues + "). Cause: " + e, e);
    }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:34,代码来源:CustomObjectFactory.java


示例14: instantiateClass

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
private <T> T instantiateClass(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  try {
    Constructor<T> constructor;
    //如果没有传入constructor,调用空构造函数,核心是调用Constructor.newInstance
    if (constructorArgTypes == null || constructorArgs == null) {
      constructor = type.getDeclaredConstructor();
      if (!constructor.isAccessible()) {
        constructor.setAccessible(true);
      }
      return constructor.newInstance();
    }
    //如果传入constructor,调用传入的构造函数,核心是调用Constructor.newInstance
    constructor = type.getDeclaredConstructor(constructorArgTypes.toArray(new Class[constructorArgTypes.size()]));
    if (!constructor.isAccessible()) {
      constructor.setAccessible(true);
    }
    return constructor.newInstance(constructorArgs.toArray(new Object[constructorArgs.size()]));
  } catch (Exception e) {
      //如果出错,包装一下,重新抛出自己的异常
    StringBuilder argTypes = new StringBuilder();
    if (constructorArgTypes != null) {
      for (Class<?> argType : constructorArgTypes) {
        argTypes.append(argType.getSimpleName());
        argTypes.append(",");
      }
    }
    StringBuilder argValues = new StringBuilder();
    if (constructorArgs != null) {
      for (Object argValue : constructorArgs) {
        argValues.append(String.valueOf(argValue));
        argValues.append(",");
      }
    }
    throw new ReflectionException("Error instantiating " + type + " with invalid types (" + argTypes + ") or values (" + argValues + "). Cause: " + e, e);
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:37,代码来源:DefaultObjectFactory.java


示例15: getCollectionValue

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
protected Object getCollectionValue(PropertyTokenizer prop, Object collection) {
  if (collection instanceof Map) {
      //map['name']
    return ((Map) collection).get(prop.getIndex());
  } else {
    int i = Integer.parseInt(prop.getIndex());
    if (collection instanceof List) {
        //list[0]
      return ((List) collection).get(i);
    } else if (collection instanceof Object[]) {
      return ((Object[]) collection)[i];
    } else if (collection instanceof char[]) {
      return ((char[]) collection)[i];
    } else if (collection instanceof boolean[]) {
      return ((boolean[]) collection)[i];
    } else if (collection instanceof byte[]) {
      return ((byte[]) collection)[i];
    } else if (collection instanceof double[]) {
      return ((double[]) collection)[i];
    } else if (collection instanceof float[]) {
      return ((float[]) collection)[i];
    } else if (collection instanceof int[]) {
      return ((int[]) collection)[i];
    } else if (collection instanceof long[]) {
      return ((long[]) collection)[i];
    } else if (collection instanceof short[]) {
      return ((short[]) collection)[i];
    } else {
      throw new ReflectionException("The '" + prop.getName() + "' property of " + collection + " is not a List or Array.");
    }
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:33,代码来源:BaseWrapper.java


示例16: instantiatePropertyValue

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
@Override
public MetaObject instantiatePropertyValue(String name, PropertyTokenizer prop, ObjectFactory objectFactory) {
  MetaObject metaValue;
  Class<?> type = getSetterType(prop.getName());
  try {
    Object newObject = objectFactory.create(type);
    metaValue = MetaObject.forObject(newObject, metaObject.getObjectFactory(), metaObject.getObjectWrapperFactory());
    set(prop, newObject);
  } catch (Exception e) {
    throw new ReflectionException("Cannot set value of property '" + name + "' because '" + name + "' is null and cannot be instantiated on instance of " + type.getName() + ". Cause:" + e.toString(), e);
  }
  return metaValue;
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:14,代码来源:BeanWrapper.java


示例17: PageProviderSqlSource

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
public PageProviderSqlSource(ProviderSqlSource provider) {
    MetaObject metaObject = SystemMetaObject.forObject(provider);
    this.sqlSourceParser = (SqlSourceBuilder) metaObject.getValue("sqlSourceParser");
    this.providerType = (Class<?>) metaObject.getValue("providerType");
    this.providerMethod = (Method) metaObject.getValue("providerMethod");
    this.configuration = (Configuration) metaObject.getValue("sqlSourceParser.configuration");
    try {
        //先针对3.3.1和之前版本做判断
        this.providerTakesParameterObject = (Boolean) metaObject.getValue("providerTakesParameterObject");
    } catch (ReflectionException e) {
        //3.4.0+版本,解决#102 by Ian Lim
        providerMethodArgumentNames = (String[]) metaObject.getValue("providerMethodArgumentNames");
    }
}
 
开发者ID:xushaomin,项目名称:apple-orm,代码行数:15,代码来源:PageProviderSqlSource.java


示例18: instantiateClass

import org.apache.ibatis.reflection.ReflectionException; //导入依赖的package包/类
private  <T> T instantiateClass(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  try {
    Constructor<T> constructor;
    if (constructorArgTypes == null || constructorArgs == null) {
      constructor = type.getDeclaredConstructor();
      if (!constructor.isAccessible()) {
        constructor.setAccessible(true);
      }
      return constructor.newInstance();
    }
    constructor = type.getDeclaredConstructor(constructorArgTypes.toArray(new Class[constructorArgTypes.size()]));
    if (!constructor.isAccessible()) {
      constructor.setAccessible(true);
    }
    return constructor.newInstance(constructorArgs.toArray(new Object[constructorArgs.size()]));
  } catch (Exception e) {
    StringBuilder argTypes = new StringBuilder();
    if (constructorArgTypes != null && !constructorArgTypes.isEmpty()) {
      for (Class<?> argType : constructorArgTypes) {
        argTypes.append(argType.getSimpleName());
        argTypes.append(",");
      }
      argTypes.deleteCharAt(argTypes.length() - 1); // remove trailing ,
    }
    StringBuilder argValues = new StringBuilder();
    if (constructorArgs != null && !constructorArgs.isEmpty()) {
      for (Object argValue : constructorArgs) {
        argValues.append(String.valueOf(argValue));
        argValues.append(",");
      }
      argValues.deleteCharAt(argValues.length() - 1); // remove trailing ,
    }
    throw new ReflectionException("Error instantiating " + type + " with invalid types (" + argTypes + ") or values (" + argValues + "). Cause: " + e, e);
  }
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:36,代码来源:DefaultObjectFactory.java



注:本文中的org.apache.ibatis.reflection.ReflectionException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AccessDeniedException类代码示例发布时间:2022-05-22
下一篇:
Java Ikon类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap