Esempio n. 1
1
 /**
  * Factory method, equivalent to a "fromXML" for step creation. Looks for a class with the same
  * name as the XML tag, with the first letter capitalized. For example, <call /> is
  * abbot.script.Call.
  */
 public static Step createStep(Resolver resolver, Element el) throws InvalidScriptException {
   String tag = el.getName();
   Map attributes = createAttributeMap(el);
   String name = tag.substring(0, 1).toUpperCase() + tag.substring(1);
   if (tag.equals(TAG_WAIT)) {
     attributes.put(TAG_WAIT, "true");
     name = "Assert";
   }
   try {
     name = "abbot.script." + name;
     Log.debug("Instantiating " + name);
     Class cls = Class.forName(name);
     try {
       // Steps with contents require access to the XML element
       Class[] argTypes = new Class[] {Resolver.class, Element.class, Map.class};
       Constructor ctor = cls.getConstructor(argTypes);
       return (Step) ctor.newInstance(new Object[] {resolver, el, attributes});
     } catch (NoSuchMethodException nsm) {
       // All steps must support this ctor
       Class[] argTypes = new Class[] {Resolver.class, Map.class};
       Constructor ctor = cls.getConstructor(argTypes);
       return (Step) ctor.newInstance(new Object[] {resolver, attributes});
     }
   } catch (ClassNotFoundException cnf) {
     String msg = Strings.get("step.unknown_tag", new Object[] {tag});
     throw new InvalidScriptException(msg);
   } catch (InvocationTargetException ite) {
     Log.warn(ite);
     throw new InvalidScriptException(ite.getTargetException().getMessage());
   } catch (Exception exc) {
     Log.warn(exc);
     throw new InvalidScriptException(exc.getMessage());
   }
 }
Esempio n. 2
0
 public void callValidator(final AQuery $, final Ajax ajax) throws VolleyError {
   Map<Annotation, java.lang.reflect.Method> method =
       ReflectUtils.getMethodsByAnnotation(Handler.class, getClass());
   for (Map.Entry<Annotation, java.lang.reflect.Method> entry : method.entrySet()) {
     try {
       entry
           .getValue()
           .invoke(
               this,
               ReflectUtils.fillParamsByAnnotations(
                   entry.getValue(),
                   new ReflectUtils.ParamInjector() {
                     @Override
                     public Object onInject(
                         Class paramType, List<? extends Annotation> annotations, int position) {
                       try {
                         return scanAnnotation($, paramType, annotations.get(0), ajax);
                       } catch (Exception e) {
                         $.log.i(e);
                         return null;
                       }
                     }
                   }));
     } catch (InvocationTargetException e) {
       if (e.getTargetException() instanceof VolleyError) {
         throw ((VolleyError) e.getTargetException());
       }
       $.log.i(e.getTargetException());
     } catch (Exception e) {
       $.log.i(e);
     }
   }
 }
