1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
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.modeling.typicals;
14 import gnu.trove.map.hash.THashMap;
16 import java.util.TreeSet;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.request.ObjectsWithType;
21 import org.simantics.db.common.request.UnaryRead;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.diagram.stubs.DiagramResource;
24 import org.simantics.layer0.Layer0;
25 import org.simantics.modeling.ModelingResources;
28 * Reads a TypicalInfo info structure for the specified typical diagram instance.
30 * @author Tuukka Lehtonen
32 public class ReadTypicalInfo extends UnaryRead<Resource, TypicalInfoBean> {
34 public ReadTypicalInfo(Resource typicalInstance) {
35 super(typicalInstance);
39 public TypicalInfoBean perform(ReadGraph graph) throws DatabaseException {
40 Layer0 L0 = Layer0.getInstance(graph);
41 DiagramResource DIA = DiagramResource.getInstance(graph);
42 ModelingResources MOD = ModelingResources.getInstance(graph);
44 TypicalInfoBean info = new TypicalInfoBean();
45 info.instanceElements = new TreeSet<Resource>( graph.syncRequest( new ObjectsWithType(parameter, L0.ConsistsOf, DIA.Element) ) );
46 info.instanceToTemplate = new THashMap<Resource, Resource>( info.instanceElements.size() );
47 info.templateToInstance = new THashMap<Resource, Resource>( info.instanceElements.size() );
48 info.isTemplatized = new TreeSet<Resource>();
49 for (Resource instanceElement : info.instanceElements) {
50 Resource templateElement = graph.getPossibleObject(instanceElement, MOD.HasElementSource);
51 if (templateElement != null) {
52 info.instanceToTemplate.put(instanceElement, templateElement);
53 info.templateToInstance.put(templateElement, instanceElement);
55 if (graph.hasStatement(instanceElement, MOD.IsTemplatized))
56 info.isTemplatized.add(instanceElement);