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