ROTypeActivator

Overview

This class is abstract. Its descendants are used together with the ROTypeManager class to create complex types instances. In simple scenarios, it is enough to call [[[SomeClass alloc] init] autorelease] to successfully create a class instance. When the instance requires a more complex initialization procedure, this procedure is delegated to the ROTypeActivator class descendant. The derived class is then registered to the ROTypeManager together with the target class reference and the target class name. Assuming we are going to register a class named ComplexFoo:

// Declaring the activator class
@interface  ComplexFooActivator : ROTypeActivator {

}
@end

@implementation ComplexFooActivator

- (id)createInstance
{
    ComplexFoo *result = [[[ComplexFoo alloc] init] autorelease];
    [result performSomeInitialization];
    return result;
}

@end
// Registering ComplexFoo class
[[ROTypeManager typeManager] addType:[ComplexFoo class] className:@"ComplexFoo" withActivator:[ComplexFooActivator class]];

When the type manager is requested to create an instance of the ComplexFoo class, it will find the activator class associated with the ComplexFoo name and will call the activator's - (id)createInstance method.
A similar approach can be used to to create an exception instead of a class.

Location

Instance Methods


createExceptionInstance:fromServer:

This method should be overridden in the descendant class if the activator is intended to create exceptions; it should return the exception class.

- (id) createExceptionInstance:(NSString *)iMessage fromServer:(BOOL)iFromServer

Parameters:

  • iMessage: The exception message.
  • iFromServer: The boolean value is passed to the method to indicate whether the exception was raised on the server or the client side.

createInstance

This method should be overridden in the descendant class if the activator is intended to create regular class instances (not exceptions). It should return the instance created.

- (id) createInstance