Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

ConfigPropertiesHelper



The ConfigPropertiesHelper class allows to simplify the implementation of the configuration API in Plugins configuration for named properties.

Overview of the API

The named configuration API has the following methods[1]
Their default implementations do nothing
:

Using the Helper

The helper is used by:
Wehn using the ConfigPropertiesHelper, you won't need to add fields fot r the various proeprties in the Plugin configuration class. All the properties values will be handled by the helper itself.

Create a configuration

The ConfigPropertiesHelper instance will maintain the values of all properties. The first thing to do is to create the properties in the constructor of the Plugin configuration.

The result of these methods is a ConfigPropertiesHelper.ConfigSet instance.

Create properties for a configuration

To create a property for a configuration, use either:

Implement the API

Example

In the following example, we have a Plugin configuration with two properties.
   public class OpenPNGImagePluginConfiguration implements Configuration {
      private static OpenPNGImagePluginConfiguration conf = null;
      private final ConfigPropertiesHelper helper = new ConfigPropertiesHelper();

      private OpenPNGImagePluginConfiguration() {
        ConfigPropertiesHelper.ConfigSet set = helper.createDefaultConfiguration();
        set.addIntProperty("maxWidth").setValue(1000);
        set.addBooleanProperty("limitWidth");
      }

      public static OpenPNGImagePluginConfiguration getInstance() {
        if (conf == null) {
          conf = new OpenPNGImagePluginConfiguration();
        }
        return conf;
      }

      @Override
      public Set<String> getConfigurationPropertiesNames(String confName) {
         return helper.getConfigurationPropertiesNames(confName);
      }

      @Override
      public boolean hasConfigurationProperty(String propertyName, String confName) {
        return helper.hasConfigurationProperty(propertyName, confName);
      }

      @Override
      public Object getConfigurationProperty(File dir, String propertyName, String confName) {
        return helper.getConfigurationProperty(dir, propertyName, confName);
      }

      @Override
      public Class getConfigurationPropertyType(String propertyName, String confName) {
        return helper.getConfigurationPropertyType(propertyName, confName);
      }

      @Override
      public void setConfigurationProperty(File dir, String propertyName, String confName, Object property) {
        helper.setConfigurationProperty(dir, propertyName, confName, property);
      }
   }

Notes

  1. ^ Their default implementations do nothing

See also


Categories: Conf

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences