How do I configure the platform?
Once compiled, you might want to set some configuration entries for the platform. The entry-point for all configurations is the file /conf/smartproducts.properties.
The entries of this file are used as the context of the OSGi container and can be programmatically used in the platform to read properties from this file.
Example:
# ---------------------------------------------------------------------- # InteractionManager # ---------------------------------------------------------------------- eu.smartproducts.interaction.InteractionManager=conf/InteractionManager/interactionManager.properties
This property is used by the Interaction Manager to load it's own configuration file, where specific information are provided, e.g. whether to start workflows automatically or not. For details, see the descriptions of the single components, e.g. the configuration of the Interaction Manager.
The property can be read using this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public void start(BundleContext context) throws Exception { // Read InteractionManager specific properties FileInputStream stream; Properties iamProperties = new Properties(); try { if (context.getProperty("eu.smartproducts.interaction.InteractionManager")!=null) { _logger.info("InteractionManager used config file: " + context.getProperty("eu.smartproducts.interaction.InteractionManager").trim()); stream = new FileInputStream( context.getProperty("eu.smartproducts.interaction.InteractionManager").trim()); iamProperties.load(stream); } else { _logger.warn("Please set the property 'eu.smartproducts.interaction.InteractionManager' in 'conf/smartproducts.properties'. This entry should point to the 'interactionManager.properties'."); } } catch (FileNotFoundException e) { _logger.warn(e.getMessage(), e); } catch (IOException e) { _logger.warn(e.getMessage(), e); } }
|
Line 10 contains the code to access the property itself, the rest is just a usecase, what could be done with the data.
context.getProperty("eu.smartproducts.interaction.InteractionManager")
Hint: If you want to get the path to the configuration folder programmatically, you can do this from within the platform by calling:
SmartProductsPlatform.getConfigPath()
This method will return the (system specific) absolute path to the /conf folder of the distribution.
|