Skip to main content

Launching an Xlet from an Xlet

11 replies [Last post]
bloomfield
Offline
Joined: 2008-01-28

Hello there,

i want to launch an Xlet out of another one.
More precisely: I downloaded a jar package containing an Xlet (class file) to the persistant strage which i want to start. I read in another thread that i have to use classes of the package org.dvb.application to realize that.
Does anyone have experience with starting Xlets (in jar Files) from Xlets?

cheers
bloomfield

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joe Rice

On Mar 19, 2008, at 10:18 AM, bd-j-dev@mobileandembedded.org wrote:

> I think the AppCacheINfo is supposed to act like the "classpath"
> concept. This is how the BD players knows which files are to be
> referanced when loading in Classes. I think the AppCacheInfo can
> only look in the JAR directory on the disc to find .jar files (or
> folders that can contain .jar files).

Well, AppCacheInfo() in my understanding is mainly to pre-buffer
files, but beyond that, there's a spec requirement that JARs
containing apps listed in the AMT need to be listed in the cache info.
I think the base directory and classpath extension bytes in the BDJO
set the actual classpath.

I was thinking the downloaded JAR would be put in /BDMV/JAR as part of
the Virtual Package created by the VFS update.

But you and Bill have an interesting idea (as you note below) that may
not require that whole VFS update process!

> The question that comes to mind then, is can you use
> java.net.URLClassLoader to dynamically add a .jar file to the
> classpath and then loadin in your class. The other question that
> comes to mind is that if this approach would work to keep in mind
> which ClassLoader you are using and make sure you are loading your
> classes into the same classloader as the BD player.

If not actually running the downloaded application as a separate Xlet,
and running in the current Xlet's context, this is a cool idea. It
would need to be signed with the same credentials as the base JAR
(which will need to be signed to read the downloaded file).

Cheers,
Joe

---------------------------------------------------------------------
To unsubscribe, e-mail: bd-j-dev-unsubscribe@hdcookbook.dev.java.net
For additional commands, e-mail: bd-j-dev-help@hdcookbook.dev.java.net

billf
Offline
Joined: 2004-02-13

The other piece of this is the idea of downloading an xlet. In the original question, the xlet is stored to persistent storage. One way of launching a downloaded xlet like this would be to put it in the BUDA, and use the VFS APIs to incorporate it into a disc image.

But perhaps it's helpful to step back from the specifics of the question, and instead discuss how downloaded code can be incorporated into an xlet. You could, for example, have a "skeleton" xlet already on the disc. That xlet could load code from another source using URLClassLoader, and thus, in effect, your xlet would be running downloaded code. URLClassLoader is defined in java.net, and the URL can refer to anything you can use to load a byte[], including from an http server.

Using URLClassLoader in this way might be subject to some interesting issues. First among them would be the permissions model - it is likely (and I believe it's perfectly within spec) that a player would treat such "downloaded" code as untrusted. Of course, the standard java.security.ProtectionDoman mechanisms and all that are available to manage the interface between trusted, signed code that is bundled on the disc, and the (most likely) untrusted code that it loads.

Perhaps a more significant issue might be that downloading code using URLClassLoader hasn't been widely tried in practice, to my knowledge. Just be aware that such a usage would be somewhat pioneering.

The conservative way of doing downloaded code is definitely VFS, though that has the downside of only working on (if memory serves) profile 1.1 and profile 2 players.

Bill

dbreitenfeld
Offline
Joined: 2007-03-18

I think the AppCacheINfo is supposed to act like the "classpath" concept. This is how the BD players knows which files are to be referanced when loading in Classes. I think the AppCacheInfo can only look in the JAR directory on the disc to find .jar files (or folders that can contain .jar files).

The question that comes to mind then, is can you use java.net.URLClassLoader to dynamically add a .jar file to the classpath and then loadin in your class. The other question that comes to mind is that if this approach would work to keep in mind which ClassLoader you are using and make sure you are loading your classes into the same classloader as the BD player.

Not sure if theis helps.

Denny B.
-------------------------------------------------------------------------------------------------------------
[i]NetBlender DoStudio Blu-ray Team - DSA - http://dostudio.netblender.com [/i]

dbreitenfeld
Offline
Joined: 2007-03-18

Hi bloomfield,

If you try and use the URLClassLoader and run into problems feel free to shoot me an email. I have a good amount of experience using the the ClassLoader especially when it comes to using different ones at the same time.

Good Luck!

Denny B.
-------------------------------------------------------------------------------------------------------------
[i]NetBlender DoStudio Blu-ray Team - DSA - http://dostudio.netblender.com [/i]

ashokabk
Offline
Joined: 2008-08-25

ClassLoader security exception due to permission settings on the device. Same code works fine perfectly in ArcSoft and WinDVD players. Pls suggest if you have any inputs on this.

Please refer the highlighted code in blue color.

***********************************************************************************************
// Get the system class loader
ClassLoader rootClassLoader = this.getClass().getClassLoader();
// Create class loader for extension "libraries"
ArrayList libraryURLCollection = new ArrayList();

// Prepare list of extensions (.jar) files to load
// Path is /VP/BDMV/ext/00001.jar, /VP/BDMV/ext/00002.jar, /VP/BDMV/ext/00003.jar
// Path is /VP/BDMV/ext/00004.jar, /VP/BDMV/ext/00005.jar, /VP/BDMV/ext/00006.jar
Extension ei;
for (Iterator it = libraries.iterator(); it.hasNext();) {
try {
ei = (Extension) it.next();
libraryURLCollection.add(ei.getCodeSource());
} catch (java.net.MalformedURLException thrown) {
log( "createExtensions()");
}
}

try{
SecurityManager security = System.getSecurityManager();
security.checkCreateClassLoader();
}
catch(Exception e){
log( "Security exception is thrown.");
}

[b] ClassLoader librariesCL = new URLClassLoader((URL[]) libraryURLCollection1.toArray(new URL[0]), rootClassLoader);[/b]

// Initialize class loader in each extension, using librariesCL as
// the parent class loader. Extensions are initialized in parallel.
Collection tasks = new ArrayList();
PlatformInit pm = PlatformInit.getInstance();
//for(Extension ei : extensions) {
Extension ei1;
for (Iterator it = extensions.iterator(); it.hasNext();) {
ei1 = (Extension) it.next();
final ClassLoader pcl = librariesCL;
final Extension fei = ei1;
// Initialize rest of them in parallel.
JoinableTask task = new JoinableTask() {
public void execute() {
try {
fei.initClassLoader(pcl);
} catch (Exception err) {
log("Unable to create class loader for " + fei + ".");
}
}
public String toString() {
return "createExtensions:" + fei;
}
};
tasks.add(task);
pm.scheduleTask(task);
}
// Join tasks to make sure all extensions are
// initialized at this point.
JoinableTask task;
for (Iterator it = tasks.iterator(); it.hasNext();) {
try {
task = (JoinableTask) it.next();
log("Task========"+task);
task.join();
} catch (InterruptedException ie) {
// ignore
}
}
}

