Ejemplo n.º 1
1
  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);
    }
  }
Ejemplo n.º 2
0
  /**
   * @param row
   * @param string
   * @param column
   */
  private void addColumnLink(Vector row, Object userObject, Object column, int id)
      throws Exception {
    LinkCell cell = null;

    String methodName = null;
    if (((ColumnLink) column).getProperty().equals("")) {
      methodName = "toString";
    } else {
      methodName = PagerUtils.buildGetterName(((ColumnLink) column).getProperty());
    }

    try {
      Method method = userObject.getClass().getMethod(methodName, null);
      Object resultInvocation = method.invoke(userObject, null);

      if (resultInvocation != null && !resultInvocation.toString().trim().equals("")) {

        String label = null;

        if (((ColumnLink) column).getLabel() == null
            || ((ColumnLink) column).getLabel().trim().equals("")) {
          label = resultInvocation.toString().trim();
        } else {
          label = ((ColumnLink) column).getLabel();
        }

        cell = new LinkCell(label, ((ColumnLink) column).getLink() + id);
        // + resultInvocation.toString().trim());

        row.add(cell);
      } else {
        row.add(new ValueCell("-", ALIGN_CENTER));
      }

    } catch (SecurityException e) {
      e.printStackTrace();
      getLogger().error("TableTag::addColumnLink()::SecurityException::" + e.getMessage());
      throw new Exception(e.getMessage());
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
      getLogger().error("TableTag::addColumnLink()::NoSuchMethodException::" + e.getMessage());
      throw new Exception(e.getMessage());
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      getLogger().error("TableTag::addColumnLink()::IllegalArgumentException::" + e.getMessage());
      throw new Exception(e.getMessage());
    } catch (IllegalAccessException e) {
      e.printStackTrace();
      getLogger().error("TableTag::addColumnLink()::IllegalAccessException::" + e.getMessage());
      throw new Exception(e.getMessage());
    } catch (InvocationTargetException e) {
      e.printStackTrace();
      getLogger().error("TableTag::addColumnLink()::InvocationTargetException::" + e.getMessage());
      throw new Exception(e.getMessage());
    }

    // getLogger().debug("TableTag: fine addColumnLink()");
  }
  @Test
  public void testMethodInBaseClassIsAnnotated() {
    Method getUserId = null;

    try {
      getUserId = UserTutorial.class.getDeclaredMethod("getUserId");
    } catch (NoSuchMethodException e) {
      Assert.fail(
          "NoSuchMethodException thrown. Check SetupDbTestScripts.sql file: " + e.getMessage());
    }

    // getUserId.setAccessible(true);

    Annotation annt = getUserId.getAnnotation(XmlElement.class);
    Assert.assertNotNull(
        "@XmlElement annotation missing from UserTutorial.getUserId() method", annt);

    String name = ((XmlElement) annt).name();
    boolean required = ((XmlElement) annt).required();

    Assert.assertEquals(
        "name attribute of the @XmlElement annotation is wrong or missing in UserTutorial.getUserId() method",
        "userId",
        name);

    Assert.assertTrue(
        "required attribute of @XmlElement annotation is wrong or missing in UserTutorial.getUserId() method",
        required);
  }
  @Test
  public void testPrimaryKeyMethodXmlAttributeNotInKeyClass() {
    Method getUserTutorialId = null;

    Class<UserTutorial> cls = UserTutorial.class;

    try {
      getUserTutorialId = cls.getDeclaredMethod("getUserTutorialId");
    } catch (NoSuchMethodException e) {
      Assert.fail(
          "NoSuchMethodException thrown. Check MyBatisGeneratorConfig.xml: " + e.getMessage());
    }

    // getUserTutorialId.setAccessible(true);

    Annotation annt = getUserTutorialId.getAnnotation(XmlAttribute.class);
    Assert.assertNotNull(
        "@XmlAttribute annotation missing from UserTutorial.getUserTutorialId() method", annt);

    String name = ((XmlAttribute) annt).name();
    boolean required = ((XmlAttribute) annt).required();

    Assert.assertEquals(
        "name attribute of the @XmlAttribute annotation is wrong or missing in UserTutorial.getUserTutorialId() method",
        "tutorialId",
        name);

    Assert.assertTrue(
        "required attribute of @XmlAttribute annotation is wrong or missing in UserTutorial.getUserTutorialId() method",
        required);
  }
  @Test
  public void testGetNarrativeMethodNotAnnotatedInBlobsClass() {
    Method getNarrative = null;

    try {
      getNarrative = UserTutorialWithBLOBs.class.getDeclaredMethod("getNarrative");
    } catch (NoSuchMethodException e) {
      Assert.fail(
          "NoSuchMethodException thrown. Check SetupDbTestScripts.sql file: " + e.getMessage());
    }

    // getNarrative.setAccessible(true);

    Annotation annt = getNarrative.getAnnotation(XmlElement.class);
    Assert.assertNotNull(
        "UserTutorialWithBLOBs.getNarrative() method should be annotated, but it isn't.", annt);

    String name = ((XmlElement) annt).name();
    boolean required = ((XmlElement) annt).required();

    Assert.assertEquals(
        "The name attribute of @XmlElement of UserTutorialWithBLOBs.getNarrative() method is wrong.",
        "TheFullContent",
        name);

    Assert.assertFalse(
        "The required attribute of @XmlElement of UserTutorialWithBLOBs.getNarrative() method should be false but it isn't.",
        required);
  }
