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.

...

Code Block
<bean id="ISolutionRepository" class="org.pentaho.SomeImpl"/> 

ISolutionRepository repo = PentahoSystem.get(ISolutionRepository.class); 

...

Code Block
<bean id="ISolutionRepository" class="org.pentaho.SomeImpl"/> 
<bean id="CustomSolutionRepository" class="org.pentaho.SomeImpl"/> 

ISolutionRepository repo = PentahoSystem.get(ISolutionRepository.class, "CustomSolutionRepository"); 

This is essentially the state of the system up until 5.0. Beans were simple Classes which were internally expected to call PentahoSystem.get() to retrieve their own dependencies. Any bean referencing another directly in Spring was discouraged. That lack of expressiveness in the Spring XML kept the internals of the system very opaque. Additionally every class was still very dependent of the PentahoSystem Service Locator.

New Enhancements

Anyone trying to customize the system prior to 5.0 brings features both to the PentahoSystem service locator as well as Spring.

PentahoSystem:

The had to drop jars into the WAR and modify our core Spring files. Maintainability was difficult.

New Enhancements

To start with, the ObjectFactory backing PentahoSystem is no longer based on a single Spring ApplicationContext. There can now be any number of registered Object Factories ObjectFactories registered with the system. Queries for a particular type will find the most appropriate type implementation from any of the registered ObjectFactories.

All Plugin's Plugins plugin.spring.xml files are registered with the system. It is now possible with the enhancements detailed below to override a core system object from within a plugin . Previously you would have to drop a new jar in the WAR and modify the core spring files.or contribute to a list of implementations. Plugin Spring files can also now reference beans from the core system eliminating the need to make calls to PentahoSystem.

In a lot of ways these enhancements are designed to deprecate the PentahoSystem service locator and the IPluginManager. Implementations should be registered from plugins and discovered the same as ones from the core code.

5.0 brings features both to the PentahoSystem service locator as well as Spring. Though as stated, usage of PentahoSystem should be avoided where possible.

PentahoSystem:

Call

Description

PentahoSystem.getAll()

Retrieve a list of implementations for a given type (i.e. all IContentGenerators). Ordered by priority

PentahoSystem.get()

Now returns the highest priority implementation registered in the system.

PentahoSystem.get(Type, Map<String, String>)

Query for an implementation with the given properties. Ordered by priority.

PentahoSystem.getObjectReference(Type)

Returns a descriptor for a registered implementation containing all attributes and a method getObject() to instantiate the referenced type.

...

Spring Element

Description

<pen:bean class="com.foo.Bar"/>

Retrieve the highest priority implementation for a the given type (i. e. all IContentGenerators). Published beans are given highest priority when searching for an implementation. If no beans have been published for the type, each registered ObjectFactory will be checked to see if they have an implementation (simple <bean>). The first one found will be returned.

<pen:list class="com.foo.Bar"/>

Retrieve a list of implementations for a given type (i.e. all IContentGenerators). Ordered by priority. unlike <pen:bean> only published implementations will be included in the list.

<pen:attributes>

Provide attribute metadata about a published bean, or use in conjuction with <pen:bean> or <pen:list> to query for specific implementations.
A special named attribute "priority" is used by the system to determine the order of implementations.

...

Code Block
xml
xml
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:pen="http://www.pentaho.com/schema/pentaho-system" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd 
http://www.pentaho.com/schema/pentaho-system http://www.pentaho.com/schema/pentaho-system.xsd"> 

  <!-- Register this ApplicationContext so it can publish beans --> 
  <bean class="org.pentaho.platform.engine.core.system.objfac.spring.ApplicationContextPentahoSystemRegisterer" scope="singleton"/> 

  <bean class="org.pentaho.MyDatasource"> 
    <pen:publish as-type="INTERFACES"/> 
    <pen:attributes> 
      <pen:attr key="type" value="special"/> 
    </pen:attributes> 
  </bean> 

</beans>

PentahoSystem now has one registered implementation of the org.pentaho.IDatasource interface. It can be retrieved by calling PentahoSystem directly:

...

Even though two implementations of IDatasource are registered. The , the second will be returned by PentahoSystem.get() and <pen:bean> as it's now the highest priority. Calls to PentahoSystem.getAll() or <pen:list> will return both, ordered by priority.

...