stanavzan
Offline
Joined: 2006-11-07

Calling URLClassLoader constructor directly must result in SecurityException according to the BD-J/MHP security policy. Please use URLClassLoader.newInstance(), which is not security constrained.

Regards,
Stan

bloomfield
Offline
Joined: 2008-01-28

Hey everybody,

thanks very much for all the replies.
I will check this out and let you know which solution worked best for me.

Cheers
bloomfield

dbreitenfeld
Offline
Joined: 2007-03-18

Hi Bloomfield and Joe,

Our team reminded me that the patterns used by castor (http://www.castor.org/xml-mapping.html) would work well for dynamically loading an xlet. It can dynamically load objects based on XML files and .jar files that were not part of the original classpath. Might be too much over head for BD-J but the patterns used might be a good start.

Hope that helps.

Denny B.
-------------------------------------------------------------------------------------------------------------
[i]NetBlender DoStudio Blu-ray Team - DSA - http://dostudio.netblender.com [/i]

dbreitenfeld
Offline
Joined: 2007-03-18

Hi Bloomfield,

Have you checked out the source code to the HD Cookbook? Correct me if I'm wrong but I believe there is code on starting an xlet from a different .jar file that you might find useful.

Cheers,

Denny B.
-------------------------------------------------------------------------------------------------------------
[i]NetBlender DoStudio Blu-ray Team - DSA - http://dostudio.netblender.com[/i]

chihiro_saito
Offline
Joined: 2006-11-08

Hi -

Like Denny said, we do have an example in our hdcookbook repository... take a look at MonitorXlet under trunk/grin/xlets/bookmenu/src/com/hdcookbook/bookmenu/monitor.

MonitorXlet is jarred as 00001.jar, and it can stop/start GameXlet (00003.jar) and MenuXlet (00002.jar). Note that stop/start code lives in MonitorIXCListener, and it uses IXC (inter-xlet communcation APIs) to let the methods be invoked from other xlets.

Chihiro

Joe Rice

Note that if you're downloading the new app, you'll probably need to
download a new BDJO listing that JAR in the ApplicationCacheInfo() and
also listing the Xlet in the AMT. I believe it's a spec requirement
that all Xlets and JARs containing those Xlets be referenced in the
BDJO.

Cheers,
Joe

On Mar 19, 2008, at 9:48 AM, bd-j-dev@mobileandembedded.org wrote:

> Hi -
>
> Like Denny said, we do have an example in our hdcookbook
> repository... take a look at MonitorXlet under trunk/grin/xlets/
> bookmenu/src/com/hdcookbook/bookmenu/monitor.
>
> MonitorXlet is jarred as 00001.jar, and it can stop/start GameXlet
> (00003.jar) and MenuXlet (00002.jar). Note that stop/start code
> lives in MonitorIXCListener, and it uses IXC (inter-xlet
> communcation APIs) to let the methods be invoked from other xlets.
>
> Chihiro
> [Message sent by forum member 'chihiro_saito' (chihiro_saito)]
>
> http://forums.java.net/jive/thread.jspa?messageID=264850
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bd-j-dev-unsubscribe@hdcookbook.dev.java.net
> For additional commands, e-mail: bd-j-dev-help@hdcookbook.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: bd-j-dev-unsubscribe@hdcookbook.dev.java.net
For additional commands, e-mail: bd-j-dev-help@hdcookbook.dev.java.net