Ejemplo n.º 6
0
  /**
   * Creates an instance of an event class using a config which may be new or recycled from an
   * existing event, possibly of another type
   *
   * @param theClass
   * @param theTest
   * @param theInitialConfig
   * @return
   */
  public AbstractEvent createEvent(
      Class<? extends AbstractEvent> theClass, TestImpl theTest, Event theInitialConfig)
      throws ConfigurationException {
    Class<? extends Event> configType = myEventClasses2ConfigTypes.get(theClass);

    try {
      Constructor<? extends AbstractEvent> constructor =
          theClass.getConstructor(TestImpl.class, configType);
      final Event convertConfig = convertConfig(theInitialConfig, configType);
      AbstractEvent event = constructor.newInstance(theTest, convertConfig);

      return event;
    } catch (InstantiationException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (IllegalAccessException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (IllegalArgumentException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (InvocationTargetException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (NoSuchMethodException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (SecurityException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    }
  }
Ejemplo n.º 7
0
  /**
   * Creates the appropriate editor form for the given event type
   *
   * @throws InstantiationException If the form can't be created for any reason
   */
  public <T extends AbstractEvent, V extends AbstractEventEditorForm> V createEditorForm(
      EventEditorContextController theController, T event) throws ConfigurationException {
    Class<V> formClass = (Class<V>) myEventClasses2EditorForm.get(event.getClass());

    if (formClass == null) {
      throw new ConfigurationException("No editor for " + event.getClass());
    }

    try {
      Constructor<V> constructor = formClass.getConstructor();
      V instance = constructor.newInstance();
      instance.setController(theController);

      return instance;
    } catch (InstantiationException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (IllegalAccessException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (IllegalArgumentException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (InvocationTargetException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (NoSuchMethodException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    } catch (SecurityException ex) {
      throw new ConfigurationException(ex.getMessage(), ex);
    }
  }
Ejemplo n.º 8
0
  /** Performs peephole optimizations on a program's live methods. */
  private static void peephole(final BloatContext context) {

    final Set liveMethods = new TreeSet(new MemberRefComparator());
    final CallGraph cg = context.getCallGraph();
    liveMethods.addAll(cg.liveMethods());

    // Perform peephole optimizations. We do this separately because
    // some peephole optimizations do things to the stack that
    // inlining doesn't like. For instance, a peephole optimizations
    // might make it so that a method has a non-empty stack upon
    // return. Inlining will barf at the sight of this.
    BloatBenchmark.tr("Performing peephole optimizations");

    final Iterator iter = liveMethods.iterator();
    while (BloatBenchmark.PEEPHOLE && iter.hasNext()) {
      try {
        final MethodEditor live = context.editMethod((MemberRef) iter.next());
        Peephole.transform(live);
        context.commit(live.methodInfo());
        context.release(live.methodInfo());

      } catch (final NoSuchMethodException ex314) {
        BloatBenchmark.err.println("** Could not find method " + ex314.getMessage());
        ex314.printStackTrace(System.err);
        System.exit(1);
      }
    }
  }
Ejemplo n.º 9
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  private static synchronized Map handlerClass(Class clazz) {

    if (classMap.containsKey(clazz.getName())) {
      return (Map) classMap.get(clazz.getName());
    }

    Map retMap = new HashMap();
    Field[] fields = clazz.getDeclaredFields();
    for (Field f : fields) {
      String name = f.getName();

      try {
        Method getMe =
            clazz.getMethod("get" + name.substring(0, 1).toUpperCase() + name.substring(1));

        Method setMe =
            clazz.getMethod(
                "set" + name.substring(0, 1).toUpperCase() + name.substring(1),
                getMe.getReturnType());

        retMap.put(name + "_setMethod", setMe);
        retMap.put(name + "_getMethod", getMe);
        retMap.put(name + "_returnType", getMe.getReturnType().getName());
      } catch (SecurityException e) {
        logger.error(e.getMessage(), e);
      } catch (NoSuchMethodException e) {
        logger.error(e.getMessage(), e);
      }
    }
    classMap.put(clazz.getName(), retMap);

    return retMap;
  }
  /**
   * This method does the work of creating an instance of the class given the URL of the wsdl
   * provided in the constructor. This is actually type-safe, so the fact that "abort" if anything
   * goes wrong should never happen.
   */
  protected void init() {
    try {
      URL url = WSDLService.getURLForWSDL(wsdl);
      Constructor<S> constructor = clazzS.getConstructor(URL.class);
      service = constructor.newInstance(url);

    } catch (SecurityException e) {
      throw new RuntimeException(
          "You supplied a bad *service*/port pair (Security):" + e.getMessage());
    } catch (NoSuchMethodException e) {
      throw new RuntimeException(
          "You supplied a bad *service*/port pair (NoSuchMethod):" + e.getMessage());
    } catch (IllegalArgumentException e) {
      throw new RuntimeException(
          "You supplied a bad *service*/port pair (IllegalArgument):" + e.getMessage());
    } catch (IllegalAccessException e) {
      throw new RuntimeException(
          "You supplied a bad *service*/port pair (IllegalAccess):" + e.getMessage());
    } catch (InvocationTargetException e) {
      throw new RuntimeException(
          "You supplied a bad *service*/port pair (InvocationTarget):" + e.getMessage());
    } catch (InstantiationException e) {
      throw new RuntimeException(
          "You supplied a bad *service*/port pair (Instantiation):" + e.getMessage());
    }
  }
Ejemplo n.º 11
0
 public void init() {
   UpdateService updateService = (UpdateService) ApplicationUtil.getBean("updateService");
   methodMap.clear();
   classMap.clear();
   List<Map<String, Object>> list = updateService.find("select * from " + AUCalcFormula.TB__NAME);
   for (Map<String, Object> map : list) {
     try {
       @SuppressWarnings("unchecked")
       Class<CalcFormula> c =
           (Class<CalcFormula>) Class.forName(map.get("FormulaInterface").toString());
       Method m = c.getDeclaredMethod("execute", String.class, String.class);
       classMap.put(map.get("RecordID").toString(), c);
       methodMap.put(map.get("RecordID").toString(), m);
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
       logger.error(
           "AUDependCalc init ClassNotFoundException ERROR[{}], DETAIL{}", e.getMessage(), e);
     } catch (SecurityException e) {
       e.printStackTrace();
       logger.error("AUDependCalc init SecurityException ERROR[{}], DETAIL{}", e.getMessage(), e);
     } catch (NoSuchMethodException e) {
       e.printStackTrace();
       logger.error(
           "AUDependCalc init NoSuchMethodException ERROR[{}], DETAIL{}", e.getMessage(), e);
     }
   }
 }
 @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);
   }
 }
Ejemplo n.º 13
0
 protected T createProviderInstanceFromType(
     final Class<? extends T> execClass, final String providerName)
     throws ProviderCreationException {
   boolean ctrfound = true;
   try {
     final Constructor<? extends T> method =
         execClass.getDeclaredConstructor(new Class[] {Framework.class});
     final T executor = method.newInstance(framework);
     return executor;
   } catch (NoSuchMethodException e) {
     ctrfound = false;
   } catch (Exception e) {
     throw new ProviderCreationException(
         "Unable to create provider instance: " + e.getMessage(), e, getName(), providerName);
   }
   try {
     final Constructor<? extends T> method = execClass.getDeclaredConstructor(new Class[0]);
     final T executor = method.newInstance();
     return executor;
   } catch (NoSuchMethodException e) {
     throw new ProviderCreationException(
         "No constructor found with signature (Framework) or (): " + e.getMessage(),
         e,
         getName(),
         providerName);
   } catch (Exception e) {
     throw new ProviderCreationException(
         "Unable to create provider instance: " + e.getMessage(), e, getName(), providerName);
   }
 }
Ejemplo n.º 14
0
 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());
   }
 }
 private Object readSetting(java.io.Reader input, Object inst) throws IOException {
   try {
     java.lang.reflect.Method m =
         inst.getClass()
             .getDeclaredMethod("readProperties", new Class[] {Properties.class}); // NOI18N
     m.setAccessible(true);
     XMLPropertiesConvertor.Reader r = new XMLPropertiesConvertor.Reader();
     r.parse(input);
     m.setAccessible(true);
     Object ret = m.invoke(inst, new Object[] {r.getProperties()});
     if (ret == null) {
       ret = inst;
     }
     return ret;
   } catch (NoSuchMethodException ex) {
     IOException ioe = new IOException(ex.getMessage());
     ioe.initCause(ex);
     throw ioe;
   } catch (IllegalAccessException ex) {
     IOException ioe = new IOException(ex.getMessage());
     ioe.initCause(ex);
     throw ioe;
   } catch (java.lang.reflect.InvocationTargetException ex) {
     Throwable t = ex.getTargetException();
     IOException ioe = new IOException(ex.getMessage());
     ioe.initCause(t);
     throw ioe;
   }
 }
Ejemplo n.º 16
0
  private void begin() {
    // copy text from the component with keyboard focus
    Component keyboardComp =
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();

    if (keyboardComp != null && keyboardComp instanceof JTextComponent) {
      JTextComponent textComp = (JTextComponent) keyboardComp;
      textComp.copy();
    } else {
      // if it was not a text component, see if we have the cut
      // method available
      Method copyMethod = null;
      try {
        copyMethod = keyboardComp.getClass().getMethod("copy", new Class[0]);
      } catch (SecurityException ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
      } catch (NoSuchMethodException ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
      }

      if (copyMethod != null) {
        try {
          copyMethod.invoke(keyboardComp, new Object[0]);
        } catch (IllegalArgumentException ex) {
          LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
        } catch (IllegalAccessException ex) {
          LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
        } catch (InvocationTargetException ex) {
          LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
        }
      }
    }
  }
Ejemplo n.º 17
0
 private void assertRGOReference(
     NonRootModelElement rgo, NonRootModelElement rto, boolean defaultReference) {
   Method defaultMethod;
   try {
     defaultMethod = getDefaultReferenceMethod(rgo, rto);
     Object result = defaultMethod.invoke(rgo, new Object[0]);
     if (defaultReference) {
       assertTrue(
           "After a cut the RGO of type "
               + rgo.getClass().getSimpleName()
               + " was not referring to default RTO.",
           ((Boolean) result).booleanValue());
     } else {
       assertFalse(
           "After a paste the RGO of type "
               + rgo.getClass().getSimpleName()
               + " was referring to default RTO.",
           ((Boolean) result).booleanValue());
     }
   } catch (SecurityException e) {
     fail(e.getMessage());
   } catch (NoSuchMethodException e) {
     fail(e.getMessage());
   } catch (IllegalArgumentException e) {
     fail(e.getMessage());
   } catch (IllegalAccessException e) {
     fail(e.getMessage());
   } catch (InvocationTargetException e) {
     fail(e.getMessage());
   }
 }
Ejemplo n.º 18
0
 public FastConstructor getConstructor(final Class[] parameterTypes) {
   try {
     return getConstructor(type.getConstructor(parameterTypes));
   } catch (final NoSuchMethodException e) {
     throw new NoSuchMethodError(e.getMessage());
   }
 }
Ejemplo n.º 19
0
  /**
   * 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;
  }
Ejemplo n.º 20
0
 public WebAppIdPManager getIdpManager() throws AppManagementException {
   if (idpManager == null) {
     String className =
         config.getFirstProperty(AppMConstants.SSO_CONFIGURATION_IDENTITY_PROVIDER_MANAGER);
     try {
       idpManager =
           (WebAppIdPManager)
               Class.forName(className)
                   .getConstructor(AppManagerConfiguration.class)
                   .newInstance(config);
     } catch (InstantiationException e) {
       log.error(e);
       throw new AppManagementException(e.getMessage());
     } catch (IllegalAccessException e) {
       log.error(e);
       throw new AppManagementException(e.getMessage());
     } catch (IllegalArgumentException e) {
       e.printStackTrace();
     } catch (InvocationTargetException e) {
       log.error(e);
       throw new AppManagementException(e.getMessage());
     } catch (NoSuchMethodException e) {
       log.error(e);
       throw new AppManagementException(e.getMessage());
     } catch (SecurityException e) {
       log.error(e);
       throw new AppManagementException(e.getMessage());
     } catch (ClassNotFoundException e) {
       log.error(e);
       throw new AppManagementException(e.getMessage());
     }
   }
   return idpManager;
 }
Ejemplo n.º 21
0
  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);
    }
  }
Ejemplo n.º 22
0
  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);
    }
  }
Ejemplo n.º 23
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;
 }
Ejemplo n.º 24
0
  @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();
  }
Ejemplo n.º 25
0
  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();
    }
  }
Ejemplo n.º 26
0
  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;
  }
Ejemplo n.º 27
0
  public synchronized Object getJavaClassInstance(Class<?> clazz) {
    Object instance = instanceCache.get(clazz);
    if (instance != null) {
      return instance;
    }

    try {
      Constructor<?> constructor = clazz.getConstructor(IValueFactory.class);
      instance = constructor.newInstance(vf);
      instanceCache.put(clazz, instance);
      return instance;
    } catch (IllegalArgumentException e) {
      throw new ImplementationError(e.getMessage(), e);
    } catch (InstantiationException e) {
      throw new ImplementationError(e.getMessage(), e);
    } catch (IllegalAccessException e) {
      throw new ImplementationError(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      throw new ImplementationError(e.getMessage(), e);
    } catch (SecurityException e) {
      throw new ImplementationError(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      throw new ImplementationError(e.getMessage(), e);
    }
  }
Ejemplo n.º 28
0
  /**
   * This is a complement to the normal webwork execution which allows for a command-based execution
   * of actions.
   */
  private String invokeCommand() throws Exception {
    Timer t = new Timer();

    final StringBuffer methodName = new StringBuffer("do" + this.commandName);
    methodName.setCharAt(2, Character.toUpperCase(methodName.charAt(2)));

    String result = "";

    try {
      final Method method = getClass().getMethod(methodName.toString(), new Class[0]);
      result = (String) method.invoke(this, new Object[0]);
      setStandardResponseHeaders();
    } catch (NoSuchMethodException e) {
      logger.warn("No such method in:" + getRequest().getRequestURI() + ":" + e.getMessage());
    } catch (Exception ie) {
      if (ie.getMessage() != null) logger.error("Exception in top action:" + ie.getMessage(), ie);

      try {
        throw ie.getCause();
      } catch (ResultException e) {
        logger.error("ResultException " + e, e);
        result = e.getResult();
      } catch (AccessConstraintException e) {
        logger.info("AccessConstraintException " + e, e);
        setErrors(e);
        result = ACCESS_DENIED;
      } catch (ConstraintException e) {
        logger.info("ConstraintException " + e, e);
        setErrors(e);
        if (e.getResult() != null && !e.getResult().equals("")) result = e.getResult();
        else result = INPUT;
      } catch (Bug e) {
        logger.error("Bug " + e.getMessage(), e);
        setError(e, e.getCause());
        result = ERROR;
      } catch (ConfigurationError e) {
        logger.error("ConfigurationError " + e);
        setError(e, e.getCause());
        result = ERROR;
      } catch (SystemException e) {
        logger.error("SystemException " + e, e);
        setError(e, e.getCause());
        result = ERROR;
      } catch (Throwable e) {
        logger.error("Throwable " + e.getMessage(), e);
        final Bug bug = new Bug("Uncaught exception!", e);
        setError(bug, bug.getCause());
        result = ERROR;
      }
    }

    try {
      ChangeNotificationController.notifyListeners();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return result;
  }
Ejemplo n.º 29
0
 /** 获得field的getter函数,如果找不到该方法,返回null. */
 public static Method getGetterMethod(Class type, String fieldName) {
   try {
     return type.getMethod(getGetterName(type, fieldName));
   } catch (NoSuchMethodException e) {
     logger.error(e.getMessage(), e);
   }
   return null;
 }
Ejemplo n.º 30
0
 /** Static setup */
 static {
   try {
     class_print_method =
         NameID.class.getMethod("defaultPrint", new Class<?>[] {NameID.class, PrintWriter.class});
   } catch (NoSuchMethodException e) {
     throw new InternalError(e.getMessage());
   }
 }