How to dynamically instantiate objects form the FrameWork library?

Hi all,

I read some configuration settings from a file and one of them is the type of an attribute, for instance a DateTimeNullable.

How can I instantiate this object, by only knowing it's ClassType?

I think it can be done by using the FindClass method on the Library class, but how can I find the correct library, i.e. FrameWork?

[363 byte] By [ReneBik] at [2007-11-25 10:09:30]
# 1

If you have a ClassType object, then the instanceAlloc() method will do the trick. If you just have the name of the ClassType, then you could try one of the following:

1) Execute the following call:

MyLibrary = task.part.Findlibrary(

projectName = 'Framework'

distributionID = ''

compatybilitylevel = 0

libraryName= '<not sure what this value is>"

loadOptions=SH_FINDLIB_NOLOAD);

then with the library you call

MyLibrary.FindClass(className='MyClass');

2) Create a class factory that you custom build to include a HashTable that contains the name of each framework class as the key with the actual classtype as the object.

e.g. hashTab.enter(key="DateTimeNullable",object=DateTimeNullable);

...

hastTab.find(key="DateTimeNullable") will return correct classtype.

Then you could do an instanceAlloc on the returning class type.

Regards.

John Parks

INVISION Inc.

704919 at 2007-7-1 20:17:17 > top of Java-index,Application & Integration Servers,Integration Servers...
# 2
I already tried the first option, but I also did not know what the value should be for the libraryName parameter.So for now I use the second option you described, but I keep me recommended for the first option.ThxRen BikPinkRoccade Finance
Rene Bik at 2007-7-1 20:17:17 > top of Java-index,Application & Integration Servers,Integration Servers...
# 3

Rene,

I figured it out. The following code works:

MyLibrary : Library = task.part.Findlibrary(

projectName = 'Framework',

distributionID = '',

compatibilitylevel = 0,

libraryName= 'SP',

loadOptions=SH_FINDLIB_NOLOAD);

c : ClassType = MyLibrary.FindClass(className='qqsp_Integer');

i : IntegerData = (IntegerData)(c.newInstance());

i.setValue(5);

If you export the framework plan you'll see that most of what you need is in the SP library. Good luck.

Regards,

John Parks

john.parks@invisioninc.com

704919 at 2007-7-1 20:17:17 > top of Java-index,Application & Integration Servers,Integration Servers...