Пример #1
0
  public BufferedImage decodeAsBufferedImage(InputStream input) throws Exception {
    if (jpegCodecClazz == null) {
      jpegCodecClazz = Class.forName("com.sun.image.codec.jpeg.JPEGCodec");
    }

    Object decoder = MethodUtils.invokeStaticMethod(jpegCodecClazz, "createJPEGDecoder", input);

    return (BufferedImage) MethodUtils.invokeMethod(decoder, "decodeAsBufferedImage", null);
  }
Пример #2
0
 // revise BeanUtils describe method do not copy data type
 public static Map describe(Object bean)
     throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
   if (bean == null) {
     return (new java.util.HashMap());
   }
   Map description = new HashMap();
   if (bean instanceof DynaBean) {
     DynaProperty[] descriptors = ((DynaBean) bean).getDynaClass().getDynaProperties();
     for (int i = 0; i < descriptors.length; i++) {
       String name = descriptors[i].getName();
       description.put(name, org.apache.commons.beanutils.BeanUtils.getProperty(bean, name));
     }
   } else {
     PropertyDescriptor[] descriptors =
         BeanUtilsBean.getInstance().getPropertyUtils().getPropertyDescriptors(bean);
     Class clazz = bean.getClass();
     for (int i = 0; i < descriptors.length; i++) {
       String name = descriptors[i].getName();
       if (MethodUtils.getAccessibleMethod(clazz, descriptors[i].getReadMethod()) != null) {
         description.put(name, PropertyUtils.getNestedProperty(bean, name));
       }
     }
   }
   return (description);
 }
