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(); } } }
/** * 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; } }