Hitachi Vantara Pentaho Community Wiki
Child pages
  • Pentaho ObjectFactory and Spring Enhancements

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Of course in this example the list will contain only one entry.

ISystemConfig

Prior to 5.0 configuration of objects was accomplished by either the SystemSettings object (pentaho.xml), through Spring property replacement, or if within a plugin by way of the settings.xml file. Unfortunately, these systems didn't interoperate well at all. ISystemConfig has been designed to unify configuration with access both programmatically and through Spring.

ISystemConfig holds a collection of IConfiguration(s) objects by name. You can gain a reference to a named configuration with the following:

Code Block
java
java

ISystemConfig sysConfig = PentahoSystem.get(ISystemConfig.class);
IConfiguration aConfig = sysConfig.getConfiguration("someConfig");

ISystemConfig also supports programmatically registering new IConfiguration(s) as well as listing all available configurations.

IConfiguration provides two methods to the user. getProperties() returning a standard java Properties object and update(Properties) which will write-back to the underlying storage if supported.

Programmatic Usage:

Code Block
java
java

ISystemConfig sysConfig = PentahoSystem.get(ISystemConfig.class);
IConfiguration aConfig = sysConfig.getConfiguration("someConfig");
Properties props = aConfig.getProperties();
String someStr = props.getProperty("someProperty");

// update a config
props.setProperty("someProperty", "newValue");
aConfig.update(props);

If you're simply accessing properties, you can call a convenience method directly on ISystemConfig using a CONFIG.PROPEPRTY notation.

Code Block
java
java

ISystemConfig sysConfig = PentahoSystem.get(ISystemConfig.class);
String someStr = sysConfig.getProperty("someConfig.someProperty");

Interaction with Spring

If you're familiar with Spring Property Replacement system the following will look familiar. You can inject values from the ISystemConfig into your beans by adding the following to your ApplicationContent XML document

Code Block
xml
xml

  <bean class="org.pentaho.platform.config.PentahoPropertyPlaceholderConfigurer" >
    <constructor-arg>
      <pen:bean class="org.pentaho.platform.api.engine.ISystemConfig"/>
    </constructor-arg>
  </bean>

Injection is the same as with the Spring Property replacements using the ${CONFIG.PROP} notation

Code Block
xml
xml

<bean class="MyClass">
  <property name="someProperty" value="${someConfig.someProperty}"/>
</bean>

You can provide new IConfiguration(s) from within Spring as well. The ISystemConfig is leveraging the <pen:list/> to collect all available IConfiguration implementations in the system. Below is an example from 5.0 registering the security.properties file as a "security" configuration.

Code Block
xml
xml

  <bean class="org.pentaho.platform.config.SolutionPropertiesFileConfiguration">
    <constructor-arg value="security"/>
    <constructor-arg value="security.properties"/>
    <pen:publish as-type="INTERFACES"/>
  </bean>

Other built-in configurations are available for "repository" corresponding to the pentaho-solutions/system/repository.spring.xml and "system" corresponding to the pentaho-solutions/system/system.properties

The intent of the system is to supplant the usage of pentaho.xml and Plugin settings.xml files. An IConfiguration implementation wrapping the pentaho.xml is available though not installed by default (SystemSettingsConfiguration). The decision was made to scrap pentaho.xml in a later release instead of hiding it.

Plugins should transition to this new system and provide a configuration for their internal use as well as from the system:

Code Block
xml
xml

  <bean class="org.pentaho.platform.config.SolutionPropertiesFileConfiguration">
    <constructor-arg value="myPlugin"/>
    <constructor-arg value="myPlugin/plugin.properties"/>
    <pen:publish as-type="INTERFACES"/>
  </bean>