Esempio n. 3
0
  public static final void fireEvent(GenericEvent e, Method m, Vector listeners)
      throws PropertyVetoException {
    Object[] snapshot = null;

    synchronized (listeners) {
      snapshot = new Object[listeners.size()];
      listeners.copyInto(snapshot);
    }

    // leighd 04/14/99 - modified for event debugging
    if (gDebugEvents) Engine.debugLog("Event : " + e.toString());

    Object params[] = new Object[] {e};

    for (int i = 0; i < snapshot.length; i++) {
      if ((e instanceof Consumable) && ((Consumable) e).isConsumed()) {
        // leighd 04/14/99
        // note that we don't catch the consumption of the
        // event until we've passed through the loop again,
        // so we reference i-1
        if (gDebugEvents) Engine.debugLog("Consumed By : " + snapshot[i - 1]);
        return;
      }
      try {
        m.invoke(snapshot[i], params);
      } catch (IllegalAccessException iae) {
        iae.printStackTrace();
      } catch (InvocationTargetException ite) {
        Throwable t = ite.getTargetException();
        if (t instanceof PropertyVetoException) throw ((PropertyVetoException) t);
        else t.printStackTrace();
      }
    }
  }
  private BrowserLauncher createBrowserLauncher(
      Class c, String browserStartCommand, String sessionId, SeleneseQueue queue) {
    try {
      BrowserLauncher browserLauncher;
      if (null == browserStartCommand) {
        Constructor ctor = c.getConstructor(new Class[] {int.class, String.class});
        Object[] args = new Object[] {new Integer(server.getPort()), sessionId};
        browserLauncher = (BrowserLauncher) ctor.newInstance(args);
      } else {
        Constructor ctor = c.getConstructor(new Class[] {int.class, String.class, String.class});
        Object[] args =
            new Object[] {
              new Integer(SeleniumServer.getPortDriversShouldContact()),
              sessionId,
              browserStartCommand
            };
        browserLauncher = (BrowserLauncher) ctor.newInstance(args);
      }

      if (browserLauncher instanceof SeleneseQueueAware) {
        ((SeleneseQueueAware) browserLauncher).setSeleneseQueue(queue);
      }

      return browserLauncher;
    } catch (InvocationTargetException e) {
      throw new RuntimeException(
          "failed to contruct launcher for "
              + browserStartCommand
              + "for"
              + e.getTargetException());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Esempio n. 5
0
 /**
  * This method is called when 'Finish' button is pressed in the wizard. We will create an
  * operation and run it using wizard as execution context.
  */
 public boolean performFinish() {
   final String containerName = page.getContainerName();
   final String fileName = page.getFileName();
   IRunnableWithProgress op =
       new IRunnableWithProgress() {
         public void run(IProgressMonitor monitor) throws InvocationTargetException {
           try {
             doFinish(containerName, fileName, monitor);
           } catch (CoreException e) {
             throw new InvocationTargetException(e);
           } finally {
             monitor.done();
           }
         }
       };
   try {
     getContainer().run(true, false, op);
   } catch (InterruptedException e) {
     return false;
   } catch (InvocationTargetException e) {
     Throwable realException = e.getTargetException();
     MessageDialog.openError(getShell(), "Error", realException.getMessage());
     return false;
   }
   return true;
 }
Esempio n. 6
0
  /**
   * Set the object to be edited.
   *
   * @param value The object to be edited.
   */
  public void setObject(Object value) {
    if (!(_type.isInstance(value))) {
      throw new IllegalArgumentException(value.getClass() + " is not of type " + _type);
    }
    _value = value;

    // Disable event generation.
    _squelchChangeEvents = true;

    // Iterate over each property, doing a lookup on the associated editor
    // and setting the editor's value to the value of the property.
    Iterator it = _prop2Editor.keySet().iterator();
    while (it.hasNext()) {
      PropertyDescriptor desc = (PropertyDescriptor) it.next();
      PropertyEditor editor = (PropertyEditor) _prop2Editor.get(desc);
      Method reader = desc.getReadMethod();
      if (reader != null) {
        try {
          Object val = reader.invoke(_value, null);
          editor.setValue(val);
        } catch (IllegalAccessException ex) {
          ex.printStackTrace();
        } catch (InvocationTargetException ex) {
          ex.getTargetException().printStackTrace();
        }
      }
    }

    // Enable event generation.
    _squelchChangeEvents = false;
  }
Esempio n. 7
0
 /** evaluate the link function */
 public static Data link(VMethod m, Object[] o) throws VisADException {
   Data ans = null;
   if (o != null) {
     for (int i = 0; i < o.length; i++) {
       // convert VRealTypes to RealTypes
       if (o[i] instanceof VRealType) {
         o[i] = ((VRealType) o[i]).getRealType();
       }
     }
   }
   try {
     ans = (Data) FormulaUtil.invokeMethod(m.getMethod(), o);
   } catch (ClassCastException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
     throw new VisADException("Link error: invalid linked method");
   } catch (IllegalAccessException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
     throw new VisADException("Link error: cannot access linked method");
   } catch (IllegalArgumentException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
     throw new VisADException("Link error: bad method argument");
   } catch (InvocationTargetException exc) {
     if (FormulaVar.DEBUG) exc.getTargetException().printStackTrace();
     throw new VisADException("Link error: linked method threw an exception");
   }
   if (ans == null) {
     throw new VisADException("Link error: linked method returned null data");
   }
   return ans;
 }
Esempio n. 8
0
  /**
   * Send an event to all registered listeners, except the named one.
   *
   * @param event the event to be sent: public void method_name( event_class event)
   */
  public void sendEventExcludeSource(java.util.EventObject event) {
    if (!hasListeners) {
      return;
    }

    Object source = event.getSource();
    Object[] args = new Object[1];
    args[0] = event;

    // send event to all listeners except the source
    ListIterator iter = listeners.listIterator();
    while (iter.hasNext()) {
      Object client = iter.next();
      if (client == source) {
        continue;
      }

      try {
        method.invoke(client, args);
      } catch (IllegalAccessException e) {
        iter.remove();
        System.err.println("ListenerManager IllegalAccessException = " + e);
      } catch (IllegalArgumentException e) {
        iter.remove();
        System.err.println("ListenerManager IllegalArgumentException = " + e);
      } catch (InvocationTargetException e) {
        iter.remove();
        System.err.println("ListenerManager InvocationTargetException on " + method);
        System.err.println("   threw exception " + e.getTargetException());
        e.printStackTrace();
      }
    }
  }
  /**
   * Provides default implementation for execution of grid-enabled methods. This method assumes that
   * argument passed in is of {@link GridifyArgument} type. It attempts to reflectively execute a
   * method based on information provided in the argument and returns the return value of the
   * method.
   *
   * <p>If some exception occurred during execution, then it will be thrown out of this method.
   *
   * @return {@inheritDoc}
   * @throws GridException {@inheritDoc}
   */
  @Override
  public Object execute() throws GridException {
    GridifyArgument arg = argument(0);

    try {
      // Get public, package, protected, or private method.
      Method mtd =
          arg.getMethodClass()
              .getDeclaredMethod(arg.getMethodName(), arg.getMethodParameterTypes());

      // Attempt to soften access control in case we grid-enabling
      // non-accessible method. Subject to security manager setting.
      if (!mtd.isAccessible())
        try {
          mtd.setAccessible(true);
        } catch (SecurityException e) {
          throw new GridException(
              "Got security exception when attempting to soften access control for "
                  + "@Gridify method: "
                  + mtd,
              e);
        }

      Object obj = null;

      // No need to create an instance for static methods.
      if (!Modifier.isStatic(mtd.getModifiers()))
        // Obtain instance to execute method on.
        obj = arg.getTarget();

      return mtd.invoke(obj, arg.getMethodParameters());
    } catch (InvocationTargetException e) {
      if (e.getTargetException() instanceof GridException)
        throw (GridException) e.getTargetException();

      throw new GridException(
          "Failed to invoke a method due to user exception.", e.getTargetException());
    } catch (IllegalAccessException e) {
      throw new GridException("Failed to access method for execution.", e);
    } catch (NoSuchMethodException e) {
      throw new GridException("Failed to find method for execution.", e);
    }
  }
Esempio n. 10
0
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
   try {
     String method = m.getName();
     if ("prepareStatement".equals(method) || "createStatement".equals(method))
       log.info("[SQL] >>> " + args[0]);
     return m.invoke(conn, args);
   } catch (InvocationTargetException e) {
     throw e.getTargetException();
   }
 }
Esempio n. 11
0
 /** invoke the test method */
 protected void invokeTest() throws Throwable {
   Method method = this.methodNamed(this.getZName());
   try {
     method.invoke(this, new Object[0]);
   } catch (IllegalAccessException iae) {
     throw new RuntimeException("The method '" + method + "' (and its class) must be public.");
   } catch (InvocationTargetException ite) {
     ite.fillInStackTrace();
     throw ite.getTargetException();
   }
 }
 // todo: equals implementation
 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
   Object result;
   try {
     result = m.invoke(this, args);
   } catch (InvocationTargetException e) {
     throw e.getTargetException();
   } catch (Exception e) {
     throw new RuntimeException("unexpected invocation exception: " + e.getMessage());
   } finally {
   }
   return result;
 }
