private void initializePluginAPI(TiWebView webView) {
    try {
      synchronized (this.getClass()) {
        // Initialize
        if (enumPluginStateOff == null) {
          Class<?> webSettings = Class.forName("android.webkit.WebSettings");
          Class<?> pluginState = Class.forName("android.webkit.WebSettings$PluginState");

          Field f = pluginState.getDeclaredField("OFF");
          enumPluginStateOff = (Enum<?>) f.get(null);
          f = pluginState.getDeclaredField("ON");
          enumPluginStateOn = (Enum<?>) f.get(null);
          f = pluginState.getDeclaredField("ON_DEMAND");
          enumPluginStateOnDemand = (Enum<?>) f.get(null);
          internalSetPluginState = webSettings.getMethod("setPluginState", pluginState);
          // Hidden APIs
          // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/webkit/WebView.java;h=bbd8b95c7bea66b7060b5782fae4b3b2c4f04966;hb=4db1f432b853152075923499768639e14403b73a#l2558
          internalWebViewPause = webView.getClass().getMethod("onPause");
          internalWebViewResume = webView.getClass().getMethod("onResume");
        }
      }
    } catch (ClassNotFoundException e) {
      Log.e(TAG, "ClassNotFound: " + e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      Log.e(TAG, "NoSuchMethod: " + e.getMessage(), e);
    } catch (NoSuchFieldException e) {
      Log.e(TAG, "NoSuchField: " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
      Log.e(TAG, "IllegalAccess: " + e.getMessage(), e);
    }
  }
 public FastMethod getMethod(final String name, final Class[] parameterTypes) {
   try {
     return getMethod(type.getMethod(name, parameterTypes));
   } catch (final NoSuchMethodException e) {
     throw new NoSuchMethodError(e.getMessage());
   }
 }
 @SuppressWarnings("unchecked")
 CustomAuthenticationProviderImpl(HiveConf conf) throws AuthenticationException {
   this.customHandlerClass =
       (Class<? extends PasswdAuthenticationProvider>)
           conf.getClass(
               HiveConf.ConfVars.HIVE_SERVER2_CUSTOM_AUTHENTICATION_CLASS.varname,
               PasswdAuthenticationProvider.class);
   // Try initializing the class with non-default and default constructors
   try {
     this.customProvider = customHandlerClass.getConstructor(HiveConf.class).newInstance(conf);
   } catch (NoSuchMethodException e) {
     try {
       this.customProvider = customHandlerClass.getConstructor().newInstance();
       // in java6, these four extend directly from Exception. So have to handle separately. In
       // java7,
       // the common subclass is ReflectiveOperationException
     } catch (NoSuchMethodException e1) {
       throw new AuthenticationException(
           "Can't instantiate custom authentication provider class. "
               + "Either provide a constructor with HiveConf as argument or a default constructor.",
           e);
     } catch (Exception e1) {
       throw new AuthenticationException(e.getMessage(), e);
     }
   } catch (Exception e) {
     throw new AuthenticationException(e.getMessage(), e);
   }
 }
  private static void applyMethodNameFiltering(TestNG testng, String methodNamePattern)
      throws TestSetFailedException {
    // the class is available in the testClassPath
    String clazzName = "org.apache.maven.surefire.testng.utils.MethodSelector";
    // looks to need a high value
    testng.addMethodSelector(clazzName, 10000);
    try {
      Class clazz = Class.forName(clazzName);

      Method method = clazz.getMethod("setMethodName", new Class[] {String.class});
      method.invoke(null, new Object[] {methodNamePattern});
    } catch (ClassNotFoundException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (SecurityException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    }
  }
  protected Object reifyCall(
      String className,
      String methodName,
      Class<?>[] parameterTypes,
      Object[] effectiveParameters,
      short priority) {
    try {
      return this.proxy.reify(
          MethodCall.getComponentMethodCall(
              Class.forName(className).getDeclaredMethod(methodName, parameterTypes),
              effectiveParameters,
              null,
              (String) null,
              null,
              priority));

      // functional interface name is null
    } catch (NoSuchMethodException e) {
      throw new ProActiveRuntimeException(e.toString());
    } catch (ClassNotFoundException e) {
      throw new ProActiveRuntimeException(e.toString());
    } catch (Throwable e) {
      throw new ProActiveRuntimeException(e.toString());
    }
  }
  /**
   * Creates a new entity enumeration icon chooser.
   *
   * @param enumeration the enumeration to display in this combo box
   */
  public EnumerationIconChooser(Class<E> enumeration) {
    super();

    this.enumeration = enumeration;

    try {
      this.icons = (ImageIcon[]) enumeration.getMethod("getIcons").invoke(null);
      for (int i = 0; i < icons.length; i++) {
        addItem(icons[i]);
      }
    } catch (NoSuchMethodException ex) {
      System.err.println(
          "The method 'getIcons()' is missing in enumeration " + enumeration.getName());
      ex.printStackTrace();
      System.exit(1);
    } catch (IllegalAccessException ex) {
      System.err.println(
          "Cannot access method 'getIcons()' in enumeration "
              + enumeration.getName()
              + ": ex.getMessage()");
      ex.printStackTrace();
      System.exit(1);
    } catch (InvocationTargetException ex) {
      ex.getCause().printStackTrace();
      System.exit(1);
    }
  }
Exemple #7
0
 /**
  * * 保存实体
  *
  * @param entity 实体类
  * @param keyName 实体类中获取主键的方法名字, 例如:getId<br>
  *     当为空时({@link StringUtils#isBlank(CharSequence)}),系统会自动找出注解有{@link
  *     javax.persistence.Id}的方法(即主键的get方法)
  * @return 返回保存实体的主键
  */
 public Object save(final T entity, String keyName) {
   entityManager.persist(entity);
   Object o = null;
   try {
     if (StringUtils.isNotBlank(keyName)) {
       o = clazz.getMethod(keyName).invoke(entity);
     } else {
       for (Method m1 : clazz.getMethods()) {
         if (m1.isAnnotationPresent(javax.persistence.Id.class)) {
           o = m1.invoke(entity);
           break;
         }
       }
     }
   } catch (SecurityException e) {
     e.printStackTrace();
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
   return o;
 }
  public void parseData(
      final Sheet sheet,
      final int startRow,
      final int endColumn,
      final List<String> propertyNames,
      final Class clazzOfTestCase) {

    int rowCounter = startRow;

    while (!isBlank(sheet, rowCounter, endColumn)) {
      Row row = sheet.getRow(rowCounter - 1);
      for (int i = 0; i < endColumn; i++) {
        Cell cell = row.getCell(i);
        if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
          try {
            Method method = clazzOfTestCase.getMethod("set" + propertyNames.get(i), Object.class);
          } catch (NoSuchMethodException e) {
            e
                .printStackTrace(); // To change body of catch statement use File | Settings | File
                                    // Templates.
          }
        }
      }
    }
  }
  public static String getValueAsString(Object bean, String property) {
    Object value = null;

    try {
      value = PropertyUtils.getProperty(bean, property);

    } catch (IllegalAccessException e) {
      Log log = LogFactory.getLog(CustomValidatorRules.class);
      log.error(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      Log log = LogFactory.getLog(CustomValidatorRules.class);
      log.error(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      Log log = LogFactory.getLog(CustomValidatorRules.class);
      log.error(e.getMessage(), e);
    }

    if (value == null) {
      return null;
    }

    if (value instanceof String[]) {
      return ((String[]) value).length > 0 ? value.toString() : "";

    } else if (value instanceof Collection) {
      return ((Collection) value).isEmpty() ? "" : value.toString();

    } else {
      return value.toString();
    }
  }
  private static String getFilePathByFileDialog(Shell shell, boolean isExport, String fileName) {
    try {
      final Class<EMFStoreFileDialogHelper> clazz =
          loadClass(EMFSTORE_CLIENT_UI_PLUGIN_ID, FILE_DIALOG_HELPER_CLASS);
      final EMFStoreFileDialogHelper fileDialogHelper = clazz.getConstructor().newInstance();

      if (isExport) {
        return fileDialogHelper.getPathForExport(shell, fileName);
      }

      return fileDialogHelper.getPathForImport(shell);
    } catch (final ClassNotFoundException ex) {
      WorkspaceUtil.logException(ex.getMessage(), ex);
    } catch (final InstantiationException ex) {
      WorkspaceUtil.logException(ex.getMessage(), ex);
    } catch (final IllegalAccessException ex) {
      WorkspaceUtil.logException(ex.getMessage(), ex);
    } catch (final IllegalArgumentException ex) {
      WorkspaceUtil.logException(ex.getMessage(), ex);
    } catch (final InvocationTargetException ex) {
      WorkspaceUtil.logException(ex.getMessage(), ex);
    } catch (final NoSuchMethodException ex) {
      WorkspaceUtil.logException(ex.getMessage(), ex);
    } catch (final SecurityException ex) {
      WorkspaceUtil.logException(ex.getMessage(), ex);
    }
    return null;
  }
  /**
   * Executes the sql sentence created by <code>getSql</code>.
   *
   * @param values the values
   * @return the list< map< string, object>>
   */
  protected List<Map<String, Object>> resolveLookups(Object[] values) {
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();

    try {
      IManagerBean bean = getForeignManagerBean();
      Criteria criteria = getCriteria(bean, values);
      List<ITransferObject> list = bean.getList(criteria);
      if (list.size() > 0) {
        List<String> alias = getAlias();
        for (ITransferObject to : list) {
          result.add(getToMap(to, alias));
        }
      }
    } catch (ManagerBeanException e) {
      LOGGER.severe(e.getMessage());
    } catch (IllegalAccessException e) {
      LOGGER.severe(e.getMessage());
    } catch (InvocationTargetException e) {
      LOGGER.severe(e.getMessage());
    } catch (NoSuchMethodException e) {
      LOGGER.severe(e.getMessage());
    } catch (ExpressionException e) {
      LOGGER.severe(e.getMessage());
    }

    return result;
  }
  ArrayList<Mob> getMobs() {
    ArrayList<Mob> realMobs = new ArrayList<Mob>();

    for (JsonMob jm : mobs) {

      Mob xyz = null;

      Class<?> cl;
      try {
        cl = Class.forName(jm.getName());

        Constructor<?> con = cl.getConstructor(float.class, float.class);
        xyz = (Mob) con.newInstance(jm.getX(), jm.getY());
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (SecurityException e) {
        e.printStackTrace();
      } catch (InstantiationException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }

      xyz.setID(jm.getID());

      realMobs.add(xyz);
    }
    return realMobs;
  }
 Engine() {
   super();
   prefs = GalleryWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
   prefs.registerOnSharedPreferenceChangeListener(this);
   this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_REPLACEIMAGE);
   this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_SYNC);
   onSharedPreferenceChanged(prefs, null);
   backgroundPaint.setFilterBitmap(false);
   backgroundPaint.setAntiAlias(true);
   backgroundPaint.setColor(Color.BLACK);
   textPaint.setAntiAlias(true);
   textPaint.setColor(Color.WHITE);
   textPaint.setShadowLayer(5f, 1f, 1f, Color.GRAY);
   textPaint.setSubpixelText(true);
   textPaint.setTextAlign(Paint.Align.LEFT);
   textPaint.setTextSize(18);
   textPaint.setTypeface(Typeface.MONOSPACE);
   this.setTouchEventsEnabled(true);
   if (Build.VERSION.SDK_INT >= 14) {
     try {
       // hinting = textPaint.HINTING_ON;
       int hinting = textPaint.getClass().getField("HINTING_ON").getInt(textPaint);
       // textPaint.setHinting(hinting);
       textPaint.getClass().getMethod("setHinting", int.class).invoke(textPaint, hinting);
     } catch (IllegalAccessException e) {
       System.err.println(e.toString());
     } catch (InvocationTargetException e) {
       System.err.println(e.toString());
     } catch (NoSuchMethodException e) {
       System.err.println(e.toString());
     } catch (NoSuchFieldException e) {
       System.err.println(e.toString());
     }
   }
 }
 public FastConstructor getConstructor(final Class[] parameterTypes) {
   try {
     return getConstructor(type.getConstructor(parameterTypes));
   } catch (final NoSuchMethodException e) {
     throw new NoSuchMethodError(e.getMessage());
   }
 }
 /**
  * 画像のExif情報から回転角度を取得する
  *
  * <pre>
  * // Original code for Android 2.1(API Level 5 Later)
  * int rotation = 0;
  * try {
  *     ExifInterface exif = new ExifInterface(fileName);
  *     int orientation = exif.getAttributeInt(
  *               ExifInterface.TAG_ORIENTATION, 1);
  *     switch (orientation) {
  *         case 6:
  *             rotation = 90;
  *             break;
  *     }
  * } catch (IOException e) {
  *     e.printStackTrace();
  * }
  * </pre>
  *
  * @param fileName 画像のファイル名(フルパス)
  * @return 回転角度(0、90、180、270)※単位は度
  */
 public static int getRotation(String fileName) {
   int rotation = 0;
   try {
     Class<?> clazz = ExifInterface.class;
     Constructor<?> constructor = clazz.getConstructor(String.class);
     Object instance = constructor.newInstance(fileName);
     Method method = clazz.getMethod("getAttributeInt", String.class, int.class);
     if (method != null) {
       rotation = (Integer) method.invoke(instance, "Orientation");
     }
   } catch (SecurityException e) {
     e.printStackTrace();
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
   return rotation;
 }
Exemple #16
0
  private Object getResults(Attribute attr, Object obj) {
    try {
      String name = attr.getID().toString();
      String Value = attr.get().toString();
      Class class1 = obj.getClass();
      String methodName =
          "set" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
      String[] methodnameIgnot = {"-"};
      for (String ignore : methodnameIgnot) {
        methodName = methodName.replaceAll(ignore, "");
      }
      Method method = class1.getMethod(methodName, String.class);

      String value = (String) method.invoke(obj, Value);

    } catch (NamingException e) {
      e.printStackTrace();
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
    return obj;
  }
  public static void pojoMappingUtility(Object pojo, Object origin) {

    Method[] methods = pojo.getClass().getDeclaredMethods();
    // System.out.printf("%d methods:%n", methods.length);

    // Method[] methods2 = origin.getClass().getDeclaredMethods();
    // System.out.printf("%d methodsOrigin:%n", methods2.length);

    for (Method method : methods) {

      // System.out.println(method.getName());
      if (method.getName().contains("set")) {
        String getMethodName = method.getName().replace("set", "get");
        try {
          method.invoke(pojo, origin.getClass().getDeclaredMethod(getMethodName).invoke(origin));
        } 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 (NoSuchMethodException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (SecurityException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
Exemple #18
0
 public String buildFilter(Object obj) {
   LOG.info("Inside buildFilter");
   Field[] fld = obj.getClass().getDeclaredFields();
   StringBuffer sb = new StringBuffer();
   for (Field flds : fld) {
     try {
       String name = flds.getName();
       Class class1 = obj.getClass();
       String methodName =
           "get" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
       Method method = class1.getMethod(methodName, null);
       String value = (String) method.invoke(obj, null);
       if (value != null && value.length() > 0) sb.append(name).append("=").append(value);
     } catch (IllegalArgumentException e) {
       e.printStackTrace();
     } catch (IllegalAccessException e) {
       e.printStackTrace();
     } catch (SecurityException e) {
       e.printStackTrace();
     } catch (NoSuchMethodException e) {
       e.printStackTrace();
     } catch (InvocationTargetException e) {
       e.printStackTrace();
     }
   }
   if (sb.length() > 0) {
     sb.substring(0, sb.length() - 1);
   }
   return sb.toString();
 }
  public static Object invokeStaticMethod(
      String class_name, String method_name, Class[] pareTyple, Object[] pareVaules) {

    try {
      Class obj_class = Class.forName(class_name);
      Method method = obj_class.getMethod(method_name, pareTyple);
      return method.invoke(null, pareVaules);
    } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  }
  /**
   * 将对象转换为XML报文字符串
   *
   * <p>
   * <li>通过java反射对象,将对象的每一个成员变量都转换成xml的标签
   * <li>然后将获取每个变量的值,放入标签之间
   *
   * @param obj 待转换对象
   * @return xml字符串
   */
  public static String obj2Xml(Object obj) {
    StringBuffer sb = new StringBuffer();
    try {
      Class clz = obj.getClass();
      Field[] fields = clz.getDeclaredFields();
      for (Field field : fields) {
        String fieldName = field.getName();
        sb.append("<" + fieldName + ">");
        String methodName = "get" + DataTools.stringUpdateFirst(field.getName());
        // 反射得到方法
        Method m = clz.getDeclaredMethod(methodName);
        // 通过反射调用set方法
        sb.append(m.invoke(obj));
        sb.append("</" + fieldName + ">");
      }
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }

    return sb.toString();
  }
  public static void main(String... args) {
    try {
      Class<?> c = Class.forName("ConstructorTroubleToo");
      // Method propagetes any exception thrown by the constructor
      // (including checked exceptions).
      if (args.length > 0 && args[0].equals("class")) {
        Object o = c.newInstance();
      } else {
        Object o = c.getConstructor().newInstance();
      }

      // production code should handle these exceptions more gracefully
    } catch (ClassNotFoundException x) {
      x.printStackTrace();
    } catch (InstantiationException x) {
      x.printStackTrace();
    } catch (IllegalAccessException x) {
      x.printStackTrace();
    } catch (NoSuchMethodException x) {
      x.printStackTrace();
    } catch (InvocationTargetException x) {
      x.printStackTrace();
      err.format("%n%nCaught exception: %s%n", x.getCause());
    }
  }
 public static XSingleComponentFactory __getComponentFactory(String sImplementationName) {
   String regClassesList = getRegistrationClasses();
   StringTokenizer t = new StringTokenizer(regClassesList, " ");
   while (t.hasMoreTokens()) {
     String className = t.nextToken();
     if (className != null && className.length() != 0) {
       try {
         Class regClass = Class.forName(className);
         Method writeRegInfo =
             regClass.getDeclaredMethod("__getComponentFactory", new Class[] {String.class});
         Object result = writeRegInfo.invoke(regClass, sImplementationName);
         if (result != null) {
           return (XSingleComponentFactory) result;
         }
       } catch (ClassNotFoundException ex) {
         ex.printStackTrace();
       } catch (ClassCastException ex) {
         ex.printStackTrace();
       } catch (SecurityException ex) {
         ex.printStackTrace();
       } catch (NoSuchMethodException ex) {
         ex.printStackTrace();
       } catch (IllegalArgumentException ex) {
         ex.printStackTrace();
       } catch (InvocationTargetException ex) {
         ex.printStackTrace();
       } catch (IllegalAccessException ex) {
         ex.printStackTrace();
       }
     }
   }
   return null;
 }
  static void testReflectionTest3() {
    try {
      String imei = taintedString();

      Class c = Class.forName("de.ecspride.ReflectiveClass");
      Object o = c.newInstance();
      Method m = c.getMethod("setIme" + "i", String.class);
      m.invoke(o, imei);

      Method m2 = c.getMethod("getImei");
      String s = (String) m2.invoke(o);

      assert (getTaint(s) != 0);
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NoSuchMethodException 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();
    }
  }
 public static boolean __writeRegistryServiceInfo(XRegistryKey xRegistryKey) {
   boolean bResult = true;
   String regClassesList = getRegistrationClasses();
   StringTokenizer t = new StringTokenizer(regClassesList, " ");
   while (t.hasMoreTokens()) {
     String className = t.nextToken();
     if (className != null && className.length() != 0) {
       try {
         Class regClass = Class.forName(className);
         Method writeRegInfo =
             regClass.getDeclaredMethod(
                 "__writeRegistryServiceInfo", new Class[] {XRegistryKey.class});
         Object result = writeRegInfo.invoke(regClass, xRegistryKey);
         bResult &= ((Boolean) result).booleanValue();
       } catch (ClassNotFoundException ex) {
         ex.printStackTrace();
       } catch (ClassCastException ex) {
         ex.printStackTrace();
       } catch (SecurityException ex) {
         ex.printStackTrace();
       } catch (NoSuchMethodException ex) {
         ex.printStackTrace();
       } catch (IllegalArgumentException ex) {
         ex.printStackTrace();
       } catch (InvocationTargetException ex) {
         ex.printStackTrace();
       } catch (IllegalAccessException ex) {
         ex.printStackTrace();
       }
     }
   }
   return bResult;
 }
  private static void applyGroupMatching(TestNG testng, Map options) throws TestSetFailedException {
    String groups = (String) options.get(ProviderParameterNames.TESTNG_GROUPS_PROP);
    String excludedGroups = (String) options.get(ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP);

    if (groups == null && excludedGroups == null) {
      return;
    }

    // the class is available in the testClassPath
    String clazzName = "org.apache.maven.surefire.testng.utils.GroupMatcherMethodSelector";
    // looks to need a high value
    testng.addMethodSelector(clazzName, 9999);
    try {
      Class clazz = Class.forName(clazzName);

      // HORRIBLE hack, but TNG doesn't allow us to setup a method selector instance directly.
      Method method = clazz.getMethod("setGroups", new Class[] {String.class, String.class});
      method.invoke(null, new Object[] {groups, excludedGroups});
    } catch (ClassNotFoundException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (SecurityException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    }
  }
Exemple #26
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 private Spell getSpellClass(int id, String name) {
   try {
     Object[] instanceArguments = new Object[] {id};
     Class[] constructorArguments = new Class[] {int.class};
     Class spellClass = Class.forName("com.ignoreourgirth.gary.oakmagic.spells." + name);
     Constructor spellConstructor = spellClass.getConstructor(constructorArguments);
     Object instancedClass = spellConstructor.newInstance(instanceArguments);
     Spell returnValue = (Spell) instancedClass;
     // OakMagic.log.info("Loaded: " + spellClass.getSimpleName());
     return returnValue;
   } catch (ClassNotFoundException ex) {
     OakMagic.log.log(Level.SEVERE, ex.getMessage());
   } catch (InstantiationException ex) {
     OakMagic.log.log(Level.SEVERE, ex.getMessage());
   } catch (IllegalAccessException ex) {
     OakMagic.log.log(Level.SEVERE, ex.getMessage());
   } catch (SecurityException ex) {
     OakMagic.log.log(Level.SEVERE, ex.getMessage());
   } catch (NoSuchMethodException ex) {
     OakMagic.log.log(Level.SEVERE, ex.getMessage());
   } catch (IllegalArgumentException ex) {
     OakMagic.log.log(Level.SEVERE, ex.getMessage());
   } catch (InvocationTargetException ex) {
     OakMagic.log.log(Level.SEVERE, ex.getMessage());
   }
   return null;
 }
Exemple #27
0
 /**
  * Get a method by name.
  * 
  * @param c  class object
  * @param methodName  method name
  * @param argTypes  argument types
  * @return  method object, or null if it does not exist
  */
 public static Method getDeclaredMethod(Class c, String methodName, Class[] argTypes) {
     Method m;
     try {
         if (argTypes != null) {
             m = c.getMethod(methodName, argTypes);
         } else {
             m = null;
             Method[] ms = c.getDeclaredMethods();
             for (int i = 0; i < ms.length; ++i) {
                 if (ms[i].getName().equals(methodName)) {
                     m = ms[i];
                     break;
                 }
             }
             if (m == null) {
                 System.err.println("Can't find "+c.getName()+"."+methodName);
                 return null;
             }
         }
         try {
             m.setAccessible(true);
         } catch (AccessControlException _) { }
     } catch (SecurityException e1) {
         System.err.println("Cannot access "+c.getName()+"."+methodName);
         e1.printStackTrace();
         return null;
     } catch (NoSuchMethodException e1) {
         System.err.println("Can't find "+c.getName()+"."+methodName);
         e1.printStackTrace();
         return null;
     }
     return m;
 }
  @Override
  public void openCamera(final int cameraId) {
    releaseCamera();

    if (sSharpCameraClass != null) {
      final Method openMethod;
      try {
        openMethod = sSharpCameraClass.getMethod("open", int.class);
      } catch (final NoSuchMethodException e) {
        throw new RuntimeException(e.getMessage(), e);
      }
      try {
        setCamera((Camera) openMethod.invoke(null, cameraId));
      } catch (final IllegalArgumentException e) {
        throw new RuntimeException(e.getMessage(), e);
      } catch (final IllegalAccessException e) {
        throw new RuntimeException(e.getMessage(), e);
      } catch (final InvocationTargetException e) {
        throw new RuntimeException(e.getMessage(), e);
      }
    } else if (cameraId != DEFAULT_CAMERA_ID) {
      throw new RuntimeException();
    } else {
      setCamera(Camera.open());
    }

    setCameraId(cameraId);
    initializeFocusMode();
  }
Exemple #29
0
  public void do_alarms() {

    // every entry may be re-added immediately after its method execution, so it's safe
    // to iterate over a copy of the hashmap
    HashMap<String, Integer> local_alarm = new HashMap<>(alarm);

    // iterate through the hashmap
    for (Map.Entry a : local_alarm.entrySet()) {
      if ((int) a.getValue() <= 0) {

        // remove the executed alarm
        alarm.remove(a.getKey().toString());

        // execute alarm method
        Method method;
        //noinspection TryWithIdenticalCatches
        try {
          method = this.getClass().getMethod("alarm_" + a.getKey());
          method.invoke(this);
        } catch (NoSuchMethodException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (InvocationTargetException e) {
          e.printStackTrace();
        }

      } else

        // decrease the alarm timer
        alarm.put(a.getKey().toString(), (int) a.getValue() - 1);
    }
  }
  /**
   * **
   *
   * @return 便利cursor, 为对象赋值
   */
  public static Object traversal(Cursor cursor, Class tableClass) {
    if (cursor.getCount() == 0) {
      Log.v("mine", "没有数据");
      return null;
    }

    GetInstances getInstances = new GetInstances(tableClass).invoke();
    if (getInstances.is()) return null;
    Object objectCopy = getInstances.getObjectCopy();
    Field[] fields = tableClass.getDeclaredFields();

    for (int i = 0; i < fields.length; i++) {
      Log.v("mine", fields[i].getName());
      String value = "";
      if (cursor.moveToNext()) value = cursor.getString(cursor.getColumnIndex(fields[i].getName()));
      String setMethodName = "set" + fields[i].getName();
      try {
        Method method = tableClass.getMethod(setMethodName, new Class[] {fields[i].getType()});
        try {
          method.invoke(objectCopy, new Object[] {value});
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (InvocationTargetException e) {
          e.printStackTrace();
        }
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      }
    }

    return objectCopy;
  }