1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.event.writer;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteOnlyGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.event.ontology.EventResource;
19 import org.simantics.layer0.Layer0;
22 * @author Tuukka Lehtonen
24 public class NewEvent implements EventWriteTask {
26 private final Resource eventInstanceOf;
27 private final Resource eventType;
28 private final int eventOrderNr;
29 private final String componentName;
30 private final double time;
31 private final String tag;
32 private final String message;
33 private final boolean eventReturned;
35 public NewEvent(Resource eventInstanceOf, Resource eventType, int eventOrderNr, String componentName, double time, String tag, String message, boolean eventReturned) {
36 if (eventInstanceOf == null)
37 throw new NullPointerException("null event instanceOf");
38 this.eventInstanceOf = eventInstanceOf;
39 this.eventType = eventType;
40 this.eventOrderNr = eventOrderNr;
41 this.componentName = componentName;
44 this.message = message;
45 this.eventReturned = eventReturned;
49 public Resource write(WriteOnlyGraph graph, Resource slice, int number) throws DatabaseException {
50 Layer0 L0 = graph.getService(Layer0.class);
51 EventResource EVENT = graph.getService(EventResource.class);
53 Resource event = graph.newResource();
54 graph.claim(event, L0.InstanceOf, null, eventInstanceOf);
56 graph.addLiteral(event, L0.HasName, L0.NameOf, L0.String, ""+number, Bindings.STRING);
57 graph.addLiteral(event, EVENT.HasTimestamp, EVENT.HasTimestamp_Inverse, EVENT.TimeStamp, time, Bindings.DOUBLE);
58 graph.addLiteral(event, EVENT.Event_sourceName, EVENT.Event_sourceName_Inverse, L0.String, componentName, Bindings.STRING);
59 if (eventType != null)
60 graph.claim(event, EVENT.Event_type, null, eventType);
61 graph.claim(slice, L0.ConsistsOf, L0.PartOf, event);
63 graph.addLiteral(event, EVENT.Event_index, EVENT.Event_index_Inverse, L0.Integer, eventOrderNr, Bindings.INTEGER);
64 graph.addLiteral(event, EVENT.Event_tag, EVENT.Event_tag_Inverse, L0.String, tag, Bindings.STRING);
65 graph.addLiteral(event, EVENT.Event_message, EVENT.Event_message_Inverse, L0.String, message, Bindings.STRING);
68 graph.claim(event, EVENT.ReturnEvent, EVENT.ReturnEvent, event);