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.WriteGraph;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.adapter.Template;
22 import org.simantics.db.request.WriteResult;
23 import org.simantics.layer0.Layer0;
25 public class DefaultInstanceFactoryRequest implements WriteResult<Map<String, Object>> {
28 HashMap<String, Object> parameters;
31 public DefaultInstanceFactoryRequest(Resource type, Map<String, Object> parameters,
32 Resource ... contexts) {
33 this.parameters = new HashMap<String, Object>(parameters);
34 this.contexts = contexts;
38 public Map<String, Object> perform(WriteGraph g) throws DatabaseException {
40 Layer0 b = Layer0.getInstance(g);
42 // Default instantiation logic
43 Resource instance = g.newResource();
44 g.claim(instance, b.InstanceOf, null, type);
46 parameters.put("", instance);
49 HashSet<Resource> templates = new HashSet<Resource>();
50 for(Resource context : contexts)
51 templates.addAll(g.getObjects(instance, context));
54 for(Resource template : templates)
55 g.adapt(template, Template.class).apply(g, parameters);