예제 #1
0
 // Get the delegated-to editor kit. Specified by classname, not
 // prototype; specifying by prototype would be possible but a little
 // harder, and would make it difficult to make a good property
 // editor for.
 private void updateDelegate() {
   try {
     delegate =
         (EditorKit)
             Beans.instantiate(TopManager.getDefault().systemClassLoader(), Settings.kitClass);
     if (Settings.debug) System.err.println("The delegate kit: " + delegate);
   } catch (Exception e) {
     TopManager.getDefault().notifyException(e);
   }
 }
예제 #2
0
  private void addSetProperty(Object bean, Class<?>[] type, String name, Object... property)
      throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    if (name == null) {
      name = type[0].getSimpleName();
    }

    int dot;
    if ((dot = name.indexOf('.')) > -1) {
      _logger.fine("looking at a composite property " + name);
      do {
        bean = Beans.invoke(bean, "get" + name.substring(0, dot));
        name =
            Strings.capitalize(
                name.substring(dot + 1)); // lower case letters may be found after '.'
      } while ((dot = name.indexOf('.')) > -1);
    }

    // attempt property injection using setXXX(), addXXX(), set(), or add(), in that order
    try {
      _logger.fine(
          S.fine(_logger)
              ? "trying set"
                  + name
                  + "() on "
                  + bean.getClass()
                  + ": "
                  + property.length
                  + args(property)
              : null);
      Beans.invoke(bean, "set" + name, property);
      _logger.fine("... successful");
    } catch (NoSuchMethodException x) {
      try {
        _logger.fine(
            S.fine(_logger)
                ? "trying add"
                    + name
                    + "() on "
                    + bean.getClass()
                    + ": "
                    + property.length
                    + args(property)
                : null);
        Beans.invoke(bean, "add" + name, property);
        _logger.fine("... successful");
      } catch (NoSuchMethodException x1) {
        try {
          _logger.fine(
              S.fine(_logger)
                  ? "trying set() on " + bean.getClass() + ": " + property.length + args(property)
                  : null);
          Beans.invoke(bean, "set", property);
          _logger.fine("... successful");
        } catch (NoSuchMethodException x2) {
          _logger.fine(
              S.fine(_logger)
                  ? "trying add() on " + bean.getClass() + ": " + property.length + args(property)
                  : null);
          Beans.invoke(bean, "add", property);
          _logger.fine("... successful");
        }
      }
    }
  }