]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.event/src/org/simantics/event/writer/NewEvent.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / writer / NewEvent.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.event.writer;
13
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;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public class NewEvent implements EventWriteTask {
25
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;
34
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;
42         this.time = time;
43         this.tag = tag;
44         this.message = message;
45         this.eventReturned = eventReturned;
46     }
47
48     @Override
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);
52
53         Resource event = graph.newResource();
54         graph.claim(event, L0.InstanceOf, null, eventInstanceOf);
55
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);
62
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);
66
67         if (eventReturned)
68             graph.claim(event, EVENT.ReturnEvent, EVENT.ReturnEvent, event);
69
70         return event;
71     }
72
73 }