Roedy Green said:
How about an example of use and then let the audience be a judge if
they are Mickey Mouse.
I have attached my implementation of a PreferencesFactory that uses the JNLP
persistence service as the backing store. The goal ot the PersistenceService
is to allow an application to store data on the client and to access that
data later in the same or a different incarnation of the app. That is all it
was designed to do.
It was *NOT* designed as a means for an application to store data on the
client for use by other applications on the client or for the user to access
the information directly. That is why the manner in which the data is stored
on the client is completely at the discretion of the JNLP implementation.
Your problem with the PersistenceService is that you are trying to use it as
a means of storing data for other applications to use. It fails miserably at
that, because it was not designed for that purpose. That does not make it
MickeyMouse, it merely indicates that you are not using it for what it was
designed for.
You talk about the "Where are the files?" But you shouldn't care. That is
all specific to the implementation of the JNLP client software. You aren't
meant to access it yourself.
So here is my implementation of a JnlpPreferencesFactory. (Note there is a
problem with the Preferences implementation that makes substituting a
different preferences factory in JNLP something that cannot be done
transparently. This is a bug in Preferences in that it is using the system
boot loader and not a problem with PersistenceService).
public class JnlpPreferencesFactory implements PreferencesFactory
{
private final PersistenceService ps
=
PersistenceService)ServiceManager.lookup( "javax.jnlp.PersistenceService" );
private class JnlpPreferences extends AbstractPreferences
{
private FileContents contents = null;
private Properties props = null;
private final URL url;
public JnlpPreferences( URL url )
{
super( null, "" );
this.url = url;
}
public JnlpPreferences( JnlpPreferences parent, String name )
throws MalformedURLException
{
super( parent, name );
this.url = new URL( parent.url, name );
}
private Properties getProperties()
{
if( props == null )
{
props = new Properties();
try
{
ps.create( url, 8096 );
}
catch( IOException e )
{
}
try
{
contents = ps.get( url );
props.load( contents.getInputStream() );
}
catch( Exception e )
{
System.out.println( e );
}
}
return props;
}
protected String[] childrenNamesSpi() throws BackingStoreException
{
try
{
return ps.getNames( url );
}
catch( IOException e )
{
System.out.println( e );
throw new BackingStoreException( e );
}
}
protected AbstractPreferences childSpi( String name )
{
try
{
return new JnlpPreferences( this, name );
}
catch( MalformedURLException e )
{
System.out.println( e );
throw new Error( e );
}
}
protected void flushSpi() throws BackingStoreException
{
if( props != null )
{
try
{
props.store( contents.getOutputStream( true ), "" );
}
catch( IOException e )
{
System.out.println( e );
throw new BackingStoreException( e );
}
}
}
protected String getSpi( String key )
{
return getProperties().getProperty( key );
}
protected String[] keysSpi() throws BackingStoreException
{
return (String[])getProperties().keySet().toArray( new
String[ 0 ] );
}
protected void putSpi(String key, String value)
{
getProperties().put( key, value );
try
{
flushSpi();
}
catch( Exception e )
{
}
}
protected void removeNodeSpi() throws BackingStoreException
{
try
{
ps.delete( url );
}
catch( IOException e )
{
throw new BackingStoreException( e );
}
}
protected void removeSpi( String key )
{
getProperties().remove( key );
}
protected void syncSpi() throws BackingStoreException
{
flushSpi();
}
}
public final Preferences userRoot;
public Preferences systemRoot()
{
throw new IllegalAccessError( "System root not supported" );
}
public Preferences userRoot()
{
return userRoot;
}
public JnlpPreferencesFactory() throws UnavailableServiceException
{
BasicService bs
=
(BasicService)ServiceManager.lookup( "javax.jnlp.BasicService" );
URL codeBase = bs.getCodeBase();
userRoot = new JnlpPreferences( codeBase );
}
}