Esempio n. 13
0
  /**
   * This creates a new <code>{@link Document}</code> from an existing <code>InputStream</code> by
   * letting a DOM parser handle parsing using the supplied stream.
   *
   * @param in <code>InputStream</code> to parse.
   * @param validate <code>boolean</code> to indicate if validation should occur.
   * @return <code>Document</code> - instance ready for use.
   * @throws IOException when I/O error occurs.
   * @throws JDOMException when errors occur in parsing.
   */
  public Document getDocument(InputStream in, boolean validate) throws IOException, JDOMException {

    try {
      // Load the parser class
      Class parserClass = Class.forName("org.apache.xerces.parsers.DOMParser");
      Object parser = parserClass.newInstance();

      // Set validation
      Method setFeature =
          parserClass.getMethod("setFeature", new Class[] {java.lang.String.class, boolean.class});
      setFeature.invoke(
          parser, new Object[] {"http://xml.org/sax/features/validation", new Boolean(validate)});

      // Set namespaces true
      setFeature.invoke(
          parser, new Object[] {"http://xml.org/sax/features/namespaces", new Boolean(true)});

      // Set the error handler
      if (validate) {
        Method setErrorHandler =
            parserClass.getMethod("setErrorHandler", new Class[] {ErrorHandler.class});
        setErrorHandler.invoke(parser, new Object[] {new BuilderErrorHandler()});
      }

      // Parse the document
      Method parse = parserClass.getMethod("parse", new Class[] {org.xml.sax.InputSource.class});
      parse.invoke(parser, new Object[] {new InputSource(in)});

      // Get the Document object
      Method getDocument = parserClass.getMethod("getDocument", null);
      Document doc = (Document) getDocument.invoke(parser, null);

      return doc;
    } catch (InvocationTargetException e) {
      Throwable targetException = e.getTargetException();
      if (targetException instanceof org.xml.sax.SAXParseException) {
        SAXParseException parseException = (SAXParseException) targetException;
        throw new JDOMException(
            "Error on line "
                + parseException.getLineNumber()
                + " of XML document: "
                + parseException.getMessage(),
            e);
      } else if (targetException instanceof IOException) {
        IOException ioException = (IOException) targetException;
        throw ioException;
      } else {
        throw new JDOMException(targetException.getMessage(), e);
      }
    } catch (Exception e) {
      throw new JDOMException(e.getClass().getName() + ": " + e.getMessage(), e);
    }
  }
