Ejemplo n.º 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.");
          }
        }
      }
    }
  }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 4
0
  /* (non-Javadoc)
   * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
   */
  public Object convertInbound(Class<?> paramType, InboundVariable data)
      throws ConversionException {
    if (data.isNull()) {
      return null;
    }

    String uriString = LocalUtil.urlDecode(data.getValue());
    try {
      return new URI(uriString);
    } catch (URISyntaxException ex) {
      log.warn("Failed to create URL from string '" + uriString + "'. Returning null");
      return null;
    }
  }
Ejemplo n.º 5
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));
 }