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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.layer0.variable;
\r
14 import java.util.HashMap;
\r
15 import java.util.Map;
\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
21 final public class VariableRepository {
\r
23 final private static HashMap<String, Variable> repository = new HashMap<String, Variable>();
\r
25 public static synchronized void register(String uri, Variable variable) {
\r
26 repository.put(uri, variable);
\r
29 public static synchronized void unregister(String uri) {
\r
30 repository.remove(uri);
\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
39 throw new MissingVariableException(uri);
\r
42 public static void clear() {
\r