Esempio n. 14
0
 /** Try to create a Java object using a one-string-param constructor. */
 public static Object newStringConstructor(String type, String param) throws Exception {
   Constructor c = Utils.getClass(type).getConstructor(String.class);
   try {
     return c.newInstance(param);
   } catch (InvocationTargetException e) {
     Throwable t = e.getTargetException();
     if (t instanceof Exception) {
       throw (Exception) t;
     } else {
       throw e;
     }
   }
 }
 @Override
 public T create() {
   Class<T> concreteClass = type.getConcreteClass();
   try {
     Constructor<T> declaredConstructor = concreteClass.getDeclaredConstructor();
     declaredConstructor.setAccessible(true);
     return declaredConstructor.newInstance();
   } catch (InvocationTargetException e) {
     throw UncheckedException.throwAsUncheckedException(e.getTargetException());
   } catch (Exception e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
Esempio n. 16
0
 /** {@inheritDoc} */
 public void run(String[] args) {
   try {
     findMain(app).invoke(null, new Object[] {args});
   } catch (NoSuchMethodException e) {
     throw new RuntimeException("can not occur; checked in constructor");
   } catch (IllegalAccessException e) {
     throw new RuntimeException(e);
   } catch (InvocationTargetException e) {
     Throwable t = e.getTargetException();
     if (t instanceof Error) throw (Error) t;
     throw new RuntimeException(t);
   }
 }
Esempio n. 17
0
 /**
  * Try to execute given method on given object. Handles invocation target exceptions. XXX nearly
  * duplicates tryMethod in JGEngine.
  *
  * @return null means method does not exist or returned null/void
  */
 static Object tryMethod(Object o, String name, Object[] args) {
   try {
     Method met = JREEngine.getMethod(o.getClass(), name, args);
     if (met == null) return null;
     return met.invoke(o, args);
   } catch (InvocationTargetException ex) {
     Throwable ex_t = ex.getTargetException();
     ex_t.printStackTrace();
     return null;
   } catch (IllegalAccessException ex) {
     System.err.println("Unexpected exception:");
     ex.printStackTrace();
     return null;
   }
 }
 public void loadAndRun(String className) throws Throwable {
   // System.out.println("Loading " + className + "...");
   Class testClass = new VerifyClassLoader().loadClass(className);
   // System.out.println("Loaded " + className);
   try {
     Method main = testClass.getMethod("main", new Class[] {String[].class});
     // System.out.println("Running " + className);
     main.invoke(null, new Object[] {new String[] {}});
     // System.out.println("Finished running " + className);
   } catch (NoSuchMethodException e) {
     return;
   } catch (InvocationTargetException e) {
     throw e.getTargetException();
   }
 }
Esempio n. 19
0
 private void invalidValueHelper(Object obj, String methodName, int i) {
   try {
     Method m = obj.getClass().getMethod(methodName, int.class);
     m.invoke(obj, i);
     fail("Didn't cause an invalid value exception.");
   } catch (NoSuchMethodException | SecurityException e) {
     System.err.println("Error when getting the method. Uh oh!");
     e.printStackTrace();
     fail();
   } catch (IllegalAccessException | IllegalArgumentException e) {
     System.err.println("Error when invoking the method. Uh oh!");
     e.printStackTrace();
     fail();
   } catch (InvocationTargetException e) {
     assertEquals(JsonTypeException.class, e.getTargetException().getClass());
   }
 }
Esempio n. 20
0
 // Lookup the value corresponding to a key found in catalog.getKeys().
 // Here we assume that the catalog returns a non-inherited value for
 // these keys. FIXME: Not true. Better see whether handleGetObject is
 // public - it is in ListResourceBundle and PropertyResourceBundle.
 private Object lookup(String key) {
   Object value = null;
   if (lookupMethod != null) {
     try {
       value = lookupMethod.invoke(catalog, new Object[] {key});
     } catch (IllegalAccessException e) {
       e.printStackTrace();
     } catch (InvocationTargetException e) {
       e.getTargetException().printStackTrace();
     }
   } else {
     try {
       value = catalog.getObject(key);
     } catch (MissingResourceException e) {
     }
   }
   return value;
 }
Esempio n. 21
0
  /**
   * {@link InvocationHandler} implementation that allows strongly-typed access to the
   * configuration.
   *
   * <p>TODO: it might be a great performance improvement to have APT generate code that does this
   * during the development time by looking at the interface.
   */
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    // serve java.lang.Object methods by ourselves
    Class<?> clazz = method.getDeclaringClass();
    if (clazz == Object.class) {
      try {
        return method.invoke(this, args);
      } catch (InvocationTargetException e) {
        throw e.getTargetException();
      }
    }

    if (method.getAnnotation(DuckTyped.class) != null) {
      return invokeDuckMethod(method, proxy, args);
    }
    if (method.getAnnotation(ConfigExtensionMethod.class) != null) {
      ConfigExtensionMethod cem = method.getAnnotation(ConfigExtensionMethod.class);
      ConfigExtensionHandler handler =
          (ConfigExtensionHandler)
              ((cem.value() != null)
                  ? getServiceLocator().getService(ConfigExtensionHandler.class, cem.value())
                  : getServiceLocator().getService(ConfigExtensionHandler.class));
      return invokeConfigExtensionMethod(handler, this, model.getProxyType(), args);
    }

    ConfigModel.Property p = model.toProperty(method);
    if (p == null)
      throw new IllegalArgumentException("No corresponding property found for method: " + method);

    if (args == null || args.length == 0) {
      // getter
      return getter(p, method.getGenericReturnType());
    } else {
      throw new PropertyVetoException(
          "Instance of "
              + getImplementation()
              + " named '"
              + getKey()
              + "' is not locked for writing when invoking method "
              + method.getName()
              + " you must use transaction semantics to access it.",
          null);
    }
  }
Esempio n. 22
0
    public void propertyChange(PropertyChangeEvent e) {
      if (_squelchChangeEvents) return;

      PropertyEditor editor = (PropertyEditor) e.getSource();
      PropertyDescriptor prop = (PropertyDescriptor) _editor2Prop.get(editor);
      Method writer = prop.getWriteMethod();
      if (writer != null) {
        try {
          Object[] params = {editor.getValue()};
          writer.invoke(_value, params);
          setObject(_value);
          firePropertyChange(_value, prop.getName(), null, editor.getValue());
        } catch (IllegalAccessException ex) {
          ex.printStackTrace();
        } catch (InvocationTargetException ex) {
          ex.getTargetException().printStackTrace();
        }
      }
    }
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
   if (state != STATE_IDLE) {
     String methodName = method.getName();
     if (methodName.equals("commit")
         || methodName.equals("rollback")
         || methodName.equals("setSavePoint")
         || (methodName.equals("setAutoCommit") && ((Boolean) args[0]).booleanValue())) {
       throw new PSQLException(
           GT.tr(
               "Transaction control methods setAutoCommit(true), commit, rollback and setSavePoint not allowed while an XA transaction is active."),
           PSQLState.OBJECT_NOT_IN_STATE);
     }
   }
   try {
     return method.invoke(con, args);
   } catch (InvocationTargetException ex) {
     throw ex.getTargetException();
   }
 }
