/Frameworks/Debug/Foundation/objj.platform/CPKeyValueCoding.j

http://github.com/jfahrenkrug/MapKit-HelloWorld · Unknown · 200 lines · 200 code · 0 blank · 0 comment · 0 complexity · a3afb7aa60ba58c1a0de6f1ea9129cd8 MD5 · raw file

  1. i;9;CPArray.ji;10;CPObject.ji;14;CPDictionary.jc;8588;
  2. var CPObjectAccessorsForClass = nil,
  3. CPObjectModifiersForClass = nil;
  4. CPUndefinedKeyException = "CPUndefinedKeyException";
  5. CPTargetObjectUserInfoKey = "CPTargetObjectUserInfoKey";
  6. CPUnknownUserInfoKey = "CPUnknownUserInfoKey";
  7. {
  8. var the_class = objj_getClass("CPObject")
  9. if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPObject\""));
  10. var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("_ivarForKey:"), function $CPObject___ivarForKey_(self, _cmd, aKey)
  11. { with(self)
  12. {
  13. var ivar = '_' + aKey;
  14. if (typeof self[ivar] != "undefined")
  15. return ivar;
  16. var isKey = "is" + aKey.charAt(0).toUpperCase() + aKey.substr(1);
  17. ivar = '_' + isKey;
  18. if (typeof self[ivar] != "undefined")
  19. return ivar;
  20. ivar = aKey;
  21. if (typeof self[ivar] != "undefined")
  22. return ivar;
  23. ivar = isKey;
  24. if (typeof self[ivar] != "undefined")
  25. return ivar;
  26. return nil;
  27. }
  28. }), new objj_method(sel_getUid("valueForKey:"), function $CPObject__valueForKey_(self, _cmd, aKey)
  29. { with(self)
  30. {
  31. var theClass = objj_msgSend(self, "class"),
  32. selector = objj_msgSend(theClass, "_accessorForKey:", aKey);
  33. if (selector)
  34. return objj_msgSend(self, selector);
  35. if(objj_msgSend(theClass, "accessInstanceVariablesDirectly"))
  36. {
  37. var ivar = objj_msgSend(self, "_ivarForKey:", aKey);
  38. if (ivar)
  39. return self[ivar];
  40. }
  41. return objj_msgSend(self, "valueForUndefinedKey:", aKey);
  42. }
  43. }), new objj_method(sel_getUid("valueForKeyPath:"), function $CPObject__valueForKeyPath_(self, _cmd, aKeyPath)
  44. { with(self)
  45. {
  46. var keys = aKeyPath.split("."),
  47. index = 0,
  48. count = keys.length,
  49. value = self;
  50. for(; index < count; ++index)
  51. value = objj_msgSend(value, "valueForKey:", keys[index]);
  52. return value;
  53. }
  54. }), new objj_method(sel_getUid("dictionaryWithValuesForKeys:"), function $CPObject__dictionaryWithValuesForKeys_(self, _cmd, keys)
  55. { with(self)
  56. {
  57. var index = 0,
  58. count = keys.length,
  59. dictionary = objj_msgSend(CPDictionary, "dictionary");
  60. for (; index < count; ++index)
  61. {
  62. var key = keys[index],
  63. value = objj_msgSend(self, "valueForKey:", key);
  64. if (value === nil)
  65. objj_msgSend(dictionary, "setObject:forKey:", objj_msgSend(CPNull, "null"), key);
  66. else
  67. objj_msgSend(dictionary, "setObject:forKey:", value, key);
  68. }
  69. return dictionary;
  70. }
  71. }), new objj_method(sel_getUid("valueForUndefinedKey:"), function $CPObject__valueForUndefinedKey_(self, _cmd, aKey)
  72. { with(self)
  73. {
  74. objj_msgSend(objj_msgSend(CPException, "exceptionWithName:reason:userInfo:", CPUndefinedKeyException, objj_msgSend(self, "description") + " is not key value coding-compliant for the key " + aKey, objj_msgSend(CPDictionary, "dictionaryWithObjects:forKeys:", [self, aKey], [CPTargetObjectUserInfoKey, CPUnknownUserInfoKey])), "raise");
  75. }
  76. }), new objj_method(sel_getUid("setValue:forKeyPath:"), function $CPObject__setValue_forKeyPath_(self, _cmd, aValue, aKeyPath)
  77. { with(self)
  78. {
  79. if (!aKeyPath) aKeyPath = "self";
  80. var i = 0,
  81. keys = aKeyPath.split("."),
  82. count = keys.length - 1,
  83. owner = self;
  84. for(; i < count; ++i)
  85. owner = objj_msgSend(owner, "valueForKey:", keys[i]);
  86. objj_msgSend(owner, "setValue:forKey:", aValue, keys[i]);
  87. }
  88. }), new objj_method(sel_getUid("setValue:forKey:"), function $CPObject__setValue_forKey_(self, _cmd, aValue, aKey)
  89. { with(self)
  90. {
  91. var theClass = objj_msgSend(self, "class"),
  92. selector = objj_msgSend(theClass, "_modifierForKey:", aKey);
  93. if (selector)
  94. return objj_msgSend(self, selector, aValue);
  95. if(objj_msgSend(theClass, "accessInstanceVariablesDirectly"))
  96. {
  97. var ivar = objj_msgSend(self, "_ivarForKey:", aKey);
  98. if (ivar)
  99. {
  100. objj_msgSend(self, "willChangeValueForKey:", aKey);
  101. self[ivar] = aValue;
  102. objj_msgSend(self, "didChangeValueForKey:", aKey);
  103. }
  104. return;
  105. }
  106. objj_msgSend(self, "setValue:forUndefinedKey:", aValue, aKey);
  107. }
  108. }), new objj_method(sel_getUid("setValue:forUndefinedKey:"), function $CPObject__setValue_forUndefinedKey_(self, _cmd, aValue, aKey)
  109. { with(self)
  110. {
  111. objj_msgSend(objj_msgSend(CPException, "exceptionWithName:reason:userInfo:", CPUndefinedKeyException, objj_msgSend(self, "description") + " is not key value coding-compliant for the key " + aKey, objj_msgSend(CPDictionary, "dictionaryWithObjects:forKeys:", [self, aKey], [CPTargetObjectUserInfoKey, CPUnknownUserInfoKey])), "raise");
  112. }
  113. })]);
  114. class_addMethods(meta_class, [new objj_method(sel_getUid("accessInstanceVariablesDirectly"), function $CPObject__accessInstanceVariablesDirectly(self, _cmd)
  115. { with(self)
  116. {
  117. return YES;
  118. }
  119. }), new objj_method(sel_getUid("_accessorForKey:"), function $CPObject___accessorForKey_(self, _cmd, aKey)
  120. { with(self)
  121. {
  122. if (!CPObjectAccessorsForClass)
  123. CPObjectAccessorsForClass = objj_msgSend(CPDictionary, "dictionary");
  124. var hash = objj_msgSend(isa, "hash"),
  125. selector = nil,
  126. accessors = objj_msgSend(CPObjectAccessorsForClass, "objectForKey:", hash);
  127. if (accessors)
  128. {
  129. selector = objj_msgSend(accessors, "objectForKey:", aKey);
  130. if (selector)
  131. return selector === objj_msgSend(CPNull, "null") ? nil : selector;
  132. }
  133. else
  134. {
  135. accessors = objj_msgSend(CPDictionary, "dictionary");
  136. objj_msgSend(CPObjectAccessorsForClass, "setObject:forKey:", accessors, hash);
  137. }
  138. var capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substr(1);
  139. if (objj_msgSend(self, "instancesRespondToSelector:", selector = CPSelectorFromString("get" + capitalizedKey)) ||
  140. objj_msgSend(self, "instancesRespondToSelector:", selector = CPSelectorFromString(aKey)) ||
  141. objj_msgSend(self, "instancesRespondToSelector:", selector = CPSelectorFromString("is" + capitalizedKey)) ||
  142. objj_msgSend(self, "instancesRespondToSelector:", selector = CPSelectorFromString("_get" + capitalizedKey)) ||
  143. objj_msgSend(self, "instancesRespondToSelector:", selector = CPSelectorFromString("_" + aKey)) ||
  144. objj_msgSend(self, "instancesRespondToSelector:", selector = CPSelectorFromString("_is" + capitalizedKey)))
  145. {
  146. objj_msgSend(accessors, "setObject:forKey:", selector, aKey);
  147. return selector;
  148. }
  149. objj_msgSend(accessors, "setObject:forKey:", objj_msgSend(CPNull, "null"), aKey);
  150. return nil;
  151. }
  152. }), new objj_method(sel_getUid("_modifierForKey:"), function $CPObject___modifierForKey_(self, _cmd, aKey)
  153. { with(self)
  154. {
  155. if (!CPObjectModifiersForClass)
  156. CPObjectModifiersForClass = objj_msgSend(CPDictionary, "dictionary");
  157. var hash = objj_msgSend(isa, "hash"),
  158. selector = nil,
  159. modifiers = objj_msgSend(CPObjectModifiersForClass, "objectForKey:", hash);
  160. if (modifiers)
  161. {
  162. selector = objj_msgSend(modifiers, "objectForKey:", aKey);
  163. if (selector)
  164. return selector === objj_msgSend(CPNull, "null") ? nil : selector;
  165. }
  166. else
  167. {
  168. modifiers = objj_msgSend(CPDictionary, "dictionary");
  169. objj_msgSend(CPObjectModifiersForClass, "setObject:forKey:", modifiers, hash);
  170. }
  171. if (selector)
  172. return selector === objj_msgSend(CPNull, "null") ? nil : selector;
  173. var capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substr(1) + ':';
  174. if (objj_msgSend(self, "instancesRespondToSelector:", selector = CPSelectorFromString("set" + capitalizedKey)) ||
  175. objj_msgSend(self, "instancesRespondToSelector:", selector = CPSelectorFromString("_set" + capitalizedKey)))
  176. {
  177. objj_msgSend(modifiers, "setObject:forKey:", selector, aKey);
  178. return selector;
  179. }
  180. objj_msgSend(modifiers, "setObject:forKey:", objj_msgSend(CPNull, "null"), aKey);
  181. return nil;
  182. }
  183. })]);
  184. }
  185. {
  186. var the_class = objj_getClass("CPDictionary")
  187. if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPDictionary\""));
  188. var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("valueForKey:"), function $CPDictionary__valueForKey_(self, _cmd, aKey)
  189. { with(self)
  190. {
  191. return objj_msgSend(self, "objectForKey:", aKey);
  192. }
  193. }), new objj_method(sel_getUid("setValue:forKey:"), function $CPDictionary__setValue_forKey_(self, _cmd, aValue, aKey)
  194. { with(self)
  195. {
  196. objj_msgSend(self, "setObject:forKey:", aValue, aKey);
  197. }
  198. })]);
  199. }
  200. i;13;CPArray+KVO.j