BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-07-2009, 11:58 PM   #1 (permalink)
New Member
 
Join Date: Apr 2009
Model: 7100
PIN: N/A
Carrier: airtel
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Multiple queries around CodeModuleManager, Class.forClass

Please Login to Remove!

I've searched through the forums, and got a few bits and pieces, enough to be able to do the following:

1) Programmatically download and "launch" a "CLDC Application" COD file: I "stream" a COD file (size less than 85KB) to the Blackberry device, extract its contents into a byte buffer,do CodeModuleManager.createNewModule() on the byte buffer, use CodeModuleManager.saveNewModule() to register into library, get a CMM_OK (or whatever the notification was for successful load). After this, I can use ApplicationManager to get the app descriptor for the code module, and then ApplicationManager.launch() it. This works fine.

2) Programmatically download a "CLDC" library, and TRIED to load a class from it:
This is a little more involved:
a) created a library COD defining an interface IUsable with a foo() method
b) wrote a CLDC application COD that references this COD, and can therefore call foo() on any object implementing IUsable
c) wrote a library COD containing a class that implements IUsable (of course, it too references the library COD in a).). Let the class that implements IUsable be "com.test.Usable".

Now... I deploy COD a) and COD b) through the Eclipse IDE (I use a simulator) normally. And then.. I "programmatically" stream the COD c) to the device, and I am even able to follow steps in test 1) to "save" the code module into library (note that I do not reset the device or anything after it).

I thought that the only thing I would have to do in COD b) is:

IUsable usable = (IUsable) Class.forClass("com.test.Usable").newInstance();
if(null == usable) {
usable.foo();
}

However, when I do this, I get a ClassCastException.. which i assume means that I've missed some step in "linking" my COD c) at run-time to the COD b).

Now, my questions:

1. I wanted to know, IS there a step I'm missing in order to accomplish above test? In essence, what I'm trying to do is like a "dynamic" classloader, where you can get new classes merely by "downloading" library CODs containing those classes, and then use CodeModuleManager APIs to install those modules into the Blackberry. The problem here is that the library COD gets installed, but I'm still unable to load classes from it. I wonder if there's a way to dynamically define a dependency (like what we do in .JAD files)?

2. What sort of checks will I have to do when I try "updating" such library modules (assuming my question 1. gets solved)? I'm guessing that everytime I want to update the library, I'll have to: a) stop other modules using it b) delete the module c) replace the COD d) install the COD? Or can I make use of the "overwrite code module" feature in CodeModuleManager to make it easier?

Last edited by neeltiwari : 04-07-2009 at 11:59 PM. Reason: some wrong references.. corrected it now
Offline  
Old 04-08-2009, 07:59 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

When you call Class.forClass("com.test.Usable").newInstance(); are you calling it from an object in the com.test package? Also there are restrictions on using com and net for third party classes, though com.test may be OK, I can't remember.
Offline  
Old 04-10-2009, 05:34 PM   #3 (permalink)
New Member
 
Join Date: Apr 2009
Model: -
PIN: N/A
Carrier: -
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can confirm that it's definitely possible to do what you've described when dealing with a built-in interface (the one that's in the JDE's library). I haven't tried this with a custom interface though.

All I can suggest is to check whether it works after you reboot the device by pulling the battery. Moreover, make sure you don't change the interface so that the interface that's in COD a) is exactly the same as the one that was referenced when building COD c). If it still doesn't work, try installing COD a) as part of a CodeModuleGroup, and then installing COD c) as part of another CodeModuleGroup that lists the former CodeModuleGroup as its dependency.

As to overwriting, you don't need to worry about stopping other modules. You need to use forceOverwrite = true in CodeModuleManager.saveNewModule. If you do this as part of a transaction (undocumented CodeModuleManager API), then it will tell you whether a reboot is required when you commit the transaction. A reboot is usually required after you overwrite or delete a module that was in use at the time. If a reboot is required, the changes won't fully apply and you might get weird results until you reboot. You could also use CodeModuleManager.isResetRequired() and CodeModuleManager.promptForResetIfRequired() on 4.2.0+.

P.S. You don't need to check for null after Class.forName("...").newInstance().

Last edited by klyubin : 04-10-2009 at 06:04 PM.
Offline  
Old 04-28-2009, 07:04 AM   #4 (permalink)
New Member
 
Join Date: Apr 2009
Model: 7100
PIN: N/A
Carrier: airtel
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks for the info! Can close...

I'll try out the suggestions you mentioned. In the meantime, I've gone with the "separate CODs communicating through RuntimeStore" approach (instead of the "pure" dynamic class loading), its working out for now.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.