]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedMethodMapOfResource.java
Speeding up platform startup time
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / UnescapedMethodMapOfResource.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.db.layer0.request;
13
14 import java.util.Collection;
15 import java.util.Map;
16
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.request.ResourceRead;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.layer0.Layer0;
23
24 import gnu.trove.map.hash.THashMap;
25
26 public class UnescapedMethodMapOfResource extends ResourceRead<Map<String, Resource>> {
27
28         public UnescapedMethodMapOfResource(Resource resource) {
29             super(resource);
30         }
31
32         @Override
33         public Map<String,Resource> perform(ReadGraph graph) throws DatabaseException {
34
35                 Layer0 L0 = Layer0.getInstance(graph);
36                 Collection<Resource> predicates = graph.getPredicates(resource); 
37         THashMap<String, Resource> result = new THashMap<String, Resource>(predicates.size());
38                 for(Resource predicate : predicates) {
39                         if(graph.isSubrelationOf(predicate, L0.HasMethod)) {
40                                 String name = graph.getPossibleRelatedValue(predicate, L0.HasName, Bindings.STRING);
41                                 if(name != null) {
42                                 if (result.put(name, predicate) != null)
43                                         System.err.println(this + ": The database resource $" + resource.getResourceId() + " contains siblings with the same name " + name + " (resource=$" + predicate.getResourceId() +").");
44                                 }
45                         }
46                 }
47                 return result;
48                 
49         }
50         
51 }