Java Code Sample

import java.net.URL;

import com.ibm.rpm.framework.RPMObject;
import com.ibm.rpm.framework.ReloadType;
import com.ibm.rpm.interfaces.Application;
import com.ibm.rpm.interfaces.ApplicationServiceLocator;
import com.ibm.rpm.interfaces.Authenticate;
import com.ibm.rpm.interfaces.AuthenticateServiceLocator;
import com.ibm.rpm.resource.containers.Pool;
import com.ibm.rpm.resource.containers.Resource;
import com.ibm.rpm.resource.scope.PoolScope;
import com.ibm.rpm.resource.scope.ResourceScope;

public class JavaSample
{

    //The Application interface has the save, query and delete methods
    public static Application applicationInterface = null;

    //The ApplicationServiceLocator creates the application
    //service from the specified URL
    public static ApplicationServiceLocator applicationLocator = 
        new ApplicationServiceLocator();

    //The URL of the Web service
    public static String url = "http://localhost:8080/rpm/services/";

    //The Authenticate interface has the login, logout and change password
    // methods
    public static Authenticate authenticate = null;

    //The AuthenticateServiceLocator creates the service,
    //authenticates service from the specified URL
    public static AuthenticateServiceLocator authlocator = 
        new AuthenticateServiceLocator();

    //The SessionID is used through the whole program to keep the connection
    // alive
    public static String sessionid;

    public static void main(String[] args) throws Exception
    {
        //Creation of the object which will be used to
        //get a session with the RPM Web Service
        //Use the AuthenticateServiceLocator to create the Authenticate with
        // the
        //URL to connect.
        //Authenticate is an Interface, so you cannot instanciate it.
        authenticate = authlocator
            .getAuthenticate(new URL(url + "Authenticate"));

        //A User/Password/dsn is required to be authenticated by the server
        String username = "rpmadministrator";
        String password = "yourrpmpassword";
        String dsn = "jdbc/RPMDATASOURCE";

        //Use the authenticate object to login with the user/password/dsn
        //If the login is successful, it returns a sessionId that will be used
        //All along the creation/modification/query of the RPM object.
        sessionid = authenticate.login(username, password, dsn);

        //Creation of the object which will be used to save\modify\query RPM
        // object

        //The application is an Interface, you have to use the
        // //applicationServiceLocator to obtain an application instance. You
        // also need //to specify where to connect by specifying the URL at
        // creation.
        applicationInterface = applicationLocator.getApplication(new URL(url
                + "Application"));

        //Create a container pool and set a name
        Pool demoPool = new Pool();
        demoPool.setName("SaveThisPool");

        //Save the pool in the RPM Repository
        applicationInterface.save(sessionid, demoPool, null,
            ReloadType.ReloadResult);

        //Query the Pool you have saved in the RPM Repository with an XPath
        // that has //the name of the pool
        //The Query returns an array of Pool that has the name you have queried
        RPMObject pools[] = applicationInterface.loadFromXpath(sessionid,
            "/Pool[name='SaveThisPool']", null).getRpmObjectList();

        Pool queryPool = (Pool) pools[0];

        //Create a resource to be saved under the pool
        Resource secondLevelResource = new Resource();

        //Set a resource that is contained within the demoPool
        queryPool.setResources(new Resource[]
        {
            secondLevelResource
        });

        //Create a scope from which the hierarchy of container will be kept
        PoolScope demoScope = new PoolScope();

        //Set a Resource under the pool which represents a multi-level
        // structure
        //If it is not set, the only container save will be the demoPool
        demoScope.setResources(new ResourceScope());

        //The application interface will connect to the server with the
        // sessionId
        //Send the container with the scope so it is correctly saved in the RPM
        // //Database
        applicationInterface.save(sessionid, queryPool, demoScope,
            ReloadType.ReloadResult);

        //Delete the Pool from the RPM Repository
        applicationInterface.delete(sessionid, queryPool);

        //After executing all commands, you have to logout with the sessionId
        authenticate.logout(sessionid);
    }
}