commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jakarta-commons Wiki] Update of "ResourcesUserGuideCreating" by NiallPemberton
Date Mon, 28 Nov 2005 11:09:15 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by NiallPemberton:
http://wiki.apache.org/jakarta-commons/ResourcesUserGuideCreating

The comment on the change is:
add Creating implementation page to user guide

New page:
|| [wiki:ResourcesUserGuide Home] || [wiki:ResourcesUserGuideImplementations Previous] ||

----
= 4. Creating a Resources Implementation =

You can implement the [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/Resources.html
Resources] and [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/ResourcesFactory.html
ResourcesFactory] interfaces directly, however, by far the easiest way is to use one of the
'''base''' implementations provided.

The two '''base''' Resources classes are:
 * [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/ResourcesBase.html
ResourcesBase] - implements Resources
    * '''{{{void:init()}}}''' - (optional) for initialization processing.
    * '''{{{Iterator:getKeys()}}}''' - (required) return the set of keys in this Resources
    * '''{{{Object:getObject(key, Locale, TimeZone)}}}''' - (required) retrieve the content
for a key/Locale/Timezone
 * [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/CollectionResourcesBase.html
CollectionResourcesBase] - extends '''!ResourcesBase''' and provides a mechanism for caching
a set of '''Map'''s containing key/value pairs for a Locale.
    * '''{{{void:init()}}}''' - (optional) for initialization processing.
    * '''{{{Map:getLocaleMap(baseUrl, Locale)}}}''' (required) returns a Map of key/value
pairs for a Locale.

== 4.1 ResourcesBase ==

{{{
    public class MyResources extends ResourcesBase {

        private String config;

        public MyResources(String name, config) {
            super(name);
            this.config = config;
        }

        public void init() {
            // do initialization here, if required
        }

        public Iterator getKeys() {
            // must implement this method
        }

        public Object getObject(String key, Locale locale, TimeZone timeZone) {
            // must implement this method
        }

    }
}}}

== 4.2 CollectionsResourcesBase ==

{{{
    public class MyResources extends CollectionsResourcesBase {

        public MyResources(String name, config) {
            super(name, config);
        }

        public void init() {
            // do initialization here, if required
        }

        public Object getLocaleMap(String baseUrl, Locale locale) {
            // must implement this method
        }
    }
}}}

== 4.2 ResourcesFactory ==

To create a '''factory''' for your '''Resources''' implementation, extends the [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/ResourcesFactoryBase.html
ResourcesFactoryBase] ...

{{{
    public class MyResourcesFactory extends ResourcesFactoryBase {

        public MyResources() {
            super();
        }

        protected Resources createResources(String name, String config) {
            Resources resources = new MyResources(name);
            Resources res = new PropertyResources(name, config);
            resources.setReturnNull(isReturnNull());
            resources.init();
            return resources;
        }
    }
}}}

'''N.B''' for implementations to be used in a Web Application there is a [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/WebappResourcesFactoryBase.html
WebappResourcesFactoryBase] factory which includes a '''!ServletContext''' property with appropriate
read/write methods.

----
|| [wiki:ResourcesUserGuide Home] || [wiki:ResourcesUserGuideImplementations Previous] ||

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message