This document is a programmer's guide to using the RM Metatype Manager.

Overview

RM Metatype Manager provides a generic API to managing metatypes in RM. Using it can obtain available metatypes and easily add new ones that will be stored in a custom DB maintained by the Metatype Manager.

The following metatypes in RM are manageable through the Metatype Manager API:

  • Metatypes of control unit types

  • Metatypes of backend OSGi Metadata Manager

  • Metatypes available in the RM Metatype Manager custom DB

Accessing the Metatype Manager API

The Metatype Manager API is represented by the com.prosyst.mprm.admin.mtppackage holding the the Metatype Manager interface. It provides methods for managing metatypes in RM. The Metatype Manager interface can be accessed in two ways:

  • By backend bundles – The Metatype Manager is available as a service on the backend, registered under the com.prosyst.mprm.admin.mtp.MetaTypeManager interface. You can call the service using the conventional techniques defined by the OSGi Framework Specification.

  • By external applications/systems – Non-RM applications/systems can access the Metatype Manager in the standard way for accessing RM services through the Remote Access Client (RAC) module. Working with it is described in the Remote Access to RM guide from the System package documentation.

Using the Metatype Manager

Adding a new Metatype

You can add new metatypes in RM that will be kept in the Matatype Manager's DB using the addMetadataRecord method. It requires the metatype's PID, version, an InputStreamof its XML definition or an instance of its org.osgi.service.metatype.MetaTypeProvider implementation .

The XML listed below defines a simple metatype that will be added to the Metatype Manager's DB in the source example after it.

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE
metatype-provider SYSTEM "conf.dtd">
   <metatype-p  rovider>
   <objectclass load="true">  
    <name>My Metatype</name>  
    <id>my.metatype.pid</id>  
    <description>An example metatype to test RM Metatype Manager</description>
    <attribute modifier="req">    
      <name>An integer property</name>    
      <id>intProp</id>    
      <description>A test integer property</description>    
      type>&int;</type>    
      <value>      
        <scalar>10</scalar
      </value>  
    <name>A boolean property</name>
    <id>booleanProp</id>  
    <description>A test boolean property</description>    
    <type>&boolean;</type>    
    <value>      
      <scalar>false</scalar>    
    </value>
  </attribute>
  <attribute modifier="req">
  <name>A String property</name>    
  <id>stringProp</id>
  <description>A test string property</description>    
  <type>&string;</type>
  <value>
         <scalar>Test String property</scalar>    
      </value>  
    </attribute>
  </objectclass>
  </metatype-provider>

Now adding a new metatype to the Metatype Manager's custom DB:

import java.io.File;
import java.io.FileInputStream;
 
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
 
import com.prosyst.mprm.admin.mtp.MetaTypeManager;
 
public class AddMetatypeExample implements BundleActivator {
 
  private ServiceReference ref;
  private MetaTypeManager manager;
  private File metatypeXML;
  private FileInputStream metatypeIS;
 
  private static final String METATYPE_PID = "my.metatype.pid";
  private static final String METATYPE_VERSION = "1.0.0";
        
  public void start(BundleContext bc) throws Exception {
 
    ref = bc.getServiceReference(MetaTypeManager.class.getName());
    manager = (MetaTypeManager) bc.getService(ref);
 
    metatypeXML = new File("myMetatype.xml");
    metatypeIS = new FileInputStream(metatypeXML);
        
    //Adding the metatype to the Matatype Manager's DB
    manager.addMetadataRecord(metatypePID, METATYPE_PID, METATYPE_VERSION);
        
  }
 
  public void stop(BundleContext bc) throws Exception {
 
             . . .
  }
 
}

Obtaining an Existing Metatype

To obtain a metatype available in RM, use the Metatype Manager's getMetaTypeProvider method which returns a MetaTypeProvider instance of the corresponding metatype. By default, when an application invokes this method, Metatype Manager starts to search for the target metatype in three sources in the following order of precedence: first in the available control unit types, then in the backend OSGi Metadata Manager and finally in its custom DB.

The getMetaTypeProvider method requires the following arguments:

  • String pid – The metatype's PID

  • String version – The metatype's version

  • String extensionKey – Optional. A registration property of a MetaTypeProvider service providing an extension adding some extra functionality to the base metatype. Currently, such extensions are supported only for adding node properties of a device type.

  • int[] sources – Optional. Here you can pass an array of constants which correspond to the three sources where the Metatype Manager searches for the metatype with the specified PID, version and extension key (if any). This can be useful, as an instance, if you wish to search only in certain source(s) or to change the default order in which Metaype Manager checks through each source. The constants you can pass in this argument are the following:

    • SOURCE_CU_TYPE – For control unit types

    • SOURCE_FRAMEWORK_MD_MANAGER – For metatypes supplied in the OSGi Metadata Manager

    • SOURCE_OWN_DB – For the Metatype Manager's custom DB


The source example that follows obtains the metatype added in the Metatype Manager's DB in the previous section and prints its ObjectClassDefinition in the system output.

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.metatype.MetaTypeProvider;
import org.osgi.service.metatype.ObjectClassDefinition;
import com.prosyst.mprm.admin.mtp.MetaTypeManager;
 
public class GetMetatype implements BundleActivator {
 
  private ServiceReference ref;
  private MetaTypeManager manager;
  private ObjectClassDefinition definition;
  private MetaTypeProvider provider;
  private static final String metatypePID = "my.metatype.pid";
  private static final String metatypeVersion = "1.0.0";
    
  public void start(BundleContext bc) throws Exception {
                    . . .
    Obtaining the MataTypeProvider service
                    . . .
    provider = manager.getMetaTypeProvider(metatypePID, metatypeVersion);
        
    if (provider != null){
            
      definition = provider.getObjectClassDefinition("exmpl.mtp.prov", null);
      System.out.println(definition);
    }
 
  }
 
  public void stop(BundleContext bc) throws Exception {
            . . .
  }
 
}