To access an OSGi service from rules, you must create a
business object model (BOM) that maps to the Java™ code of the service. You first create a
project to contain the BOM, and then you reference the project in
the rule agent.
Before you begin
Create an OSGi service in a plug-in project and import the
project into the Eclipse workspace that contains your rule agent.
Restriction: OSGi services to be packaged in a solution must
be implemented in a plug-in project that is created in the Plug-in
Development Environment (PDE). OSGi projects from the Eclipse Web
Tools Platform (WTP) are not supported.
About this task
The OSGi service is represented by a verbalized BOM class
that corresponds to the Java interface
of the OSGi service. This BOM class must contain a custom property
named OSGi.service. The value of this property is
the fully qualified name of the Java interface.
The BOM class can also contain a property to specify the version of
the package as defined in the Export-Package header
property in the manifest file of the solution.
The BOM class
for the OSGi service must be created in a separate rule project because
it cannot be hosted by the solution BOM project. This rule project
must have a reference to the plug-in project that contains the Java interface. This plug-in project
serves as the Execution Object Model (XOM).
To be accessible
in rules, a method of the service must have a corresponding method
in the BOM class. This corresponding method must be static, and have
the same name and the same number of parameters. Each parameter must
have a type that corresponds to the Java type
of the parameter in the Java interface.
Procedure
- Create a rule project:
- Click .
- Follow the wizard to create a standard rule project.
- On the Rule Project References page,
do not select references to other projects.
- On the Rule Project XOM Settings page,
select the Java project that
contains your service, and click Finish. This setting is used at export time to check the validity of
the OSGi service API.
- In the Solution Explorer, right-click
the new rule project and click Properties.
- Click Rule Engine, select Decision
Engine, and click OK.
Restriction: The Classic Rule Engine is not supported in Decision Server
Insights.
- Create a BOM entry:
- Right-click the new rule project, and click ,
and then click Next.
- Enter a name for the BOM entry, select Create
an empty BOM entry, and click Finish. A BOM entry with a type that represents the OSGi service is
generated and displayed in the Solution Explorer.
- Edit the new BOM entry:
- In the Solution Explorer, double-click
the empty BOM type that you just created to open it the BOM editor.
- Click New Class to create a new
class and enter a name. This class is used to hold properties
to map an OSGi service with method definitions.
- In the Members section of the Class tab,
add a member for each method that is defined in the interface of the
OSGi service. The members must have the same name, type, and arguments
as defined in the OSGi service.
- In the Member tab, create a default
verbalization for each member. You might edit the default
verbalizations to make them easier to use and read in rules.
- Select the Static check-box for
each member.
- When you select the Static check-box,
an error is displayed in the verbalization. To remove the error, delete
the {this} placeholder in the member verbalization
in the BOM editor.
- In the Class tab, expand the
Custom Properties section and click Add. You might have to scroll down in the BOM editor to view the
Customer properties section.
- Enter OSGi.service as the name
of the property, and the fully qualified name of the Java type for your OSGi service as the value.
You can also add an OSGi.service.version property
to refer to a specific version of the service. If you don't specify
a version, the most recent version of the service available on the
server is used.
Important: The OSGi.service property
is case-sensitive and must be written as shown.
The OSGi.service and OSGi.service.version properties
appear in the Import-Package header in the manifest
file of the solution when you export an agent or the solution.
You
might have to scroll down in the BOM editor to view the Custom
Properties section.
In the following
example, the fully qualified name of the type is service.ageservice.AgeHelper,
and its version is 1.0.0.
- Save the changes.
- In the rule agent project, add a reference to the rule
project that contains the service BOM:
- Right-click the agent project, and click Properties.
- Click Project References, and
select the rule project where you created the service BOM.
- Click OK.
Results
A separate business object model is created for the OSGi service
along with the vocabulary to use in the rules.
What to do next
In your rule agent, you can write rules that use the OSGi
service.