Esempio n. 24
0
 protected PsmEvent run(PsmEvent event, PsmInterp interp, Object[] argArray) {
   try {
     return (PsmEvent) method.invoke(null, argArray);
   } catch (IllegalAccessException ex) {
     // This really should never happen, given the checks at
     // construction time.
     throw new PsmMethodActionException(ex.toString());
   } catch (InvocationTargetException ex) {
     // This may occur if the method throws a runtime exception.  Rather
     // than wrap it in a PsmMethodActionException, let it percolate up.
     // If not a RuntimeException, wrap it in a PsmMethodActionException.
     Throwable th = ex.getTargetException();
     if (th instanceof RuntimeException) {
       throw (RuntimeException) th;
     } else {
       throw new PsmMethodActionException(
           "Exception thrown from " + "target method invocation " + " is not a Runtime Exception",
           th);
     }
   }
 }
Esempio n. 25
0
  /**
   * Invoke the user defined static method in the nested "Duck" class so that the user can define
   * convenience methods on the config beans.
   */
  Object invokeDuckMethod(Method method, Object proxy, Object[] args) throws Exception {
    Method duckMethod = model.getDuckMethod(method);

    Object[] duckArgs;
    if (args == null) {
      duckArgs = new Object[] {proxy};
    } else {
      duckArgs = new Object[args.length + 1];
      duckArgs[0] = proxy;
      System.arraycopy(args, 0, duckArgs, 1, args.length);
    }

    try {
      return duckMethod.invoke(null, duckArgs);
    } catch (InvocationTargetException e) {
      Throwable t = e.getTargetException();
      if (t instanceof Exception) throw (Exception) t;
      if (t instanceof Error) throw (Error) t;
      throw e;
    }
  }
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
   Class clazz = getClass();
   Method matchingMethod;
   try {
     matchingMethod = clazz.getMethod(method.getName(), method.getParameterTypes());
   } catch (NoSuchMethodException e) {
     matchingMethod = null;
   } catch (SecurityException e) {
     matchingMethod = null;
   }
   try {
     if (matchingMethod != null) {
       // Invoke the method in the derived class.
       return matchingMethod.invoke(this, args);
     } else {
       // Invoke the method on the proxy.
       return method.invoke(getTarget(), args);
     }
   } catch (InvocationTargetException e) {
     throw e.getTargetException();
   }
 }
