Package org.backsource.utils.resource

A flexible package to look up resources.

See:
          Description

Interface Summary
URLFactory Return a valid URL from URI.
 

Class Summary
ClassContextURLFactory An URL factory which translates the URI into a resource available in the classpath.
ServletContextURLFactory Resolve URI:s to URL by looking them up in the ServletContext.
TestURI TestURI.java Created: Thu Jan 24 15:42:44 2002
URI A class to represent a Uniform Resource Identifier (URI) and to get a valid URL representation from the URI.
URIFactory A factory that produces URI:s that translates URI:s to URL with the help of URLFactories.
URIFactoryContext A dynamic singleton used by URI to lookup an URIFactory.
ValidURLFactory Factory to use for URI:s that is URL:s backed by a URLStreamHandler.
 

Exception Summary
MalformedURIException Thrown when URI is now wellformed.
 

Package org.backsource.utils.resource Description

A flexible package to look up resources.

This package is based in an idea and a couple of core classes.The idea constits of these two building blocks:

The basis to solve this problem is the introduction of the URI class. This class may be use to instanciate a name of a resource. There might be a whole series of schema/proptocol types for resources, since they are not bound to a specific locations. For examples servlet:myprop, classpath:/my/class.class and much more.

For this to be interesting we however need a way to get at the location of the resource, we need to be able to reach it to use it. To do this we need to translate it into an URL. An URL is actually also an URI, with one difference, it points to a physical location. To get the URL of an URI we use the URI.getURL().

But how do we translate URI:s to URL:s. The URI uses an URIFactory object to do this. The URIFactory is sort of a registry. You register zero or more different URLFactory instances with a URIFactory. When an URIFactory gets a request to translate an URI to an URL it looks up the schema in the URI (makes it named "default" if its empty) and tries to lookup a URLFactory registered by that schema. If no factory is registered it tries the normal URL (with its preregistered factorys) and lastly tries the default URLFactory.

But how does URI know which URIFactory to use? There are basically thre ways. You congigure URI with a factory, you use the getURL method wich takes a factory or you use URI without setting a factory and gets some magic. What magic? If URI does not have a URIFactory it will use URIFactoryContext to look one up. The URIFactoryContext is a very dynamic singleton, based on the patterns developed in org.backsource.utils.lang. Basically you can set different URIFactory in URIFactoryContext wich will be made available to URI indifferent cointexts, be it thread, classloader or global.

For more examples see URIFactory.



Copyright © 2000-2004 Backsource. All Rights Reserved.