예제 #1
0
  /**
   * Set the parameters to be used for constructor injection
   *
   * @param paramsString a comma separated list of type/name pairs.
   */
  public void setConstructor(String paramsString) {
    this.paramsString = paramsString;

    // Convert a paramString into a list of parameters
    StringTokenizer st = new StringTokenizer(paramsString, ",");
    while (st.hasMoreTokens()) {
      String paramString = st.nextToken().trim();
      String[] paramParts = paramString.split(" ");

      if (paramParts.length != 2) {
        log.error(
            "Parameter list includes parameter '"
                + paramString
                + "' that can't be parsed into a [type] and [name]");
        throw new IllegalArgumentException(
            "Badly formatted constructor parameter list. See log console for details.");
      }

      String typeName = paramParts[0];

      try {
        Class<?> type = LocalUtil.classForName(typeName);
        Pair<Class<?>, String> parameter = new Pair<Class<?>, String>(type, paramParts[1]);
        parameters.add(parameter);
      } catch (ClassNotFoundException ex) {
        if (typeName.contains(".")) {
          log.error("Parameter list includes unknown type '" + typeName + "'");
          throw new IllegalArgumentException(
              "Unknown type in constructor parameter list. See log console for details.");
        } else {
          try {
            Class<?> type = LocalUtil.classForName("java.lang." + typeName);
            Pair<Class<?>, String> parameter = new Pair<Class<?>, String>(type, paramParts[1]);
            parameters.add(parameter);
          } catch (ClassNotFoundException ex2) {
            log.error(
                "Parameter list includes unknown type '"
                    + typeName
                    + "' (also tried java.lang."
                    + typeName
                    + ")");
            throw new IllegalArgumentException(
                "Unknown type in constructor parameter list. See log console for details.");
          }
        }
      }
    }
  }
예제 #2
0
 /**
  * What sort of class do we create?
  *
  * @param classname The name of the class
  */
 public void setClass(String classname) {
   try {
     this.clazz = LocalUtil.classForName(classname);
   } catch (ClassNotFoundException ex) {
     throw new IllegalArgumentException("Class not found: " + classname, ex);
   }
 }
예제 #3
0
 /**
  * What sort of class do we create?
  *
  * @param classname The name of the class
  */
 public void setClass(String classname) {
   try {
     clazz = LocalUtil.classForName(classname);
     if (getJavascript() == null) {
       setJavascript(clazz.getSimpleName());
     }
   } catch (ExceptionInInitializerError ex) {
     throw new IllegalArgumentException("Error loading class: " + classname, ex);
   } catch (ClassNotFoundException ex) {
     throw new IllegalArgumentException("Class not found: " + classname, ex);
   }
 }
예제 #4
0
 /**
  * @param name The class name to use as an implementation of the converted bean
  * @throws ClassNotFoundException If the given class can not be found
  */
 public void setImplementation(String name) throws ClassNotFoundException {
   setInstanceType(LocalUtil.classForName(name));
 }