Esempio n. 27
0
  /**
   * Fire an event to the registered listeners, but stop on a PropertyVetoException. Subclasses may
   * choose to implement their own fire method, and just use this class for the add/remove methods.
   *
   * @param evt the Event we're going to pass to the listeners
   * @throws java.beans.PropertyVetoException
   */
  protected final void firePropertyEvent(Object evt, Method m) throws PropertyVetoException {
    // grab a reference to the listeners
    Object[] array = fListeners;

    if (array.length == 0) return;

    Object[] params = fCachedParams;
    if (params == null) params = new Object[] {evt}; // wasn't available, make a new array
    else {
      fCachedParams = null; // set to null in case fire is called re-entrantly
      params[0] = evt;
    }

    try {
      for (int i = 0; i < array.length; i++) {
        try {
          m.invoke(array[i], params);
        } catch (IllegalAccessException iae) {
          iae.printStackTrace();
        } catch (InvocationTargetException ite) {
          Throwable t = ite.getTargetException();
          if (t instanceof PropertyVetoException) throw ((PropertyVetoException) t);
          else t.printStackTrace();
        }

        if ((evt instanceof Consumable) && ((Consumable) evt).isConsumed()) {
          if (gDebugEvents) Engine.debugLog("Consumed By : " + array[i]);
          return;
        }
      }
    } finally {
      // make our param array available for re-use
      // doesn't matter if we made it fresh, or already
      // reused it from a previous fire call
      params[0] = null;
      fCachedParams = params;
    }
  }
