PageRenderTime 36ms CodeModel.GetById 28ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 23@import "CPException.j"
 24@import "CPObject.j"
 25@import "CPDictionary.j"
 26
 27/*!
 28    @class CPNotification
 29    @ingroup foundation
 30    @brief A notification that can be posted to a CPNotificationCenter.
 31
 32    Represents a notification for posting to an CPNotificationCenter. Consists
 33    of a name, an object, and an optional dictionary. The notification center
 34    will check for observers registered to receive either notifications with
 35    the name, the object, or both and pass the notification instance on to them.
 36
 37    To create a notification use one of the class methods. The default init
 38    method will throw a CPUnsupportedMethodException.
 39*/
 40@implementation CPNotification : CPObject
 41{
 42    CPString        _name;
 43    id              _object;
 44    CPDictionary    _userInfo;
 45}
 46
 47/*!
 48    Creates a new notification with the specified name, object and dictionary.
 49    @param aNotificationName the name of the notification
 50    @param anObject the associated object
 51    @param aUserInfo the associated dictionary
 52    @return the new notification
 53*/
 54+ (CPNotification)notificationWithName:(CPString)aNotificationName object:(id)anObject userInfo:(CPDictionary)aUserInfo
 55{
 56    return [[self alloc] initWithName:aNotificationName object:anObject userInfo:aUserInfo];
 57}
 58
 59/*!
 60    Creates a new notification with the specified name and object.
 61    @param aNotificationName the name of the notification
 62    @param anObject the associated object
 63    @return the new notification
 64*/
 65+ (CPNotification)notificationWithName:(CPString)aNotificationName object:(id)anObject
 66{
 67    return [[self alloc] initWithName:aNotificationName object:anObject userInfo:nil];
 68}
 69
 70/*!
 71    @throws CPUnsupportedMethodException always, because the method should not be used
 72*/
 73- (id)init
 74{
 75    [CPException raise:CPUnsupportedMethodException
 76                reason:"CPNotification's init method should not be used"];
 77}
 78
 79/*!
 80    Initializes the notification with a name, object and dictionary
 81    @param aNotificationName the name of the notification
 82    @param anObject the associated object
 83    @param aUserInfo the associated dictionary
 84    @return the initialized notification
 85    @ignore
 86*/
 87- (id)initWithName:(CPString)aNotificationName object:(id)anObject userInfo:(CPDictionary)aUserInfo
 88{
 89    self = [super init];
 90
 91    if (self)
 92    {
 93        _name = aNotificationName;
 94        _object = anObject;
 95        _userInfo = aUserInfo;
 96    }
 97
 98    return self;
 99}
100
101/*!
102    Returns the notification name.
103*/
104- (CPString)name
105{
106    return _name;
107}
108
109/*!
110    Returns the notification's object.
111*/
112- (id)object
113{
114    return _object;
115}
116
117/*!
118    Returns the notification's dictionary.
119*/
120- (CPDictionary)userInfo
121{
122    return _userInfo;
123}
124
125@end