]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedPropertyMapOfResource.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / UnescapedPropertyMapOfResource.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.layer0.request;\r
13 \r
14 import gnu.trove.map.hash.THashMap;\r
15 \r
16 import java.util.Collection;\r
17 import java.util.Map;\r
18 \r
19 import org.simantics.db.ReadGraph;\r
20 import org.simantics.db.Resource;\r
21 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;\r
22 import org.simantics.db.common.request.ResourceRead;\r
23 import org.simantics.db.exception.DatabaseException;\r
24 \r
25 public class UnescapedPropertyMapOfResource extends ResourceRead<Map<String, PropertyInfo>> {\r
26 \r
27         public UnescapedPropertyMapOfResource(Resource resource) {\r
28             super(resource);\r
29         }\r
30 \r
31         @Override\r
32         public Map<String,PropertyInfo> perform(ReadGraph graph) throws DatabaseException {\r
33 \r
34                 Collection<Resource> predicates = graph.getPredicates(resource); \r
35         THashMap<String, PropertyInfo> result = new THashMap<String, PropertyInfo>(predicates.size());\r
36                 for(Resource predicate : predicates) {\r
37                         PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate), TransientCacheAsyncListener.<PropertyInfo>instance());\r
38                         if(info != null && info.isHasProperty) {\r
39                         String name = info.name;\r
40                         if (result.put(name, info) != null)\r
41                                 System.err.println(this + ": The database resource $" + resource.getResourceId() + " contains siblings with the same name " + name + " (resource=$" + info.predicate.getResourceId() +").");\r
42                         }                               \r
43                 }\r
44                 return result;\r
45                 \r
46         }\r
47         \r
48 }\r