]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableRepository.java
Merge commit 'ad8333027322fda6b9a8a524c7a7e15a54c52f38'
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / VariableRepository.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.variable;\r
13 \r
14 import java.util.HashMap;\r
15 import java.util.Map;\r
16 \r
17 import org.simantics.db.ReadGraph;\r
18 import org.simantics.db.exception.DatabaseException;\r
19 import org.simantics.db.layer0.exception.MissingVariableException;\r
20 \r
21 final public class VariableRepository {\r
22 \r
23         final private static HashMap<String, Variable> repository = new HashMap<String, Variable>(); \r
24         \r
25         public static synchronized void register(String uri, Variable variable) {\r
26                 repository.put(uri, variable);\r
27         }\r
28 \r
29         public static synchronized void unregister(String uri) {\r
30                 repository.remove(uri);\r
31         }\r
32 \r
33         public static synchronized Variable get(ReadGraph graph, String uri) throws DatabaseException {\r
34                 for(Map.Entry<String, Variable> e : repository.entrySet()) {\r
35                         if(uri.startsWith(e.getKey())) {\r
36                                 return e.getValue().browse(graph, uri.substring(e.getKey().length()));\r
37                         }\r
38                 }\r
39                 throw new MissingVariableException(uri);\r
40         }\r
41         \r
42         public static void clear() {\r
43             repository.clear();\r
44         }\r
45     \r
46 }\r
47 \r