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=cd918d908d0228ffac2daa8cc58cfbb36fef37e0;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=c8d5a0766d965ffd91080e9fd0a9d71e4f7acd43;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;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 index c8d5a0766..cd918d908 100644 --- a/bundles/org.simantics.event/src/org/simantics/event/writer/NewEvent.java +++ b/bundles/org.simantics.event/src/org/simantics/event/writer/NewEvent.java @@ -1,73 +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; - } - -} +/******************************************************************************* + * 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; + } + +}