Ejemplo n.º 1
0
  /**
   * @param xstreamObject not null
   * @param jarFile not null
   * @param packageFilter a package name to filter.
   */
  private void addAlias(XStream xstreamObject, File jarFile, String packageFilter) {
    JarInputStream jarStream = null;
    try {
      jarStream = new JarInputStream(new FileInputStream(jarFile));
      JarEntry jarEntry = jarStream.getNextJarEntry();
      while (jarEntry != null) {
        if (jarEntry.getName().toLowerCase(Locale.ENGLISH).endsWith(".class")) {
          String name = jarEntry.getName().substring(0, jarEntry.getName().indexOf("."));
          name = name.replaceAll("/", "\\.");

          if (name.indexOf(packageFilter) != -1) {
            try {
              Class<?> clazz = ClassUtils.getClass(name);
              String alias = StringUtils.lowercaseFirstLetter(ClassUtils.getShortClassName(clazz));
              xstreamObject.alias(alias, clazz);
              if (!clazz.equals(Model.class)) {
                xstreamObject.omitField(clazz, "modelEncoding"); // unnecessary field
              }
            } catch (ClassNotFoundException e) {
              e.printStackTrace();
            }
          }
        }

        jarStream.closeEntry();
        jarEntry = jarStream.getNextJarEntry();
      }
    } catch (IOException e) {
      if (getLog().isDebugEnabled()) {
        getLog().debug("IOException: " + e.getMessage(), e);
      }
    } finally {
      IOUtil.close(jarStream);
    }
  }
Ejemplo n.º 2
0
 public static Class loadClass(ClassLoader classLoader, String className)
     throws ClassNotFoundException {
   if (classLoader == null) {
     classLoader = Thread.currentThread().getContextClassLoader();
   }
   return org.apache.commons.lang.ClassUtils.getClass(classLoader, className);
 }
 @Override
 public String getOptions() {
   AssertUtil.parameterEmpty(getField().getRelationClass(), "getField().getRelationClass()");
   try {
     List<? extends BaseEnum> items =
         EnumUtils.getEnumList(ClassUtils.getClass(getField().getRelationClass()));
     StringBuffer buffer = new StringBuffer();
     for (BaseEnum item : items) {
       buffer.append(
           "<option value='" + ((Enum) item).name() + "'>" + item.getTitle() + "</option>");
     }
     return buffer.toString();
   } catch (ClassNotFoundException e) {
     log.error("枚举类型[" + getField().getRelationClass() + "]创建失败,错误信息:" + e.getMessage());
   }
   return "";
 }
 final Class<?> type(String name) throws Exception {
   return ClassUtils.getClass(name);
 }
 private Class<?> findClass(String name) throws ClassNotFoundException {
   return ClassUtils.getClass(getClass().getClassLoader(), name, false);
 }