Mixing Static and Dynamic Types
You can mix static types and dynamic types in the same application. A dynamic type can also inherit from a C++ static type, provided that this static type inherits from IlsDynObject. In this case, the dynamic description should be loaded to the server before any object of this type is instantiated and before any view using this type is opened.
When you declare a dynamic model element (class, attribute, method, or relation), either using the IlsDynModelInterpreter API or through an XMI file, your declaration will be effective only if the corresponding static model element has not already been declared.
A static class inheriting from IlsDynObject may have both “static” attributes defined using the standard C++ modeling classes and dynamic attributes whose implementation is dynamic.
Inheritance from IlsDynObject
If you want to be able to extend a static type with dynamic attributes and relations or if you want to be able to derive a static type with a dynamic type, you must follow the following rules:
Derive your static type from the class
IlsDynObject.
Use the macro
ILS_DYNOBJECT_DECL, ILS_DYNOBJECT_BEGIN and ILS_DYNOBJECT_END or similar macros to declare your type to the server model interpreter.
Call the function
IlsDynObject::initObject just after an instance of your subtype has been built, passing it the appropriate
IlsObjectType instance as its argument, as well as the identifier if your object is an identified object.
When these objects are created from a component request or from an Rogue Wave Script, Rogue Wave® Server instantiates your object by using the standard constructor and calls the function initObject with the right IlsObjectType as the argument.
Note: Do not call the function initObject from the constructor, because virtual methods called from that member function will not be operational as virtual. |
Example
class Network : public IlsDynObject
{
public:
Network(IlsString id) : identifier(*this, n) {}
IlsBoolean setIdentifier(const IlsString& i);
IlsEntry<IlsString> identifier;
ILS_DYNOBJECT_DECL(Network)
};
ILS_DYNOBJECT_WITH_ID_BEGIN(Network, identifier)
ILS_RW_ATTRIBUTE_STRING(Network,
identifier,
getIdentifier,
setIdentifier,
isIdentifierModified)
ILS_DYNOBJECT_END(Network)
static int main(...)
{
IlsString name = "Views";
Network* n = new Network(name);
n->initObject("Network", name);
}
As a dynamic object must be assigned a type (that is, an instance of IlsObjectType), it is not possible to use the API of IlsDynObject before the call to initObject is completed.
Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.