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