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.request;
14 import java.util.HashMap;
15 import java.util.HashSet;
18 import org.simantics.db.Resource;
19 import org.simantics.db.VirtualGraph;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.layer0.adapter.Template;
23 import org.simantics.db.request.UndoTraits;
24 import org.simantics.db.request.WriteResult;
25 import org.simantics.layer0.Layer0;
27 public class DefaultInstanceFactoryRequest implements WriteResult<Map<String, Object>> {
30 HashMap<String, Object> parameters;
33 public DefaultInstanceFactoryRequest(Resource type, Map<String, Object> parameters,
34 Resource ... contexts) {
35 this.parameters = new HashMap<String, Object>(parameters);
36 this.contexts = contexts;
40 public Map<String, Object> perform(WriteGraph g) throws DatabaseException {
42 Layer0 b = Layer0.getInstance(g);
44 // Default instantiation logic
45 Resource instance = g.newResource();
46 g.claim(instance, b.InstanceOf, null, type);
48 parameters.put("", instance);
51 HashSet<Resource> templates = new HashSet<Resource>();
52 for(Resource context : contexts)
53 templates.addAll(g.getObjects(instance, context));
56 for(Resource template : templates)
57 g.adapt(template, Template.class).apply(g, parameters);
64 public UndoTraits getUndoTraits() {
69 public VirtualGraph getProvider() {