summaryrefslogtreecommitdiff
path: root/js/src/Ice/ValueFactoryManager.js
diff options
context:
space:
mode:
authorJoe George <joe@zeroc.com>2015-12-08 11:33:42 -0500
committerJoe George <joe@zeroc.com>2015-12-08 16:09:24 -0500
commit6a43686ce26de5d2d5edf4a485ecff3a242c26b6 (patch)
treed31e4f16dc9ed6e28056a7224e045a4638955f5e /js/src/Ice/ValueFactoryManager.js
parentC++11 mapping IceDiscovery plug-in (diff)
downloadice-6a43686ce26de5d2d5edf4a485ecff3a242c26b6.tar.bz2
ice-6a43686ce26de5d2d5edf4a485ecff3a242c26b6.tar.xz
ice-6a43686ce26de5d2d5edf4a485ecff3a242c26b6.zip
ICE-6908 - Add ValueFactory
ValueFactory is a replacement for ObjectFactory (which is still available if needed). It is an interface with only one operation and can has the "delegate" metadata.
Diffstat (limited to 'js/src/Ice/ValueFactoryManager.js')
-rw-r--r--js/src/Ice/ValueFactoryManager.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/js/src/Ice/ValueFactoryManager.js b/js/src/Ice/ValueFactoryManager.js
new file mode 100644
index 00000000000..55efddf9fea
--- /dev/null
+++ b/js/src/Ice/ValueFactoryManager.js
@@ -0,0 +1,77 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+var Ice = require("../Ice/ModuleRegistry").Ice;
+Ice.__M.require(module, ["../Ice/Class", "../Ice/HashMap", "../Ice/LocalException"]);
+
+var HashMap = Ice.HashMap;
+var AlreadyRegisteredException = Ice.AlreadyRegisteredException;
+var NotRegisteredException = Ice.NotRegisteredException;
+
+//
+// Only for use by Instance
+//
+var ValueFactoryManager = Ice.Class({
+ __init__: function()
+ {
+ this._factoryMap = new HashMap(); // Map<String, ValueFactory>
+ this._objectFactoryMap = new HashMap(); // Map<String, ObjectFactory>
+ },
+ add: function(factory, id)
+ {
+ var o, ex;
+ o = this._factoryMap.get(id);
+ if(o !== undefined)
+ {
+ ex = new AlreadyRegisteredException();
+ ex.id = id;
+ ex.kindOfObject = "value factory";
+ throw ex;
+ }
+ this._factoryMap.set(id, factory);
+ },
+ addObjectFactory: function(factory, id)
+ {
+ var o, ex;
+ o = this._factoryMap.get(id);
+ if(o !== undefined)
+ {
+ ex = new AlreadyRegisteredException();
+ ex.id = id;
+ ex.kindOfObject = "value factory";
+ throw ex;
+ }
+ this._factoryMap.set(id, factory);
+ this._objectFactoryMap.set(id, factory);
+ },
+ find: function(id)
+ {
+ return this._factoryMap.get(id);
+ },
+ findObjectFactory: function(id)
+ {
+ return this._objectFactoryMap.get(id);
+ },
+ destroy: function()
+ {
+ var oldMap = this._objectFactoryMap,
+ e = oldMap.entries;
+ this._factoryMap = new HashMap(); // Map<String, ValueFactory>
+ this._objectFactoryMap = new HashMap(); // Map<String, ObjectFactory>
+
+ while(e !== null)
+ {
+ e.value.destroy();
+ e = e.next;
+ }
+ }
+});
+
+Ice.ValueFactoryManager = ValueFactoryManager;
+module.exports.Ice = Ice;