1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2007 1&1 Internet AG, Germany, http://www.1and1.org
License:
LGPL: http://www.gnu.org/licenses/lgpl.html
EPL: http://www.eclipse.org/org/documents/epl-v10.php
See the LICENSE file in the project's top-level directory for details.
Authors:
* Sebastian Werner (wpbasti)
* Andreas Ecker (ecker)
************************************************************************ */
/* ************************************************************************
#module(core)
#load(qx.core.Init)
#resource(static:static)
************************************************************************ */
/**
* The qooxdoo root class. All other classes are direct or indirect subclasses of this one.
*
* This class contains methods for:
* <ul>
* <li> object management (creation and destruction) </li>
* <li> logging & debugging </li>
* <li> generic getter/setter </li>
* <li> user data </li>
* <li> settings </li>
* <li> internationalization </li>
* </ul>
*
* @param vAutoDispose {Boolean ? true} whether the object should be automatically disposed
*/
qx.OO.defineClass("qx.core.Object", Object,
function(vAutoDispose)
{
this._hashCode = qx.core.Object._availableHashCode++;
if (vAutoDispose !== false)
{
this._dbKey = qx.core.Object._db.length;
qx.core.Object._db.push(this);
}
});
/*
---------------------------------------------------------------------------
DEFAULT SETTINGS
---------------------------------------------------------------------------
*/
qx.Settings.setDefault("enableDisposerDebug", false);
/* ************************************************************************
Class data, properties and methods
************************************************************************ */
qx.Class._availableHashCode = 0;
qx.Class._db = [];
qx.Class._disposeAll = false;
/**
* Returns an unique identifier for the given object. If such an identifier
* does not yet exist, create it.
*
* @param o {Object} the Object to get the hashcode for
* @return {Integer} unique identifier for the given object
*/
qx.Class.toHashCode = function(o)
{
if(o._hashCode != null) {
return o._hashCode;
}
return o._hashCode = qx.core.Object._availableHashCode++;
}
/**
* Destructor. This method is called by qooxdoo on object destruction.
*
* Any class that holds resources like links to DOM nodes must overwrite
* this method and free these resources.
*/
qx.Class.dispose = function()
{
// var logger = qx.log.Logger.getClassLogger(qx.core.Object);
// logger.debug("Disposing Application");
// var vStart = (new Date).valueOf();
qx.core.Object._disposeAll = true;
var vObject;
for (var i=qx.core.Object._db.length-1; i>=0; i--)
{
vObject = qx.core.Object._db[i];
if (vObject && vObject._disposed === false)
{
// logger.debug("Disposing: " + vObject);
vObject.dispose();
}
}
// logger.debug("Done in: " + ((new Date).valueOf() - vStart) + "ms");
}
/**
* Summary of allocated objects
*
* @return {String} summary of allocated objects.
*/
qx.Class.summary = function()
{
var vData = {};
var vCounter = 0;
var vObject;
for (var i=qx.core.Object._db.length-1; i>=0; i--)
{
vObject = qx.core.Object._db[i];
if (vObject && vObject._disposed === false)
{
if (vData[vObject.classname] == null)
{
vData[vObject.classname] = 1;
}
else
{
vData[vObject.classname]++;
}
vCounter++;
}
}
var vArrData = [];
for (var vClassName in vData) {
vArrData.push({ classname : vClassName, number : vData[vClassName] });
}
vArrData.sort(function(a, b) {
return b.number - a.number;
});
var vMsg = "Summary: (" + vCounter + " Objects)\n\n";
for (var i=0; i<vArrData.length; i++) {
vMsg += vArrData[i].number + ": " + vArrData[i].classname + "\n";
}
alert(vMsg);
};
/**
* Enable or disable the Object.
*
* The actual semantic of this property depends on concrete subclass of qx.core.Object.
*/
qx.OO.addProperty({ name : "enabled", type : "boolean", defaultValue : true, getAlias : "isEnabled" });
/* ************************************************************************
Instance data, properties and methods
************************************************************************ */
/*
---------------------------------------------------------------------------
UTILITIES
---------------------------------------------------------------------------
*/
/**
* Returns a string represantation of the qooxdoo object.
*
* @return {String} string representation of the object
*/
qx.Proto.toString = function()
{
if(this.classname) {
return "[object " + this.classname + "]";
}
return "[object Object]";
}
/**
* Return unique hash code of object
*
* @return {Integer} unique hash code of the object
*/
qx.Proto.toHashCode = function() {
return this._hashCode;
}
/**
* Returns true if the object is disposed.
*
* @return {Boolean} wether the object has been disposed
*/
qx.Proto.getDisposed = function() {
return this._disposed;
}
/**
* Returns true if the object is disposed.
*
* @return {Boolean} wether the object has been disposed
*/
qx.Proto.isDisposed = function() {
return this._disposed;
}
/**
* Returns a settings from global setting definition
*
* @param vKey {String} the key
* @return {Object} value of the global setting
*/
qx.Proto.getSetting = function(vKey) {
return qx.Settings.getValueOfClass(this.classname, vKey);
}
/*
---------------------------------------------------------------------------
I18N INTERFACE
---------------------------------------------------------------------------
*/
/**
* Translate a message
* Mark the message for translation.
* @see qx.lang.String.format
*
* @param messageId {String} message id (may contain format strings)
* @param varargs {Object} variable number of argumes applied to the format string
* @return {qx.locale.LocalizedString}
*/
qx.Proto.tr = function(messageId, varargs) {
var nlsManager = qx.locale.Manager;
return nlsManager.tr.apply(nlsManager, arguments);
};
/**
* Translate a plural message
* Mark the messages for translation.
*
* Depending on the third argument the plursl or the singular form is chosen.
*
* @see qx.lang.String.format
*
* @param singularMessageId {String} message id of the singular form (may contain format strings)
* @param pluralMessageId {String} message id of the plural form (may contain format strings)
* @param count {Integer} if greater than 1 the plural form otherwhise the singular form is returned.
* @param varargs {Object} variable number of argumes applied to the format string
* @return {qx.locale.LocalizedString)
*/
qx.Proto.trn = function(singularMessageId, pluralMessageId, count, varargs) {
var nlsManager = qx.locale.Manager;
return nlsManager.trn.apply(nlsManager, arguments);
};
/**
* Mark the message for translation but return the original message.
*
* @param messageId {String} the message ID
* @return {String} messageId
*/
qx.Proto.marktr = function(messageId) {
var nlsManager = qx.locale.Manager;
return nlsManager.marktr.apply(nlsManager, arguments);
};
/*
---------------------------------------------------------------------------
LOGGING INTERFACE
---------------------------------------------------------------------------
*/
/**
* Returns the logger of this class.
*
* @return {qx.log.Logger} the logger of this class.
*/
qx.Proto.getLogger = function() {
return qx.log.Logger.getClassLogger(this.constructor);
}
/**
* Logs a debug message.
*
* @param msg {var} the message to log. If this is not a string, the
* object dump will be logged.
* @param exc {var ? null} the exception to log.
*/
qx.Proto.debug = function(msg, exc) {
this.getLogger().debug(msg, this._hashCode, exc);
}
/**
* Logs an info message.
*
* @param msg {var} the message to log. If this is not a string, the
* object dump will be logged.
* @param exc {var ? null} the exception to log.
*/
qx.Proto.info = function(msg, exc) {
this.getLogger().info(msg, this._hashCode, exc);
}
/**
* Logs a warning message.
*
* @param msg {var} the message to log. If this is not a string, the
* object dump will be logged.
* @param exc {var ? null} the exception to log.
*/
qx.Proto.warn = function(msg, exc) {
this.getLogger().warn(msg, this._hashCode, exc);
}
/**
* Logs an error message.
*
* @param msg {var} the message to log. If this is not a string, the
* object dump will be logged.
* @param exc {var ? null} the exception to log.
*/
qx.Proto.error = function(msg, exc) {
this.getLogger().error(msg, this._hashCode, exc);
}
/*
---------------------------------------------------------------------------
COMMON SETTER/GETTER SUPPORT
---------------------------------------------------------------------------
*/
/**
* Sets multiple properties at once by using a property list
*
* @param propertyValues {Object} A hash of key-value pairs.
*/
qx.Proto.set = function(propertyValues)
{
if (typeof propertyValues !== "object") {
throw new Error("Please use a valid hash of property key-values pairs.");
}
for (var prop in propertyValues)
{
try
{
this[qx.OO.setter[prop]](propertyValues[prop]);
}
catch(ex)
{
this.error("Setter of property '" + prop + "' returned with an error", ex);
}
}
return this;
}
/**
* Gets multiple properties at once by using a property list
*
* @param propertyNames {String | Array | Map} list of the properties to get
* @param outputHint {String ? "array"} how should the values be returned. Possible values are "hash" and "array".
*/
qx.Proto.get = function(propertyNames, outputHint)
{
switch(typeof propertyNames)
{
case "string":
return this["get" + qx.lang.String.toFirstUp(propertyNames)]();
case "object":
if (typeof propertyNames.length === "number")
{
if (outputHint == "hash")
{
var h = {};
propertyLength = propertyNames.length;
for (var i=0; i<propertyLength; i++)
{
try{
h[propertyNames[i]] = this["get" + qx.lang.String.toFirstUp(propertyNames[i])]();
}
catch(ex)
{
throw new Error("Could not get a valid value from property: " + propertyNames[i] + "! Is the property existing? (" + ex + ")");
}
}
return h;
}
else
{
propertyLength = propertyNames.length;
for (var i=0; i<propertyLength; i++)
{
try{
propertyNames[i] = this["get" + qx.lang.String.toFirstUp(propertyNames[i])]();
}
catch(ex)
{
throw new Error("Could not get a valid value from property: " + propertyNames[i] + "! Is the property existing? (" + ex + ")");
}
}
return propertyNames;
}
}
else
{
for (var i in propertyNames) {
propertyNames[i] = this["get" + qx.lang.String.toFirstUp(i)]();
}
return propertyNames;
}
default:
throw new Error("Please use a valid array, hash or string as parameter!");
}
}
/*
---------------------------------------------------------------------------
USER DATA
---------------------------------------------------------------------------
*/
/**
* Store user defined data inside the object.
*
* @param vKey {String} the key
* @param vValue {Object} the value of the user data
*/
qx.Proto.setUserData = function(vKey, vValue)
{
if (!this._userData) {
this._userData = {};
}
this._userData[vKey] = vValue;
}
/**
* Load user defined data from the object
*
* @param vKey {String} the key
* @return {Object} the user data
*/
qx.Proto.getUserData = function(vKey)
{
if (!this._userData) {
return null;
}
return this._userData[vKey];
}
/*
---------------------------------------------------------------------------
DISPOSER
---------------------------------------------------------------------------
*/
qx.Proto._disposed = false;
/**
* Dispose this object
*/
qx.Proto.dispose = function()
{
if (this.getDisposed()) {
return;
}
// Dispose user data
if (this._userData)
{
for(var vKey in this._userData) {
this._userData[vKey] = null;
}
this._userData = null;
}
// Finally cleanup properties
if (this._objectproperties)
{
var a = this._objectproperties.split(",");
var d = qx.OO.values;
for (var i=0, l=a.length; i<l; i++) {
this[d[a[i]]] = null;
}
this._objectproperties = null;
}
if (this.getSetting("enableDisposerDebug"))
{
for (var vKey in this)
{
if (this[vKey] !== null && typeof this[vKey] === "object")
{
this.debug("Missing class implementation to dispose: " + vKey);
delete this[vKey];
}
}
}
/*
if (typeof CollectGarbage === "function") {
CollectGarbage();
}
*/
/*
// see bug #258.
if(this._dbKey != this._hashCode) {
console.log("Disposing wrong entry: " + this._dbKey + " vs. " + this._hashCode);
}
*/
// Delete Entry from Object DB
if (this._dbKey != null)
{
if (qx.core.Object._disposeAll)
{
qx.core.Object._db[this._dbKey] = null;
this._hashCode = null;
this._dbKey = null;
}
else
{
delete qx.core.Object._db[this._dbKey];
delete this._hashCode;
delete this._dbKey;
}
}
// Mark as disposed
this._disposed = true;
}
|