]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/query/AnnotationTypeProperties.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / query / AnnotationTypeProperties.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.query;
13
14 import gnu.trove.map.hash.THashMap;
15
16 import java.util.Collection;
17 import java.util.Map;
18
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;
25
26 /**
27  * @author Tuukka Lehtonen
28  */
29 public class AnnotationTypeProperties extends ResourceRead<Map<String, Resource>> {
30
31     public AnnotationTypeProperties(Resource annotationType) {
32         super(annotationType);
33     }
34
35     @Override
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);
43                 if (name != null)
44                     properties.put(name, child);
45             }
46         }
47         return properties;
48     }
49
50 }