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.db.layer0.adapter.impl;
\r
14 import java.util.Map;
\r
16 import org.simantics.db.ReadGraph;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.db.layer0.adapter.InstanceFactory;
\r
19 import org.simantics.db.layer0.request.DefaultInstanceFactoryRequest;
\r
20 import org.simantics.db.request.WriteResult;
\r
22 public class DefaultInstanceFactory implements InstanceFactory {
\r
24 final Resource resource;
\r
26 public DefaultInstanceFactory(Resource resource) {
\r
27 this.resource = resource;
\r
30 public WriteResult<Map<String, Object>> create(ReadGraph graph, Map<String, Object> attachment, Resource ... templates) {
\r
31 return new DefaultInstanceFactoryRequest(resource, attachment, templates);
\r
35 // public Resource create(WriteGraph graph) throws DatabaseException {
\r
37 // Builtins b = graph.getBuiltins();
\r
38 // SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
\r
40 // InstanceFactory sheetElementFactory = graph.adapt(sr.SpreadsheetElement, InstanceFactory.class);
\r
41 // Map<String, Object> sheetElement = graph.syncRequest(sheetElementFactory.create(ArrayMap.keys("").values(""), sr.ForCompositeTemplate));
\r
43 //// InstanceFactory sheetFactory = w.adapt(ssr.Spreadsheet, InstanceFactory.class);
\r
44 //// w.syncRequest(sheetFactory.create(ArrayMap.keys("composite").values(model), ssr.ForCompositeTemplate));
\r
46 // Resource result = OrderedSetUtils.create(graph, sr.Spreadsheet, (Resource)sheetElement.get("resource"));
\r
48 // graph.claim((Resource)sheetElement.get("resource"), sr.HasSheet, result);
\r
50 // Resource rowResource0 = graph.newResource();
\r
51 // graph.claim(rowResource0, b.InstanceOf, null, sr.Row);
\r
52 // Resource rowResource1 = graph.newResource();
\r
53 // graph.claim(rowResource1, b.InstanceOf, null, sr.Row);
\r
54 // Resource columnResource0 = graph.newResource();
\r
55 // graph.claim(columnResource0, b.InstanceOf, null, sr.Column);
\r
56 // Resource columnResource1 = graph.newResource();
\r
57 // graph.claim(columnResource1, b.InstanceOf, null, sr.Column);
\r
58 // Resource columnResource2 = graph.newResource();
\r
59 // graph.claim(columnResource2, b.InstanceOf, null, sr.Column);
\r
60 // Resource columnResource3 = graph.newResource();
\r
61 // graph.claim(columnResource3, b.InstanceOf, null, sr.Column);
\r
63 // graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0, rowResource1));
\r
64 // graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0, columnResource1, columnResource2, columnResource3));
\r
66 //// RowsColumnsIndex rowIndex = graph.syncRequest(new Rows(result));
\r
67 //// RowsColumnsIndex columnIndex = graph.syncRequest(new Columns(result));
\r
68 //// Resource rowResource0 = rowIndex.ensureIndex(graph, 0);
\r
69 //// Resource rowResource1 = rowIndex.ensureIndex(graph, 1);
\r
70 //// Resource columnResource0 = columnIndex.ensureIndex(graph, 0);
\r
71 //// Resource columnResource1 = columnIndex.ensureIndex(graph, 1);
\r
72 //// Resource columnResource2 = columnIndex.ensureIndex(graph, 2);
\r
73 //// Resource columnResource3 = columnIndex.ensureIndex(graph, 3);
\r
76 // Resource newCell = graph.newResource();
\r
77 // graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
\r
78 // String label = "Pipe name";
\r
79 // graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
80 // graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);
\r
81 // graph.addValue(newCell, sr.HasLabel, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
\r
82 // graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
86 // Resource newCell = graph.newResource();
\r
87 // graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
\r
88 // String label = "Pipe length";
\r
89 // graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
90 // graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource1);
\r
91 // graph.addValue(newCell, sr.HasLabel, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
\r
92 // graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
96 // Resource newCell = graph.newResource();
\r
97 // graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
\r
98 // String label = "Flow area";
\r
99 // graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
100 // graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource2);
\r
101 // graph.addValue(newCell, sr.HasLabel, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
\r
102 // graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
106 // Resource newCell = graph.newResource();
\r
107 // graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
\r
108 // String label = "In simulation";
\r
109 // graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
110 // graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource3);
\r
111 // graph.addValue(newCell, sr.HasLabel, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
\r
112 // graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
116 // Resource newCell = graph.newResource();
\r
117 // graph.claim(newCell, b.InstanceOf, null, sr.ExpressionCell);
\r
118 // String label = "Attributes(Components('Pipe*'), 'Name', 'Pi12 Length', 'Pi12 Area', 'Included In Simulation')";
\r
119 // graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource1);
\r
120 // graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);
\r
121 // graph.addValue(newCell, sr.HasExpression, sr.ExpressionOf, b.String, label, StringJavaBinding.INSTANCE);
\r
122 // graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
130 // public Resource create(WriteGraph graph, Resource container, Resource relation) throws DatabaseException {
\r
132 // Builtins b = graph.getBuiltins();
\r
133 // Resource sheet = create(graph);
\r
134 // String name = GraphUtils.findFreshName(graph, "Sheet", container, relation);
\r
135 // graph.addValue(sheet, b.HasName, b.NameOf, b.String, name, StringJavaBinding.INSTANCE);
\r
136 // graph.claim(container, relation, sheet);
\r
142 // public Resource create(WriteGraph graph, Map<String, Resource> attachment,
\r
143 // Collection<Resource> templates) throws DatabaseException {
\r
144 // throw new Error("Not implemented");
\r