1 /*******************************************************************************
2 * Copyright (c) 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.diagram.query;
14 import gnu.trove.map.hash.THashMap;
16 import java.util.Collection;
19 import org.simantics.databoard.Bindings;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.common.request.ResourceRead;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.layer0.Layer0;
27 * @author Tuukka Lehtonen
29 public class AnnotationTypeProperties extends ResourceRead<Map<String, Resource>> {
31 public AnnotationTypeProperties(Resource annotationType) {
32 super(annotationType);
36 public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
37 Layer0 L0 = Layer0.getInstance(graph);
38 Collection<Resource> children = graph.getObjects(resource, L0.ConsistsOf);
39 Map<String, Resource> properties = new THashMap<String, Resource>(children.size());
40 for (Resource child : children) {
41 if (graph.isSubrelationOf(child, L0.HasProperty)) {
42 String name = graph.getPossibleRelatedValue2(child, L0.HasName, Bindings.STRING);
44 properties.put(name, child);