Esempio n. 28
0
  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Object res = null;

    {
      long t0 = System.nanoTime();

      try {
        res = method.invoke(resource, args);
      } catch (InvocationTargetException ex) {
        throw ex.getTargetException();
      } catch (Exception ex) {
        throw ex;
      } finally {
        long t1 = System.nanoTime();
        long t = t1 - t0;

        log(method, args, t);
      }
    }

    return res;
  }
Esempio n. 29
0
 private Object buildValue() {
   Class cl = Kit.classOrNull(className);
   if (cl != null) {
     try {
       Object value = ScriptableObject.buildClassCtor(scope, cl, sealed, false);
       if (value == null) {
         // cl has own static initializer which is expected
         // to set the property on its own.
         value = scope.get(propertyName, scope);
         if (value != Scriptable.NOT_FOUND) return value;
       }
     } catch (InvocationTargetException ex) {
       Throwable target = ex.getTargetException();
       if (target instanceof RuntimeException) {
         throw (RuntimeException) target;
       }
     } catch (RhinoException ex) {
     } catch (InstantiationException ex) {
     } catch (IllegalAccessException ex) {
     } catch (SecurityException ex) {
     }
   }
   return Scriptable.NOT_FOUND;
 }
Esempio n. 30
0
 public void run() {
   boolean exceptionInTest = false;
   try {
     try {
       setUp();
       invoke();
     } catch (InvocationTargetException x) {
       exceptionInTest = true;
       throw new TestException(x.getTargetException());
     } catch (Exception x) {
       exceptionInTest = true;
       throw new TestException(x);
     }
   } finally {
     try {
       tearDown();
     } catch (RuntimeException exc) {
       if (!exceptionInTest) {
         throw exc;
       }
       exc.printStackTrace();
     }
   }
 }