JSPWIKI-1131: allow events to carry args - objects related to event's src
diff --git a/jspwiki-event/src/main/java/org/apache/wiki/event/WikiEvent.java b/jspwiki-event/src/main/java/org/apache/wiki/event/WikiEvent.java
index 7ee9a96..c2b79c2 100644
--- a/jspwiki-event/src/main/java/org/apache/wiki/event/WikiEvent.java
+++ b/jspwiki-event/src/main/java/org/apache/wiki/event/WikiEvent.java
@@ -40,6 +40,9 @@
private final long m_when;
+ /** objects associated to src which only make sense in the context of a given WikiEvent */
+ private Object[] args;
+
// ............
/**
@@ -51,8 +54,20 @@
public WikiEvent( final Object src, final int type ) {
super( src );
m_when = System.currentTimeMillis();
+ args = new Object[]{};
setType( type );
}
+
+ /**
+ * Constructs an instance of this event.
+ *
+ * @param src the Object that is the source of the event.
+ * @param type the event type.
+ */
+ public WikiEvent( final Object src, final int type, final Object... args ) {
+ this( src, type );
+ this.args = args != null ? args : new Object[]{};
+ }
/**
* Convenience method that returns the typed object to which the event applied.
@@ -93,6 +108,27 @@
}
/**
+ * Returns the args associated to src, if any.
+ *
+ * @return args associated to src, if any.
+ */
+ public Object[] getArgs() {
+ return args;
+ }
+
+ /**
+ * Returns the requested arg, if any.
+ *
+ * @return requested arg or null.
+ */
+ public < T > T getArg( int index, Class< T > cls ) {
+ if( index >= args.length ) {
+ return null;
+ }
+ return ( T )args[ index ];
+ }
+
+ /**
* Returns a String (human-readable) description of an event type. This should be subclassed as necessary.
*
* @return the String description
diff --git a/jspwiki-event/src/main/java/org/apache/wiki/event/WikiEventEmitter.java b/jspwiki-event/src/main/java/org/apache/wiki/event/WikiEventEmitter.java
index 579f7c0..f8c93bd 100644
--- a/jspwiki-event/src/main/java/org/apache/wiki/event/WikiEventEmitter.java
+++ b/jspwiki-event/src/main/java/org/apache/wiki/event/WikiEventEmitter.java
@@ -43,6 +43,17 @@
return fireEvent( new WorkflowEvent( src, type ) );
}
+ /**
+ * Fires a Workflow Event from provided source and workflow type.
+ *
+ * @param src the source of the event, which can be any object: a wiki page, group or authentication/authentication/group manager.
+ * @param type the type of event
+ * @return fired {@link WorkflowEvent} or {@code null} if the {@link WikiEventEmitter} instance hasn't listeners attached.
+ */
+ public static WorkflowEvent fireWorkflowEvent( final Object src, final int type, final Object... args ) {
+ return fireEvent( new WorkflowEvent( src, type, args ) );
+ }
+
static < T extends WikiEvent > T fireEvent( final T event ) {
if( WikiEventManager.isListening( WikiEventEmitter.get() ) ) {
WikiEventManager.fireEvent( WikiEventEmitter.get(), event );
diff --git a/jspwiki-event/src/main/java/org/apache/wiki/event/WorkflowEvent.java b/jspwiki-event/src/main/java/org/apache/wiki/event/WorkflowEvent.java
index 10f0d48..992aae2 100644
--- a/jspwiki-event/src/main/java/org/apache/wiki/event/WorkflowEvent.java
+++ b/jspwiki-event/src/main/java/org/apache/wiki/event/WorkflowEvent.java
@@ -70,18 +70,27 @@
public static final int DQ_REASSIGN = 90;
/**
- * Constructs a new instance of this event type, which signals a security event has occurred.
- * The <code>source</code> parameter is required, and may not be <code>null</code>. When the
+ * Constructs a new instance of this event type, which signals a security event has occurred.
+ * The <code>source</code> parameter is required, and may not be <code>null</code>. When the
* WikiSecurityEvent is constructed, the security logger {@link WikiSecurityEvent#log} is notified.
- *
+ *
* @param src the source of the event, which can be any object: a wiki page, group or authentication/authentication/group manager.
* @param type the type of event
*/
public WorkflowEvent( final Object src, final int type ) {
super( src, type );
- if( src == null ) {
- throw new IllegalArgumentException( "Argument(s) cannot be null." );
- }
+ }
+
+ /**
+ * Constructs a new instance of this event type, which signals a security event has occurred.
+ * The <code>source</code> parameter is required, and may not be <code>null</code>. When the
+ * WikiSecurityEvent is constructed, the security logger {@link WikiSecurityEvent#log} is notified.
+ *
+ * @param src the source of the event, which can be any object: a wiki page, group or authentication/authentication/group manager.
+ * @param type the type of event
+ */
+ public WorkflowEvent( final Object src, final int type, final Object... args ) {
+ super( src, type, args );
}
/**