--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2012 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.event.writer;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteOnlyGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.event.ontology.EventResource;\r
+import org.simantics.layer0.Layer0;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class NewEvent implements EventWriteTask {\r
+\r
+ private final Resource eventInstanceOf;\r
+ private final Resource eventType;\r
+ private final int eventOrderNr;\r
+ private final String componentName;\r
+ private final double time;\r
+ private final String tag;\r
+ private final String message;\r
+ private final boolean eventReturned;\r
+\r
+ public NewEvent(Resource eventInstanceOf, Resource eventType, int eventOrderNr, String componentName, double time, String tag, String message, boolean eventReturned) {\r
+ if (eventInstanceOf == null)\r
+ throw new NullPointerException("null event instanceOf");\r
+ this.eventInstanceOf = eventInstanceOf;\r
+ this.eventType = eventType;\r
+ this.eventOrderNr = eventOrderNr;\r
+ this.componentName = componentName;\r
+ this.time = time;\r
+ this.tag = tag;\r
+ this.message = message;\r
+ this.eventReturned = eventReturned;\r
+ }\r
+\r
+ @Override\r
+ public Resource write(WriteOnlyGraph graph, Resource slice, int number) throws DatabaseException {\r
+ Layer0 L0 = graph.getService(Layer0.class);\r
+ EventResource EVENT = graph.getService(EventResource.class);\r
+\r
+ Resource event = graph.newResource();\r
+ graph.claim(event, L0.InstanceOf, null, eventInstanceOf);\r
+\r
+ graph.addLiteral(event, L0.HasName, L0.NameOf, L0.String, ""+number, Bindings.STRING);\r
+ graph.addLiteral(event, EVENT.HasTimestamp, EVENT.HasTimestamp_Inverse, EVENT.TimeStamp, time, Bindings.DOUBLE);\r
+ graph.addLiteral(event, EVENT.Event_sourceName, EVENT.Event_sourceName_Inverse, L0.String, componentName, Bindings.STRING);\r
+ if (eventType != null)\r
+ graph.claim(event, EVENT.Event_type, null, eventType);\r
+ graph.claim(slice, L0.ConsistsOf, L0.PartOf, event);\r
+\r
+ graph.addLiteral(event, EVENT.Event_index, EVENT.Event_index_Inverse, L0.Integer, eventOrderNr, Bindings.INTEGER);\r
+ graph.addLiteral(event, EVENT.Event_tag, EVENT.Event_tag_Inverse, L0.String, tag, Bindings.STRING);\r
+ graph.addLiteral(event, EVENT.Event_message, EVENT.Event_message_Inverse, L0.String, message, Bindings.STRING);\r
+\r
+ if (eventReturned)\r
+ graph.claim(event, EVENT.ReturnEvent, EVENT.ReturnEvent, event);\r
+\r
+ return event;\r
+ }\r
+\r
+}\r