X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Fwriter%2FNewEvent.java;fp=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Fwriter%2FNewEvent.java;h=c8d5a0766d965ffd91080e9fd0a9d71e4f7acd43;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.event/src/org/simantics/event/writer/NewEvent.java b/bundles/org.simantics.event/src/org/simantics/event/writer/NewEvent.java new file mode 100644 index 000000000..c8d5a0766 --- /dev/null +++ b/bundles/org.simantics.event/src/org/simantics/event/writer/NewEvent.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.event.writer; + +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.event.ontology.EventResource; +import org.simantics.layer0.Layer0; + +/** + * @author Tuukka Lehtonen + */ +public class NewEvent implements EventWriteTask { + + private final Resource eventInstanceOf; + private final Resource eventType; + private final int eventOrderNr; + private final String componentName; + private final double time; + private final String tag; + private final String message; + private final boolean eventReturned; + + public NewEvent(Resource eventInstanceOf, Resource eventType, int eventOrderNr, String componentName, double time, String tag, String message, boolean eventReturned) { + if (eventInstanceOf == null) + throw new NullPointerException("null event instanceOf"); + this.eventInstanceOf = eventInstanceOf; + this.eventType = eventType; + this.eventOrderNr = eventOrderNr; + this.componentName = componentName; + this.time = time; + this.tag = tag; + this.message = message; + this.eventReturned = eventReturned; + } + + @Override + public Resource write(WriteOnlyGraph graph, Resource slice, int number) throws DatabaseException { + Layer0 L0 = graph.getService(Layer0.class); + EventResource EVENT = graph.getService(EventResource.class); + + Resource event = graph.newResource(); + graph.claim(event, L0.InstanceOf, null, eventInstanceOf); + + graph.addLiteral(event, L0.HasName, L0.NameOf, L0.String, ""+number, Bindings.STRING); + graph.addLiteral(event, EVENT.HasTimestamp, EVENT.HasTimestamp_Inverse, EVENT.TimeStamp, time, Bindings.DOUBLE); + graph.addLiteral(event, EVENT.Event_sourceName, EVENT.Event_sourceName_Inverse, L0.String, componentName, Bindings.STRING); + if (eventType != null) + graph.claim(event, EVENT.Event_type, null, eventType); + graph.claim(slice, L0.ConsistsOf, L0.PartOf, event); + + graph.addLiteral(event, EVENT.Event_index, EVENT.Event_index_Inverse, L0.Integer, eventOrderNr, Bindings.INTEGER); + graph.addLiteral(event, EVENT.Event_tag, EVENT.Event_tag_Inverse, L0.String, tag, Bindings.STRING); + graph.addLiteral(event, EVENT.Event_message, EVENT.Event_message_Inverse, L0.String, message, Bindings.STRING); + + if (eventReturned) + graph.claim(event, EVENT.ReturnEvent, EVENT.ReturnEvent, event); + + return event; + } + +}