<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.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.
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.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.
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);
myProperty: my/package/MyPropertyLoaderWe wil define two classes:
MyPropertyLoader
class to load the "myProperty" property valuePropertiesConfiguration
singleton class to keep the property valueMyPropertyLoader
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
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; } }
Copyright 2016-2017 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v2 licence