/Foundation/CPNotification.j

http://github.com/cacaodev/cappuccino · Unknown · 125 lines · 111 code · 14 blank · 0 comment · 0 complexity · 0c55c7af780aeca42f10e7dbdaa33868 MD5 · raw file

  1. /*
  2. * CPNotification.j
  3. * Foundation
  4. *
  5. * Created by Francisco Tolmasky.
  6. * Copyright 2008, 280 North, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. @import "CPException.j"
  23. @import "CPObject.j"
  24. @import "CPDictionary.j"
  25. /*!
  26. @class CPNotification
  27. @ingroup foundation
  28. @brief A notification that can be posted to a CPNotificationCenter.
  29. Represents a notification for posting to an CPNotificationCenter. Consists
  30. of a name, an object, and an optional dictionary. The notification center
  31. will check for observers registered to receive either notifications with
  32. the name, the object, or both and pass the notification instance on to them.
  33. To create a notification use one of the class methods. The default init
  34. method will throw a CPUnsupportedMethodException.
  35. */
  36. @implementation CPNotification : CPObject
  37. {
  38. CPString _name;
  39. id _object;
  40. CPDictionary _userInfo;
  41. }
  42. /*!
  43. Creates a new notification with the specified name, object and dictionary.
  44. @param aNotificationName the name of the notification
  45. @param anObject the associated object
  46. @param aUserInfo the associated dictionary
  47. @return the new notification
  48. */
  49. + (CPNotification)notificationWithName:(CPString)aNotificationName object:(id)anObject userInfo:(CPDictionary)aUserInfo
  50. {
  51. return [[self alloc] initWithName:aNotificationName object:anObject userInfo:aUserInfo];
  52. }
  53. /*!
  54. Creates a new notification with the specified name and object.
  55. @param aNotificationName the name of the notification
  56. @param anObject the associated object
  57. @return the new notification
  58. */
  59. + (CPNotification)notificationWithName:(CPString)aNotificationName object:(id)anObject
  60. {
  61. return [[self alloc] initWithName:aNotificationName object:anObject userInfo:nil];
  62. }
  63. /*!
  64. @throws CPUnsupportedMethodException always, because the method should not be used
  65. */
  66. - (id)init
  67. {
  68. [CPException raise:CPUnsupportedMethodException
  69. reason:"CPNotification's init method should not be used"];
  70. }
  71. /*!
  72. Initializes the notification with a name, object and dictionary
  73. @param aNotificationName the name of the notification
  74. @param anObject the associated object
  75. @param aUserInfo the associated dictionary
  76. @return the initialized notification
  77. @ignore
  78. */
  79. - (id)initWithName:(CPString)aNotificationName object:(id)anObject userInfo:(CPDictionary)aUserInfo
  80. {
  81. self = [super init];
  82. if (self)
  83. {
  84. _name = aNotificationName;
  85. _object = anObject;
  86. _userInfo = aUserInfo;
  87. }
  88. return self;
  89. }
  90. /*!
  91. Returns the notification name.
  92. */
  93. - (CPString)name
  94. {
  95. return _name;
  96. }
  97. /*!
  98. Returns the notification's object.
  99. */
  100. - (id)object
  101. {
  102. return _object;
  103. }
  104. /*!
  105. Returns the notification's dictionary.
  106. */
  107. - (CPDictionary)userInfo
  108. {
  109. return _userInfo;
  110. }
  111. @end