private void call(String operation, Map<String, String> args)
      throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {

    final String requestClassName = packageName + ".model." + operation + "Request";
    final String operationMethodName =
        operation.substring(0, 1).toLowerCase() + operation.substring(1);
    Class<Object> requestClass = ReflectionUtils.loadClass(this.getClass(), requestClassName);
    Object requestObject = ReflectionUtils.newInstance(requestClass);

    if (args != null && !args.isEmpty()) {
      for (Map.Entry<String, String> entry : args.entrySet()) {

        String key = entry.getKey().substring(0, 1).toUpperCase() + entry.getKey().substring(1);
        Object value =
            convertTo(
                ReflectionUtils.getParameterTypes(requestObject, Arrays.asList(key)),
                entry.getValue());

        ReflectionUtils.setByPath(requestObject, value, Arrays.asList(key));
      }
    }

    Method method = ReflectionUtils.findMethod(client, operationMethodName, requestClass);

    result = method.invoke(client, requestObject);
  }
示例#2
0
 private String resolveTypeDiscriminatorForBackReference(Member m) {
   Method me =
       ReflectionUtils.findMethod(
           m.getDeclaringClass(), "get" + firstCharToUpperCase(m.getName()));
   if (me != null) {
     return resolveTypeDiscriminator(resolveReturnType(me));
   }
   return "";
 }
 @Ignore("[SPR-8644] findMethod() does not currently support var-args")
 @Test
 public void findMethodWithVarArgs() throws Exception {
   assertNotNull(ReflectionUtils.findMethod(B.class, "add", int.class, int.class, int.class));
 }
 @Test
 public void findMethod() throws Exception {
   assertNotNull(ReflectionUtils.findMethod(B.class, "bar", String.class));
   assertNotNull(ReflectionUtils.findMethod(B.class, "foo", Integer.class));
   assertNotNull(ReflectionUtils.findMethod(B.class, "getClass"));
 }
示例#5
0
  static {
    ClassLoader loader = VfsUtils.class.getClassLoader();
    String pkg;
    Class<?> vfsClass;

    // check for JBoss 6
    try {
      vfsClass = loader.loadClass(VFS3_PKG + VFS_NAME);
      version = VFS_VER.V3;
      pkg = VFS3_PKG;

      if (logger.isDebugEnabled()) {
        logger.debug("JBoss VFS packages for JBoss AS 6 found");
      }
    } catch (ClassNotFoundException ex) {
      // fallback to JBoss 5
      if (logger.isDebugEnabled())
        logger.debug(
            "JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages");
      try {
        vfsClass = loader.loadClass(VFS2_PKG + VFS_NAME);

        version = VFS_VER.V2;
        pkg = VFS2_PKG;

        if (logger.isDebugEnabled()) logger.debug("JBoss VFS packages for JBoss AS 5 found");
      } catch (ClassNotFoundException ex2) {
        logger.error(
            "JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled");
        throw new IllegalStateException("Cannot detect JBoss VFS packages", ex2);
      }
    }

    // cache reflective information
    try {
      String methodName = (VFS_VER.V3.equals(version) ? "getChild" : "getRoot");

      VFS_METHOD_GET_ROOT_URL = ReflectionUtils.findMethod(vfsClass, methodName, URL.class);
      VFS_METHOD_GET_ROOT_URI = ReflectionUtils.findMethod(vfsClass, methodName, URI.class);

      Class<?> virtualFile = loader.loadClass(pkg + "VirtualFile");

      VIRTUAL_FILE_METHOD_EXISTS = ReflectionUtils.findMethod(virtualFile, "exists");
      VIRTUAL_FILE_METHOD_GET_INPUT_STREAM = ReflectionUtils.findMethod(virtualFile, "openStream");
      VIRTUAL_FILE_METHOD_GET_SIZE = ReflectionUtils.findMethod(virtualFile, "getSize");
      VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED =
          ReflectionUtils.findMethod(virtualFile, "getLastModified");
      VIRTUAL_FILE_METHOD_TO_URI = ReflectionUtils.findMethod(virtualFile, "toURI");
      VIRTUAL_FILE_METHOD_TO_URL = ReflectionUtils.findMethod(virtualFile, "toURL");
      VIRTUAL_FILE_METHOD_GET_NAME = ReflectionUtils.findMethod(virtualFile, "getName");
      VIRTUAL_FILE_METHOD_GET_PATH_NAME = ReflectionUtils.findMethod(virtualFile, "getPathName");
      GET_PHYSICAL_FILE = ReflectionUtils.findMethod(virtualFile, "getPhysicalFile");

      methodName = (VFS_VER.V3.equals(version) ? "getChild" : "findChild");

      VIRTUAL_FILE_METHOD_GET_CHILD =
          ReflectionUtils.findMethod(virtualFile, methodName, String.class);

      Class<?> utilsClass = loader.loadClass(pkg + "VFSUtils");

      VFS_UTILS_METHOD_GET_COMPATIBLE_URI =
          ReflectionUtils.findMethod(utilsClass, "getCompatibleURI", virtualFile);
      VFS_UTILS_METHOD_IS_NESTED_FILE =
          ReflectionUtils.findMethod(utilsClass, "isNestedFile", virtualFile);

      VIRTUAL_FILE_VISITOR_INTERFACE = loader.loadClass(pkg + "VirtualFileVisitor");
      VIRTUAL_FILE_METHOD_VISIT =
          ReflectionUtils.findMethod(virtualFile, "visit", VIRTUAL_FILE_VISITOR_INTERFACE);

      Class<?> visitorAttributesClass = loader.loadClass(pkg + "VisitorAttributes");
      VISITOR_ATTRIBUTES_FIELD_RECURSE =
          ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
    } catch (ClassNotFoundException ex) {
      throw new IllegalStateException("Could not detect the JBoss VFS infrastructure", ex);
    }
  }