1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 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 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.layer0.utils.writer;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.WriteGraph;
\r
16 import org.simantics.db.exception.DatabaseException;
\r
17 import org.simantics.layer0.Layer0;
\r
19 public class DirectGraphWriter extends GraphWriterPartial {
\r
24 public DirectGraphWriter(WriteGraph graph) {
\r
27 this.current = null;
\r
31 public GraphWriter create() throws DatabaseException {
\r
32 current = wg.newResource();
\r
37 public GraphWriter create(Resource type) throws DatabaseException {
\r
38 current = wg.newResource();
\r
39 Layer0 b = Layer0.getInstance(wg);
\r
40 wg.claim(current, b.InstanceOf, null, type);
\r
45 public Resource get() {
\r
50 public GraphWriter handle(Resource s) {
\r
56 public GraphWriter let(Resource p, Resource o) throws DatabaseException {
\r
58 throw new RuntimeException("Should call create or handle before let.");
\r
59 wg.claim(current, p, o);
\r
64 public GraphWriter let(Resource p, Object value, Resource dataType) throws DatabaseException {
\r
66 throw new RuntimeException("Should call create or handle before let.");
\r
67 Resource temp = wg.newResource();
\r
68 wg.claim(temp, l0.InstanceOf, null, dataType);
\r
69 wg.claimValue(temp, value);
\r
70 wg.claim(current, p, temp);
\r
75 public GraphWriter flush() throws DatabaseException {
\r
81 public GraphWriter createLiteral(Object value, Resource dataType) throws DatabaseException {
\r
82 current = wg.newResource();
\r
83 wg.claim(current, l0.InstanceOf, null, dataType);
\r
84 wg.claimValue(current, value);
\r
89 public GraphWriter createInverse(Resource r) throws DatabaseException {
\r
90 current = wg.newResource();
\r
91 wg.claim(r, l0.InverseOf, current);
\r