annotate src/implab/di/ServiceDescriptor.js @ 17:9c21e656cbec

Разработка кнопки выбора координат с карт
author nickolay
date Tue, 19 Sep 2017 20:37:56 +0300
parents 00779cb63b12
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
1 define(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
2 [
1
93fb6c09f2e1 minor fixes
cin
parents: 0
diff changeset
3 "../declare",
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
4 "../safe",
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
5 "./Descriptor",
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
6 "./ValueDescriptor"
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
7 ],
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
8
1
93fb6c09f2e1 minor fixes
cin
parents: 0
diff changeset
9 function (declare, safe, Descriptor, Value) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
10 var SINGLETON_ACTIVATION = 1,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
11 CONTAINER_ACTIVATION = 2,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
12 CONTEXT_ACTIVATION = 3,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
13 CALL_ACTIVATION = 4,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
14 HIERARCHY_ACTIVATION = 5;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
15
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
16 var injectMethod = function (target, method, context, args) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
17 var m = target[method];
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
18 if (!m)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
19 throw new Error("Method '" + method + "' not found");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
20
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
21 if (args instanceof Array)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
22 m.apply(target, context.parse(args, "." + method));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
23 else
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
24 m.call(target, context.parse(args, "." + method));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
25 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
26
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
27 var makeClenupCallback = function (target, method) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
28 if (typeof (method) === "string") {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
29 return function () {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
30 target[method]();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
31 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
32 } else {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
33 return function () {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
34 method(target);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
35 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
36 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
37 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
38
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
39 var cacheId = 0;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
40
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
41 var cls = declare(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
42 Descriptor, {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
43 _instance: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
44 _hasInstance: false,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
45 _activationType: CALL_ACTIVATION,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
46 _services: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
47 _type: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
48 _typeMap: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
49 _factory: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
50 _params: undefined,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
51 _inject: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
52 _cleanup: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
53 _cacheId: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
54 _owner: null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
55
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
56 constructor: function (opts) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
57 safe.argumentNotNull(opts, "opts");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
58 safe.argumentNotNull(opts.owner, "opts.owner");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
59
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
60 this._owner = opts.owner;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
61
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
62 if (!(opts.type || opts.factory))
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
63 throw new Error(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
64 "Either a type or a factory must be specified");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
65
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
66 if (typeof (opts.type) === "string" && !opts.typeMap)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
67 throw new Error(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
68 "The typeMap is required when the type is specified by its name");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
69
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
70 if (opts.activation)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
71 this._activationType = opts.activation;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
72 if (opts.type)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
73 this._type = opts.type;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
74 if (opts.params)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
75 this._params = opts.params;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
76 if (opts.inject)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
77 this._inject = opts.inject instanceof Array ? opts.inject : [opts.inject];
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
78 if (opts.services)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
79 this._services = opts.services;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
80 if (opts.factory)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
81 this._factory = opts.factory;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
82 if (opts.typeMap)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
83 this._typeMap = opts.typeMap;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
84 if (opts.cleanup) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
85 if (!(typeof (opts.cleanup) === "string" || opts.cleanup instanceof Function))
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
86 throw new Error(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
87 "The cleanup parameter must be either a function or a function name");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
88
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
89 this._cleanup = opts.cleanup;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
90 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
91
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
92 this._cacheId = ++cacheId;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
93 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
94
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
95 activate: function (context, name) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
96
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
97 // if we have a local service records, register them first
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
98
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
99 var instance;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
100
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
101 switch (this._activationType) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
102 case 1: // SINGLETON
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
103 // if the value is cached return it
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
104 if (this._hasInstance)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
105 return this._instance;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
106
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
107 var tof = this._type || this._factory;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
108
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
109 // create the persistent cache identifier for the type
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
110 if (safe.isPrimitive(tof))
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
111 this._cacheId = this._type;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
112 else
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
113 this._cacheId = safe.oid(tof);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
114
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
115 // singletons are bound to the root container
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
116 var container = context.container.getRootContainer();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
117
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
118 if (container.has(this._cacheId)) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
119 instance = container.get(this._cacheId);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
120 } else {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
121 instance = this._create(context, name);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
122 container.store(this._cacheId, instance);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
123 if (this._cleanup)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
124 container.onDispose(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
125 makeClenupCallback(instance, this._cleanup));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
126 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
127
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
128 this._hasInstance = true;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
129 return (this._instance = instance);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
130
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
131 case 2: // CONTAINER
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
132 //return a cached value
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
133 if (this._hasInstance)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
134 return this._instance;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
135
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
136 // create an instance
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
137 instance = this._create(context, name);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
138
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
139 // the instance is bound to the container
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
140 if (this._cleanup)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
141 this._owner.onDispose(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
142 makeClenupCallback(instance, this._cleanup));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
143
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
144 // cache and return the instance
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
145 this._hasInstance = true;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
146 return (this._instance = instance);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
147 case 3: // CONTEXT
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
148 //return a cached value if one exists
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
149 if (context.has(this._cacheId))
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
150 return context.get(this._cacheId);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
151 // context context activated instances are controlled by callers
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
152 return context.store(this._cacheId, this._create(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
153 context,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
154 name));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
155 case 4: // CALL
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
156 // per-call created instances are controlled by callers
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
157 return this._create(context, name);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
158 case 5: // HIERARCHY
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
159 // hierarchy activated instances are behave much like container activated
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
160 // except they are created and bound to the child container
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
161
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
162 // return a cached value
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
163 if (context.container.has(this._cacheId))
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
164 return context.container.get(this._cacheId);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
165
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
166 instance = this._create(context, name);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
167
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
168 if (this._cleanup)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
169 context.container.onDispose(makeClenupCallback(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
170 instance,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
171 this._cleanup));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
172
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
173 return context.container.store(this._cacheId, instance);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
174 default:
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
175 throw "Invalid activation type: " + this._activationType;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
176 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
177 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
178
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
179 isInstanceCreated: function () {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
180 return this._hasInstance;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
181 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
182
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
183 getInstance: function () {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
184 return this._instance;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
185 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
186
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
187 _create: function (context, name) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
188 context.enter(name, this, Boolean(this._services));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
189
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
190 if (this._activationType != CALL_ACTIVATION &&
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
191 context.visit(this._cacheId) > 0)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
192 throw new Error("Recursion detected");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
193
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
194 if (this._services) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
195 for (var p in this._services) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
196 var sv = this._services[p];
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
197 context.register(p, sv instanceof Descriptor ? sv : new Value(sv, false));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
198 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
199 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
200
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
201 var instance;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
202
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
203 if (!this._factory) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
204 var ctor, type = this._type;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
205
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
206 if (typeof (type) === "string") {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
207 ctor = this._typeMap[type];
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
208 if (!ctor)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
209 throw new Error("Failed to resolve the type '" +
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
210 type + "'");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
211 } else {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
212 ctor = type;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
213 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
214
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
215 if (this._params === undefined) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
216 this._factory = function () {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
217 return new ctor();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
218 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
219 } else if (this._params instanceof Array) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
220 this._factory = function () {
3
00779cb63b12 formatting
cin
parents: 1
diff changeset
221 var inst = Object.create(ctor.prototype);
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
222 var ret = ctor.apply(inst, arguments);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
223 return typeof (ret) === "object" ? ret : inst;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
224 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
225 } else {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
226 this._factory = function (param) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
227 return new ctor(param);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
228 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
229 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
230 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
231
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
232 if (this._params === undefined) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
233 instance = this._factory();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
234 } else if (this._params instanceof Array) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
235 instance = this._factory.apply(this, context.parse(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
236 this._params,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
237 ".params"));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
238 } else {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
239 instance = this._factory(context.parse(
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
240 this._params,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
241 ".params"));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
242 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
243
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
244 if (this._inject) {
1
93fb6c09f2e1 minor fixes
cin
parents: 0
diff changeset
245 this._inject.forEach(function (spec) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
246 for (var m in spec)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
247 injectMethod(instance, m, context, spec[m]);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
248 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
249 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
250
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
251 context.leave();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
252
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
253 return instance;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
254 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
255
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
256 // @constructor {singleton} foo/bar/Baz
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
257 // @factory {singleton}
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
258 toString: function () {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
259 var parts = [];
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
260
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
261 parts.push(this._type ? "@constructor" : "@factory");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
262
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
263 parts.push(activationNames[this._activationType]);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
264
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
265 if (typeof (this._type) === "string")
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
266 parts.push(this._type);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
267
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
268 return parts.join(" ");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
269 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
270
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
271 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
272
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
273 cls.SINGLETON = SINGLETON_ACTIVATION;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
274 cls.CONTAINER = CONTAINER_ACTIVATION;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
275 cls.CONTEXT = CONTEXT_ACTIVATION;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
276 cls.CALL = CALL_ACTIVATION;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
277 cls.HIERARCHY = HIERARCHY_ACTIVATION;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
278
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
279 var activationNames = [
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
280 "",
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
281 "{singleton}",
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
282 "{container}",
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
283 "{context}",
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
284 "{call}",
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
285 "{hierarchy}"
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
286 ];
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
287
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
288 return cls;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
289 });