Rogue Wave Server/Rogue Wave Views Integration > Server/Views Mapping > Extending the Server/Views Mapping > Factories
 
Factories
The standard way to have user-defined classes generated by Rogue Wave Server Studio is to subclass Rogue Wave Server Studio classes. However, you can also do this using the Server/Views library.
Since all objects are created by that library, the only way to create instances of derived classes is by using factories. Instead of calling the new global function on the derivable classes, the library uses a factory to create those new objects. You can create your own factories and declare them so that they are called instead of the default factories.
The following factories are supplied:
*IlsSwMemoryTableFactory
*IlsSwGadgetContainerFactory
*IlsSwComponentFactory
Description of a Factory
A factory typically offers the following interface:
class IlsSwMemoryTableFactory
{
public:
virtual IlsSwMemoryTable& newInstance( /* ctor params */) {
return *new IlsSwMemoryTable(/* ctor params */ );
}
static IlsSwMemoryTableFactory& GetSingleton();
static IlsSwMemoryTableFactory* GetSingletonPtr()
{return _Singleton;}
static void SetSingleton(IlsSwMemoryTableFactory* f);
}
*The function newInstance is the function you redefine to create the object of the right type. Its parameters are replaced by placeholders because they are usually those of the constructor of the object you are creating.
*The function GetSingletonPtr can be used to check if a factory has been declared or not. It can return 0.
*The function GetSingleton returns a reference to the current factory. If none has been set, this function creates the default factory and returns it.
*You use the function SetSingleton to declare your factory. You must call this function before you initialize the component via a call to IlsSwComponent::Initialize.
The Server/Views component creates two kinds of objects, for which factories are supplied:
*Server/Views objects (classes that are defined in the mvsw library).
The IlsSwComponentFactory and IlsSwMemoryTableFactory factories create Server/Views objects.
*Rogue Wave Views objects.
For example, the default factory IlsSwGadgetContainerFactory creates IlvGadgetContainer objects.
Example: Using a Factory
Suppose you want the component to use your own IlsSwMemoryTable class, which looks like this:
class MyMemoryTable : public IlsSwMemoryTable {
public:
MyMemoryTable(IlvDisplay* d)
: IlsSwMemoryTable(d, p)
{ /*...*/ }
};
You need to create a factory for this class:
class MyMemoryTableFactory :public IlsSwMemoryTableFactory {
virtual IlsSwMemoryTable&
newInstance(IlvDisplay* d,
const IlsString& viewName = IlsString::Null,
const IlsString& repTypeName = IlsString::Null,
const IlsString& repName = IlsString::Null) {
return *new MyMemoryTable(d);
};
and then, declare this factory before initializing the component:
IlsSwMemoryTable::SetSingleton(new MyMemoryTableFactory());
IlsSwComponent::Initialize(argc, argv);

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.