@Override
public ApplicationEvent createEvent( String name, Object[] args )
{
ValueBuilder<ApplicationEvent> builder = vbf.newValueBuilder( ApplicationEvent.class );
ApplicationEvent prototype = builder.prototype();
prototype.name().set( name );
prototype.on().set( new Date() );
prototype.identity().set( idGenerator.generate( ApplicationEvent.class ) );
UnitOfWork uow = uowf.currentUnitOfWork();
prototype.usecase().set( uow.usecase().name() );
prototype.version().set( version );
// JSON-ify parameters
JSONStringer json = new JSONStringer();
try
{
JSONWriter params = json.object();
for (int i = 1; i < args.length; i++)
{
params.key( "param" + i );
if (args[i] == null)
params.value( JSONObject.NULL );
else
params.value( args[i] );
}
json.endObject();
} catch (JSONException e)
{
throw new IllegalArgumentException( "Could not create event", e );
}
prototype.parameters().set( json.toString() );
ApplicationEvent event = builder.newInstance();
return event;
}