Previous Topic

Next Topic

Book Contents

Book Index

Application Abstraction Layer

The application abstraction layer enables you to restrict the access of client applications to commands, conditions and rules that are not created by them.

For more information, refer to System Architecture.

Introducing the Application Abstraction Layer

The application abstraction layer enables you to restrict the access of client applications to commands, conditions and rules that are not created by them. It is introduced with the use of a service factory that depending on the requester's access permissions provides different instances of the Home Automation Admin service. There are two ways to use an abstraction-aware Home Automation Admin service object: via the Java (OSGi) API and via the JSON-RPC API.

Obtaining Application-Aware Home Automation Admin via Java API

If you are using the Java API, the application abstraction layer is introduced by the Home Automation Admin service factory. It provides a different instance of the Home Automation Admin service to each application:

To obtain a Home Automation Admin service object:

  1. Retrieve the Home Automation Admin service reference.
  2. Get a HomeAutomationAdmin service object by calling the getService method with the Home Automation Admin service reference as argument.

      ServiceReference haAdminRef = bc.getServiceReference(HomeAutomationAdmin.class.getName());
      HomeAutomationAdmin haAdmin = bc.getService(haAdminRef);

The method returns a Home Automation Admin service object which isolates the commands, conditions and rules created by one application from the ones that were created by other applications.

Using Application-Aware Functions (JSON-RPC API)

If you are using the JSON-RPC API, you can assign application IDs to commands/conditions/rules, by using application-aware functions.

All JSON-RPC functions for managing commands, conditions and rules have application-aware counterparts which behave in the same way as the regular ones except that they isolate the commands, conditions and rules created by one application from the ones that are created by other applications.

For example a rule created with HAM/createRule(ruledata, "one application") will not be returned if you call HAM/getRules(null, "another application").

Importing/Exporting Commands, Conditions and Rules per Application

You can export all commands, conditions and rules that are assigned to a certain application and then import them to another using the exportApplication and importApplication methods of the Home Automation Admin. This functionality is based on the ConfigTree module. The methods accept a FileOutputStream, respectively InputStream, a String for the ID of the application and a String representing the file format (BIN or XML) - both available as String ConfigTree constants.

The following snippet exports an application with ID myapplication to the application.xml file.

  File file = new File ("D:\\application.xml");
  FileOutputStream out=null;
  try {
    out = new FileOutputStream(file);
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  }
  hamAdminFactory.exportApplication(out , "myapplication", ConfigTreeAdmin.XML);

The method returns a ConfigTree status object that contains information about any errors which may have occurred during the import/export.