Пример #3
0
  private Boolean callMethod(String attributeName, Object parentObj, Map<String, String> values) {
    if (logger.isTraceEnabled()) {
      logger.trace(
          ">>> callMethod attributeName="
              + attributeName
              + ", parentObj="
              + parentObj
              + ", values="
              + values);
    }

    if (attributeName == null || parentObj == null || values == null) return null;
    String methodName = values.get(MODIFIER_CALL);
    if (methodName == null) return null;
    Object result = null;
    try {
      result = MethodUtils.invokeMethod(parentObj, methodName, attributeName);
    } catch (NoSuchMethodException e) {
      return null;
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    if (result == null || !(result instanceof Boolean)) {
      return null;
    }
    return (Boolean) result;
  }
 /** Get static Method. */
 public static Method getStaticMethod(Class<?> cls, String methodName, Object[] arguments)
     throws NoSuchMethodException {
   Method method =
       MethodUtils.getMatchingAccessibleMethod(cls, methodName, getArgumentClasses(arguments));
   if (method == null)
     throw new NoSuchMethodException("No such accessible method: " + methodName + "() on object");
   return method;
 }
Пример #5
0
 public void actionListener(ActionEvent actionEvent) {
   try {
     Object instance = ScreenUtils.evaluate(getActionListenerObject());
     if (instance != null) {
       MethodUtils.invokeExactMethod(instance, getActionListenerMethod(), actionEvent);
     }
   } catch (Exception e) {
     LOGGER.error("Ocurrio un error ejecutando actionListener", e);
   }
 }
Пример #6
0
  /**
   * Used for the evaluation of the emptiness in the META SQL fragments.
   *
   * @param attributeName the name of the input value
   * @param obj the input value
   * @param parentObj the parent of the input value
   * @param sqlMetaType the internal type (= META type) devoted for the special processing of the
   *     input values
   * @param inOutModifier the input/output value modifier devoted to extend the processing of the
   *     input/output values
   * @param inSqlSetOrInsert an indicator the input value is evaluated in the CRUD statement (INSERT
   *     or SET)
   * @param values values for a special identifier handling, for example a sequence for an identity
   * @param features the optional features in the statement coontext
   * @return the non-emptiness of the input value
   */
  protected boolean isNotEmptyInternal(
      String attributeName,
      Object obj,
      Object parentObj,
      SqlMetaType sqlMetaType,
      String inOutModifier,
      boolean inSqlSetOrInsert,
      Map<String, String> values,
      Map<String, Object> features)
      throws IllegalArgumentException {

    if (MODIFIER_NOTNULL.equalsIgnoreCase(inOutModifier)) {
      if (obj == null) throw new IllegalArgumentException(MODIFIER_NOTNULL);
    }

    if (inSqlSetOrInsert) {
      boolean isEmptyUseMethodIsNull = false;
      if (obj == null && attributeName != null && parentObj != null) {
        Object o = features.get(SqlFeature.EMPTY_USE_METHOD_IS_NULL);
        if (o != null && o instanceof Boolean && ((Boolean) o)) isEmptyUseMethodIsNull = true;
      }
      Object isNullObj = null;
      if (isEmptyUseMethodIsNull) {
        try {
          isNullObj = MethodUtils.invokeMethod(parentObj, "isNull", attributeName);
        } catch (NoSuchMethodException e) {
        } catch (IllegalAccessException e) {
          throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
          throw new RuntimeException(e);
        }
      }
      if (isNullObj != null && isNullObj instanceof Boolean && ((Boolean) isNullObj)) {
        return true;
      }
      boolean isEmptyForNull = isEmptyUseMethodIsNull;
      if (isEmpty(obj, values)) {
        Object o = features.get(SqlFeature.EMPTY_FOR_NULL);
        if (o != null && o instanceof Boolean && ((Boolean) o)) isEmptyForNull = true;
        if (!isEmptyForNull) return true;
      }
    }

    if (MODIFIER_ANY.equalsIgnoreCase(inOutModifier)) {
      return true;
    } else if (MODIFIER_NULL.equalsIgnoreCase(inOutModifier)) {
      if (obj == null) return true;
      else return false;
    } else {
      return !isEmpty(obj, values);
    }
  }
Пример #7
0
 public void invoke(String method) {
   if (method != null && method.trim().length() > 0) {
     try {
       Object o = MethodUtils.invokeMethod(getController(), method, null);
       if (o != null) {
         if (o instanceof String) {
           String p = (String) o;
           setCurrentPage(p);
         }
       }
       if (getCurrentPage() == null) {
         setCurrentPage("default");
       }
     } catch (Exception ex) {
       throw new IllegalStateException(ex.getMessage(), ex);
     }
   }
 }
Пример #8
0
  protected void populateDataFromManager(
      Object executionClass, WebDropDownListIF methodName, ModelAndView modelview, Map extraParams)
      throws ApplicationCoreException {

    StringBuilder methodNameStr = new StringBuilder();
    methodNameStr.append(REF_DATA_PREFIX);
    methodNameStr.append(StringUtil.makeFirstLetterUpperCase(methodName.toString()));

    Object[] params = {methodName.toString(), modelview, extraParams};

    try {
      Map returnValues =
          (Map) MethodUtils.invokeMethod(executionClass, methodNameStr.toString(), params);
      modelview.addObject(methodName.toString(), returnValues);

    } catch (NoSuchMethodException e) {
      logger.warn("Invalid method on the web data source during population.");
    } catch (IllegalAccessException e) {
      throw new ApplicationCoreException(e);
    } catch (InvocationTargetException e) {
      logger.warn("Invalid method on the web data source during population.");
    }
  }
  /** {@inheritDoc} */
  @Override
  public Requisition deletePath(final String groupName, final String pathToDelete) {
    m_writeLock.lock();

    try {
      final Requisition group = getProvisioningGroup(groupName);

      final PropertyPath path = new PropertyPath(pathToDelete);

      final Object objToDelete = path.getValue(group);
      final Object parentObject =
          path.getParent() == null ? group : path.getParent().getValue(group);

      final String propName = path.getPropertyName();
      final String methodSuffix = Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
      final String methodName = "delete" + methodSuffix;

      try {
        MethodUtils.invokeMethod(parentObject, methodName, new Object[] {objToDelete});
      } catch (final NoSuchMethodException e) {
        throw new IllegalArgumentException(
            "Unable to find method " + methodName + " on object of type " + parentObject.getClass(),
            e);
      } catch (final IllegalAccessException e) {
        throw new IllegalArgumentException("unable to access property " + pathToDelete, e);
      } catch (final InvocationTargetException e) {
        throw new IllegalArgumentException("an execption occurred deleting " + pathToDelete, e);
      }

      m_pendingForeignSourceRepository.save(group);
      m_pendingForeignSourceRepository.flush();
      return m_pendingForeignSourceRepository.getRequisition(groupName);
    } finally {
      m_writeLock.unlock();
    }
  }
 @Override
 public boolean bind(Object content, Node node) throws ContentNodeBindingException {
   // TODO Auto-generated method stub
   log.info("Let's update the document by binder");
   BeanInfo bi;
   try {
     bi = Introspector.getBeanInfo(content.getClass());
     PropertyDescriptor[] properties = bi.getPropertyDescriptors();
     DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(content);
     for (PropertyDescriptor property : properties) {
       if (formMap.getField(property.getName()) != null) {
         log.info("have a founding");
         if (node != null) {
           Class<?> theTypeClass = directFieldAccessor.getPropertyType(property.getName());
           if (!theTypeClass.isPrimitive()) {
             try {
               Class<?> thePrimitiveClass =
                   (Class<?>) theTypeClass.getDeclaredField("TYPE").get(node);
               if (thePrimitiveClass != null) {
                 theTypeClass = thePrimitiveClass;
               }
             } catch (NoSuchFieldException e) {
               // TODO Auto-generated catch block
               // e.printStackTrace();
             }
           }
           Object theValue =
               formMap.getField(property.getName()).getValue(); // theReadMethod.invoke(anObject);
           Method theMethod =
               MethodUtils.getAccessibleMethod(
                   node.getClass(), "setProperty", new Class[] {String.class, theTypeClass});
           if (theMethod != null) {
             theMethod.invoke(node, "mootlywcm:" + property.getName(), theValue);
           } else {
             if (node.hasNode("mootlywcm:" + property.getName())) {
               Node htmlNode = node.getNode("mootlywcm:" + property.getName());
               if (theValue != null) {
                 htmlNode.setProperty("hippostd:content", theValue.toString());
               }
             }
           }
         }
       }
       // }
     }
   } catch (IntrospectionException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (SecurityException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (RepositoryException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return true;
 }
 /** Invoke the static method. */
 public static Object invokeStaticMethod(Class<?> cls, String methodName, Object[] arguments)
     throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
   return MethodUtils.invokeStaticMethod(cls, methodName, arguments);
 }
 /**
  * Invoke the method. NOTE: MethodUtils doesn't support primitive arguments. e.g) echo(long[] v)
  */
 public static Object invokeMethod(Object obj, String methodName, Object[] arguments)
     throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
   return MethodUtils.invokeMethod(obj, methodName, arguments);
 }