Context and Deployment Descriptor > The Context Services > URL Access Service

The URL access service is defined by the interface IlpURLAccessService.

It turns relative URLs into absolute URLs or pathnames and can be used to deploy applications and applets without hard coding pathnames or URLs.

More specifically, it can be used to access configuration files, data source files, and resource files.

IlpURLAccessService provides the method getFileLocation which returns the URL of a file in the path, or null if the file is not found. This method takes as its parameter a relative URL or pathname as follows:

public java.net.URL getFileLocation (String filename);

Optionally, this service also provides the method getFileLocation with two optional parameters which specify whether the file shall be searched for in the CLASSPATH (directories and jars) or not, as follows:

public java.net.URL getFileLocation (String filename,
                                     boolean searchClassPathFirst,
                                     boolean searchClassPathLast)
How to Initialize the URL Access Service Through the Deployment Descriptor File

The URL access service can be initialized in the deployment descriptor file using the tag <urlAccess>.

[<urlAccess [verbose="bool"] [documentBase="xxx"]>
   [<relativePath>xxx</relativePath>]*
   [<absolutePath>xxx</absolutePath>]*
</urlAccess>]

For:

How to Customize the URL Access Service Through the Deployment Descriptor

The following example illustrates the customization of the URL access service through the deployment descriptor:

<urlAccess>
    <!-- Add relative path to sample root directory -->
    <relativePath>../..</relativePath>
</urlAccess>
How to Use the URL Access Service in an Application

The following code extract shows you how you can use the URL access service in your application:

IlpContext context = IltSystem.GetDefaultContext();
IlpNetwork networkComponent = new IlpNetwork(context);
 
IlpURLAccessService urlService = context.getURLAccessService();
URL url = urlService.getFileLocation("europe.ivl");
if (url != null) {
  networkComponent.addBackgroundURL(url);
} else {
  System.err.println("Background file could not be found.");
}

By default, the URL access service is implemented by the class IlpDefaultURLAccessService. This default implementation uses one base URL that is usually defined according to the deployment model:

You can specify additional paths to the locations to be searched for a given filename. These additional paths can be:

How to Use the URL Access Service Through the API

The following example illustrates the use of the URL access service through the API:

IlpDefaultURLAccessService accessService = new IltDefaultURLAccessService();
accessService.setDocumentBase(new URL("file:C:/myfiles/"));
accessService.addRelative("myname/");
acesssService.addAbsolute(new URL("file://nfs/shared/resources/"));
accessService.addRelative("my.jar");
accessService.addAbsolute(new URL("file://nfs/shared/resources.jar"));

A call to getFileLocation("myresource") will return one of the following URLs:

file:C:/myfiles/myname/myresource
file://nfs/shared/resources/myresource
jar:file:C:/myfiles/my.jar!/myresource
jar:file://nfs/shared/resources.jar!/myresource

For details about the file URL syntax, refer to http://www.w3.org/Addressing/rfc1738.txt.

For details about the jar URL syntax, refer to http://java.sun.com/javase/6/docs/api/java/net/JarURLConnection.html.