diff options
Diffstat (limited to 'node_modules/montage/data/objectproperty.js')
-rwxr-xr-x | node_modules/montage/data/objectproperty.js | 298 |
1 files changed, 298 insertions, 0 deletions
diff --git a/node_modules/montage/data/objectproperty.js b/node_modules/montage/data/objectproperty.js new file mode 100755 index 00000000..de2e861b --- /dev/null +++ b/node_modules/montage/data/objectproperty.js | |||
@@ -0,0 +1,298 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module montage/data/objectproperty | ||
8 | @requires montage/core/core | ||
9 | @requires montage/core/logger | ||
10 | */ | ||
11 | var Montage = require("montage").Montage; | ||
12 | var Pledge = require("data/pledge").Pledge; | ||
13 | var PledgedSortedSet = require("data/pledge").PledgedSortedSet; | ||
14 | var logger = require("core/logger").logger("objectproperty"); | ||
15 | /** | ||
16 | Description TODO | ||
17 | @private | ||
18 | */ | ||
19 | var _objectPropertyManager = null; | ||
20 | /** | ||
21 | @class module:montage/data/objectproperty.ObjectProperty | ||
22 | @extends module:montage/core/core.Montage | ||
23 | */ | ||
24 | var ObjectProperty = exports.ObjectProperty = Montage.create(Montage,/** @lends module:montage/data/objectproperty.ObjectProperty# */ { | ||
25 | /** | ||
26 | Description TODO | ||
27 | @function | ||
28 | @returns itself | ||
29 | */ | ||
30 | init: { | ||
31 | serializable: false, | ||
32 | enumerable: false, | ||
33 | value: function() { | ||
34 | return this; | ||
35 | } | ||
36 | }, | ||
37 | |||
38 | /** | ||
39 | Add all the properties defined in the blueprint to the target prototype.<br> | ||
40 | If the blueprint is null, this method will make a best attempt to locate it. | ||
41 | @function | ||
42 | @param {Property} prototype TODO | ||
43 | @param {Object} blueprint TODO | ||
44 | */ | ||
45 | apply: { | ||
46 | value: function(prototype, blueprint) { | ||
47 | if (! prototype.hasOwnProperty("blueprint")) { | ||
48 | var info; | ||
49 | info = Montage.getInfoForObject(prototype); | ||
50 | if (info != null && info.isInstance === false) { | ||
51 | if (typeof blueprint === "undefined") { | ||
52 | blueprint = Store.defaultManager.blueprintForPrototype(info.objectName, info.moduleId); | ||
53 | } else if ((blueprint.prototypeName !== info.objectName) || (blueprint.moduleId !== info.moduleId)) { | ||
54 | // Something is wrong, the hierarchies are out of wack | ||
55 | blueprint = null; | ||
56 | } | ||
57 | this.applyWithBlueprint(prototype, blueprint); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | }, | ||
62 | |||
63 | /** | ||
64 | Add all the properties defined in the blueprint to the target prototype. | ||
65 | @function | ||
66 | @param {Property} prototype TODO | ||
67 | @param {Object} blueprint TODO | ||
68 | */ | ||
69 | applyWithBlueprint: { | ||
70 | value: function(prototype, blueprint) { | ||
71 | if (blueprint != null) { | ||
72 | this.addProperties(prototype, blueprint); | ||
73 | if (blueprint.parent !== null) { | ||
74 | this.apply(Object.getPrototypeOf(prototype), blueprint); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | }, | ||
79 | /** | ||
80 | Description TODO | ||
81 | @function | ||
82 | @param {Property} prototype TODO | ||
83 | @param {Object} blueprint TODO | ||
84 | */ | ||
85 | addProperties: { | ||
86 | value: function(prototype, blueprint) { | ||
87 | //for loop over attributes | ||
88 | var i, attribute; | ||
89 | for (i = 0; attribute = blueprint.attributes[i]; i++) { | ||
90 | if (attribute.isDerived) { | ||
91 | this.addDerivedProperty(prototype, attribute); | ||
92 | } else { | ||
93 | this.addProperty(prototype, attribute); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | Montage.defineProperty(prototype, "context", { serializable: false, enumerable: true, value: null }); | ||
98 | Montage.defineProperty(prototype, "_objectId", { serializable: true, enumerable: false, value: null }); | ||
99 | Montage.defineProperty(prototype, "objectId", { | ||
100 | enumerable: true, | ||
101 | serializable: false, | ||
102 | get: function() { | ||
103 | if (this._objectId === null) { | ||
104 | this._objectId = this.blueprint.objectId$Implementation; | ||
105 | } | ||
106 | return this._objectId; | ||
107 | }, | ||
108 | set: function(value) { | ||
109 | if (value !== null) { | ||
110 | this._objectId = value; | ||
111 | } else { | ||
112 | throw Exception.create().initWithMessageTargetAndMethod("Cannot set object Id to null", this, "objectId.set"); | ||
113 | } | ||
114 | } | ||
115 | }); | ||
116 | Montage.defineProperty(prototype, "_blueprint", { serializable: false, enumerable: false, value: blueprint }); | ||
117 | Montage.defineProperty(prototype, "blueprint", { enumerable: false, serializable: false, get: function() { | ||
118 | return this._blueprint; | ||
119 | }}); | ||
120 | Montage.defineProperty(prototype, "isPledge", { serializable: false, enumerable: true, value: false }); | ||
121 | Montage.defineProperty(prototype, "withProperties", { serializable: false, enumerable: false, value: function() { | ||
122 | return null; | ||
123 | }}); | ||
124 | Montage.defineProperty(prototype, "willRead", { serializable: false, enumerable: false, value: this.willRead }); | ||
125 | Montage.defineProperty(prototype, "willModify", { serializable: false, enumerable: false, value: this.willModify }); | ||
126 | // Enable access to the 'inherited' get method for easy override. | ||
127 | Montage.defineProperty(prototype, "blueprintGet", { serializable: false, enumerable: false, value: blueprint.blueprintGet}); | ||
128 | // Enable access to the 'inherited' set method for easy override. | ||
129 | Montage.defineProperty(prototype, "blueprintSet", { serializable: false, enumerable: false, value: blueprint.blueprintSet}); | ||
130 | // Provide a storage property for any state the access layer need to store in teh object. This would typically be a database snapshot reference. | ||
131 | Montage.defineProperty(prototype, "_opaqueAccessState", { serializable: false, enumerable: false, value: null}); | ||
132 | } | ||
133 | }, | ||
134 | /** | ||
135 | Description TODO | ||
136 | @function | ||
137 | @param {Property} prototype TODO | ||
138 | @param {Object} attribute TODO | ||
139 | */ | ||
140 | addProperty: { | ||
141 | value: function(prototype, attribute) { | ||
142 | this.addPropertyStorage(prototype, attribute); | ||
143 | this.addPropertyDefinition(prototype, attribute); | ||
144 | this.addPropertyStoredValue(prototype, attribute); | ||
145 | } | ||
146 | }, | ||
147 | /** | ||
148 | Description TODO | ||
149 | @function | ||
150 | @param {Property} prototype TODO | ||
151 | @param {Object} attribute TODO | ||
152 | */ | ||
153 | addPropertyStorage: { | ||
154 | value: function(prototype, attribute) { | ||
155 | var storageKey = "_" + attribute.name, | ||
156 | storageDefinition = null; | ||
157 | if (! prototype.hasOwnProperty(storageKey)) { | ||
158 | if (attribute.isToMany) { | ||
159 | storageDefinition = { | ||
160 | value: [], | ||
161 | enumerable: false, | ||
162 | serializable: true, | ||
163 | distinct: true | ||
164 | }; | ||
165 | } else { | ||
166 | storageDefinition = { | ||
167 | value: null, | ||
168 | enumerable: false, | ||
169 | serializable: true | ||
170 | }; | ||
171 | } | ||
172 | Montage.defineProperty(prototype, storageKey, storageDefinition); | ||
173 | } else { | ||
174 | // We have an issue here. The developer should not override the storage value. | ||
175 | } | ||
176 | } | ||
177 | }, | ||
178 | /** | ||
179 | Description TODO | ||
180 | @function | ||
181 | @param {Property} prototype TODO | ||
182 | @param {Object} attribute TODO | ||
183 | */ | ||
184 | addPropertyDefinition: { | ||
185 | value : function(prototype, attribute) { | ||
186 | var propertyKey = attribute.name, | ||
187 | propertyDefinition = null; | ||
188 | if (! prototype.hasOwnProperty(propertyKey)) { | ||
189 | propertyDefinition = { | ||
190 | get: function() { | ||
191 | return this.blueprintGet(propertyKey); | ||
192 | }, | ||
193 | enumerable: true, | ||
194 | serializable: false | ||
195 | }; | ||
196 | if (! attribute.readOnly) { | ||
197 | propertyDefinition.set = function(value) { | ||
198 | return this.blueprintSet(propertyKey, value); | ||
199 | }; | ||
200 | } | ||
201 | Montage.defineProperty(prototype, propertyKey, propertyDefinition); | ||
202 | } else { | ||
203 | // The developer has already created the property method do nothing. | ||
204 | } | ||
205 | } | ||
206 | }, | ||
207 | /** | ||
208 | Description TODO | ||
209 | @function | ||
210 | @param {Property} prototype TODO | ||
211 | @param {Object} attribute TODO | ||
212 | */ | ||
213 | addPropertyStoredValue: { | ||
214 | value: function(prototype, attribute) { | ||
215 | var storedValueKey = attribute.name + "$Storage", | ||
216 | storedValueDefinition = null; | ||
217 | if (! prototype.hasOwnProperty(storedValueKey)) { | ||
218 | if (attribute.isToMany) { | ||
219 | storedValueDefinition = { | ||
220 | value: [], | ||
221 | enumerable: false, | ||
222 | serializable: false, | ||
223 | distinct: true | ||