Пример #1
0
 /**
  * 获取一个字段的泛型参数数组,如果这个字段没有泛型,返回空数组
  *
  * @param f 字段
  * @return 泛型参数数组
  */
 public static Class<?>[] getGenericTypes(Field f) {
   String gts = f.toGenericString();
   Matcher m = PTN.matcher(gts);
   if (m.find()) {
     String s = m.group(2);
     String[] ss = Strings.splitIgnoreBlank(s);
     if (ss.length > 0) {
       Class<?>[] re = new Class<?>[ss.length];
       try {
         for (int i = 0; i < ss.length; i++) {
           String className = ss[i];
           if (className.length() > 0 && className.charAt(0) == '?') re[i] = Object.class;
           else {
             int pos = className.indexOf('<');
             if (pos < 0) re[i] = Lang.loadClass(className);
             else re[i] = Lang.loadClass(className.substring(0, pos));
           }
         }
         return re;
       } catch (ClassNotFoundException e) {
         throw Lang.wrapThrow(e);
       }
     }
   }
   return new Class<?>[0];
 }
Пример #2
0
 static {
   try {
     /** 加载DruidDataSourceFactory, 即Druid连接池的工厂类 */
     druidFactoryClass = Lang.loadClass("com.alibaba.druid.pool.DruidDataSourceFactory");
   } catch (ClassNotFoundException e) {
     // 找不到就用内置的SimpleDataSource好了.
     // TODO 支持其他类型的数据源, 低优先级
   }
 }
Пример #3
0
 /** @return 如果当前类为内部类,则返回其外部类。否则返回 null */
 public Class<?> getOuterClass() {
   if (Modifier.isStatic(klass.getModifiers())) return null;
   String name = klass.getName();
   int pos = name.lastIndexOf('$');
   if (pos == -1) return null;
   name = name.substring(0, pos);
   try {
     return Lang.loadClass(name);
   } catch (ClassNotFoundException e) {
     return null;
   }
 }
Пример #4
0
 public void init() throws Exception {
   String prefix = "cron.";
   for (String key : conf.getKeys()) {
     if (key.length() < prefix.length() + 1 || !key.startsWith(prefix)) continue;
     String name = key.substring(prefix.length());
     if ("pkgs".equals(name)) {
       log.debug("found cron job packages = " + conf.get(key));
       for (String pkg : Strings.splitIgnoreBlank(conf.get(key), ",")) {
         addPackage(pkg);
       }
       continue;
     }
     String cron = conf.get(key);
     log.debugf("job define name=%s cron=%s", name, cron);
     Class<?> klass = null;
     if (name.contains(".")) {
       klass = Lang.loadClass(name);
     } else {
       klass = Lang.loadClass(getClass().getPackage().getName() + ".job." + name);
     }
     cron(cron, klass);
   }
 }
Пример #5
0
 public void setExpert(Object obj) throws Exception {
   if (obj == null) throw new NullPointerException("expert MUST NOT NULL!!");
   if (obj instanceof JdbcExpert) {
     this.expert = (JdbcExpert) obj;
   } else {
     String name = obj.toString();
     this.expert = Jdbcs.getExpert(name, "");
     if (this.expert == null) {
       if (name.contains(".")) {
         this.expert = (JdbcExpert) Lang.loadClass(name).newInstance();
       } else {
         throw new DaoException("not such expert=" + obj);
       }
     }
   }
   DataSource ds = this.dataSource;
   // 如果数据源比expert先设置,那么需要重新设置一次
   if (ds != null) {
     this.dataSource = null;
     setDataSource(ds);
   }
 }