]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/Commands.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.commands / src / org / simantics / scl / commands / Commands.java
1 package org.simantics.scl.commands;\r
2 \r
3 import java.util.concurrent.ConcurrentHashMap;\r
4 \r
5 import org.simantics.db.ReadGraph;\r
6 import org.simantics.scl.commands.internal.CommandImpl;\r
7 \r
8 \r
9 public class Commands {\r
10     private static final ConcurrentHashMap<String, Command> COMMAND_CACHE = \r
11             new ConcurrentHashMap<String, Command>();\r
12 \r
13     /**\r
14      * Returns a command object of given type. This method always succeeds,\r
15      * but may return a command object whose check-method always returns fail\r
16      * and commit will throw an exception.\r
17      */\r
18     public static Command get(ReadGraph graph, String name) {\r
19         Command command = COMMAND_CACHE.get(name);\r
20         if(command == null) {\r
21             command = CommandImpl.create(graph, name);\r
22             COMMAND_CACHE.put(name, command);\r
23         }\r
24         return command;\r
25     }\r
26 }\r