Java Reference
In-Depth Information
L
ISTING
11.4
Continued
11
DownloadService ds = null;
ds = (DownloadService)Utilities.getService(“javax.jnlp.DownloadService”);
URL url = null;
try {
url = new URL(Utilities.getBasicService().getCodeBase(), resourceName);
} catch(IOException exc) {
System.out.println(“Creating URL: “+exc);
}
try {
ds.removeResource(url ,null);
System.out.println(“Resource “+url+” removed from JNLP cache.”);
} catch(IOException exc) {
System.out.println(“removing resource from JNLP cache: “+exc);
}
}
}
Persistence
Persistence services are achieved through the use of a
PersistenceService
class that saves
FileContents
objects given a URL as a key. The local file system works like a cache for this
data that is always thought of as being a copy of data stored on the server. The whole concept
is inspired by the cookies mechanism; the primary difference being that the space allowed on
the disk is bigger and more flexible.
The URL-keys work hierarchically. That is, common directories are shared by applications
sharing portions of their codebase.
For example, two applications having codebases can see each other application's data at loca-
tions
http://www.asite.org/pub/
and
http://www.asite.org/
:
•
http://www.asite.org/pub/app1/
•
http://www.asite.org/pub/app2/
Therefore, common data can be organized following remote paths on a Web server.
Each single entry (a pair of a
URL
as a key and a
FileContents
as a value) can be tagged
regarding its relationship with the server-side data cache. Tags are represented as
int
s that can
be accessed via the accessory methods
setTag()
and
getTag()
. We can have three possible
states for data stored locally: