@Override
public DomainEventValue createEvent( EntityComposite entity, String name, Object[] args )
{
ValueBuilder<DomainEventValue> builder = vbf.newValueBuilder( DomainEventValue.class );
DomainEventValue prototype = builder.prototype();
prototype.name().set( name );
prototype.entityType().set( first(Qi4j.FUNCTION_DESCRIPTOR_FOR.map( entity ).types()).getName() );
prototype.entityId().set( entity.identity().get() );
// JSON-ify parameters
JSONStringer json = new JSONStringer();
try
{
JSONWriter params = json.object();
for (int i = 0; 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 eventValue", e );
}
prototype.parameters().set( json.toString() );
DomainEventValue eventValue = builder.newInstance();
return eventValue;
}