Home
Categories
Dictionary
Download
Project Details
Changes Log
Who We Are
FAQ
License

Extensions manifest properties



By default only properties which are defined for the Client or Server are taken into account. However it is possible to define specific properties for J661 extensions.

Defining the names of these properties and the class which will be able to load them is performed in two steps:
  • A SupportedProperties attribute in the extension Manifest file must be specified. The value of this property will define the list of property keys which will be takne into account by the extension, and the Classpath of the loader which will be responsible to load them
  • An associated loader class must exist in the extension

Manifest attribute format

The format of the "SupportedProperties" property in the manifest is is <property1, property2, ...: <ExtensionPropertyLoader classPath>. The first part of the String is the list of property names which the extension support, the second part (after the colon) represent the ClassPath of the ExtensionPropertyLoader which will be responsible of loading the properties of the specified names.

For example, for the following attribute in an extension Manifest: prop, prop2: arinc.ext.MyPropertyLoader: The extension supports two properties ("prop1" and "prop2". This support is performed through an instance of the class arinc.ext.MyPropertyLoader which will be lazily instantiated if one of these properties is present in the properties file.

Loader class

The class responsible for the loading of the properties specific to the extension should implement the ExtensionPropertyLoader interface. This class should have a constructor without arguments. An instance of this class will be created if there is at least one specific property defined for the "SupportedProperties" manifest key.

Beware that the ExtensionPropertyLoader class will be instanciated by reflection by the J661 module, and because of that it can not be known by the extension code itself. To store the properties, it is good advice to store them in a singleton configuration class, which means that after the created ExtensionPropertyLoader instance will be discared, the extension will keep the properties values.

Loader class signature

The ExtensionPropertyLoader interface has the following methods:
      /**
      * Return true if the extension manage the property with the specified key.
      *
      * @param key the property key
      * @return true if the extension manage the property with the specified key
      */
      public boolean hasProperty(String key);

      /**
      * Return the type of the managed property with the specified key.
      *
      * @param key the property key
      * @return the type of the managed property with the specified key, or null if the property is not managed by the extension
      */
      public Class getPropertyType(Object key);

      /**
      * Return the value of the managed property with the specified key.
      *
      * @param key the property key
      * @return the value of the managed property with the specified key, or null if the property is not managed by the extension
      */
      public Object getProperty(Object key);

      /**
      * Set the value of the managed property with the specified key.
      *
      * @param key the property key
      * @param value the property value
      * @return true if the extension manage the property with the specified key
      */
      public boolean setProperty(String key, Object value);

      /**
      * Register the property Loader with the Engine. Do nothing by default.
      *
      * @param engine the Engine
      */
      public default void register(Engine engine);

Example

Suppose that we have a boolean property called "myProperty". We will have the following Manifest property for the extension:
     myProperty: my/package/MyPropertyLoader
We wil define two classes:
  • The MyPropertyLoader class to load the "myProperty" property value
  • A PropertiesConfiguration singleton class to keep the property value

MyPropertyLoader code

The MyPropertyLoader class will have the following code:

      public class TestPropertyLoader implements ExtensionPropertyLoader {
      public static final String KEY_PROP = "myProperty";

      public boolean hasProperty(String key) {
        return key.equals(KEY_PROP);
      }

      public Class getPropertyType(Object key) {
      if (key.equals(KEY_PROP)) {{
      return Boolean.class;
      } else {
      return null;
      }
      }

      public Object getProperty(Object key) {
      if (key.equals(KEY_PROP)) {
      return PropertiesConfiguration.getInstance().prop;
      } else {
      return null;
      }
      }

      public boolean setProperty(String key, Object value) {
      if (key.equals(KEY_PROP)) {
      if (value instanceof Boolean) {
      PropertiesConfiguration.getInstance().prop = (Boolean) value;
      return true;
      } else {
      return false;
      }
      } else {
      return false;
      }
      }

      public void register(Engine engine) {
      }

PropertiesConfiguration code

The PropertiesConfiguration singleton class will have the following code:
      public class PropertiesConfiguration {
      private static PropertiesConfiguration conf = null;
      public boolean prop = false;

      private PropertiesConfiguration() {
      }

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

      }

See also


Categories: client | dev | extensions | server | user

Copyright 2016-2017 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v2 licence