RIFE logo
This page last changed on Aug 07, 2006 by koreth.


We don't support the creation and dependency management of object references. Instead, we focus on the retrieval of the references and the injection of objects into the web engine elements.

The instantiation or management of your object references has to be done in participants. These can contain your own personal Java code where you create new objects for the reference keys that are requested, or you can setup existing IoC containers like Spring, Pico, ... and delegate the management to them in dedicated participants.

See Spring integration for information about how to use Spring with RIFE. For simple, lightweight injection of dependencies into classes other than element implementations, see the IoC support for non-element objects page in the Tips and Tricks section.

Retrieving the references

We simply rely on the repository as a generic way of providing object references. We already had support for any kind of participant which can provide any kind of object according to a key. An IoC container is simply one possible participant and any number of containers can work together and even be swapped later in the development.

Besides setting a simple string as a property value, the syntax we will use for this is:

<property name="datasource">
    <participant name="ParticipantDatasources">
        <participant name="ParticipantConfig">DATASOURCE</participant>
    </participant>
</property>

This is the full syntax of what could have been written like this:

<property name="datasource">
    <participant name="ParticipantDatasources">
        <config param="DATASOURCE"/>
    </participant>
</property>

Or even like this:

<property name="datasource">
    <datasource>DATASOURCE</datasource>
</property>

For convenience, we directly support tags for common RIFE features. These tags are:

  • config
  • datasource
  • template

[top]

Declaring the properties

Properties can be declared in several locations:

  • an element definition
  • a site declaration
  • a sub-site declaration
  • an element declaration in the site

Properties with the same name are applied in the same order as the list above, which means that properties inside an element declaration take precedence over anything else.

Properties that are defined in a sub-site or in a site, will be available to all containing elements. This is very handy for global dependencies like, for instance, datasources.

[top]

Injecting the references

Every time an element is created, the declared properties will be compared with the actual bean properties and the setters will be used to inject the references of those with the same name.

Currently we only support three situations here:

  • String bean properties:
    The reference's toString() method will be called before injecting it.
  • primitive bean properties or their class wrappers:
    We do our best to convert the values and if it's not possible, an exception is thrown.
  • other bean properties:
    If the bean property type is assignable from the type of injected reference, the setter will be called normally. Otherwise, an exception will be thrown, indicating that the types are not compatible.

[top]

Obtaining the references

If an element hasn't got the appropriate setters, the references are still obtainable through the existing getPropertyString(String key) and getProperty(String key) method. The same rules as above will apply.

[top]

An example

<datasources>
    <datasource name="postgresql">
        <driver>org.postgresql.Driver</driver>
        <url>jdbc:postgresql://localhost:5432/mydb</url>
        <user>user</user>
        <password>password</password>
        <poolsize>10</poolsize>
    </datasource>
</datasources>
<element implementation="MyBlah">
    <property name="datasource"><datasource>postgresql</datasource></property>
</element>
public class MyBlah extends Element
{
    public void processElement()
    {
        Datasource ds = (Datasource)getProperty("datasource");
        ...
    }
}

... or ...

public class MyBlah extends Element
{
    Datasource mDatasource;

    public void setDatasource(Datasource datasource) { mDatasource = datasource; }

    public void processElement()
    {
        ...
    }
}

[top]

Document generated by Confluence on Oct 19, 2010 14:56