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