SPS API: Java example

Assuming that you want to add and then modify a com.sun.n1.sps.model.category.Category the 'cat.add' and 'cat.mod' commands would be used.
Under the 'cat.add' command, the argument table has the username (u), plain text password (p), encoded password (ep) and session ID (s) as [O/R] arguments.
Thus, you can supply one the following combinations: [ u and p ] , [ u and ep ] , [ s ].
Assuming that you are logging in for the first time and want  to use the plain text password, the following snippet of code would be used:

      // Before executing any command, the reference to the CommandManager must by got by:

       CommandManagerBuilder builder = new CommandManagerBuilder();
       builder.setCLIInstallationDir(<the path of the CLI installation>);
       builder.setTestConnection(true);
    
      CommandManager commandManager = builder.build();
      
     // Now the HashMap can be constructed using the arguments as described above:

     Map arguments = new HashMap();
     arguments.put("u", <user_name>);
     arguments.put("p", <user_password>);
    
The 'cat.add' command also requires, as required [R] arguments, that the name ("name") and the description ("desc") of the Category be defined, thus:
 
    arguments.put("name", "foo");
    arguments.put("desc", "bar");

Now we are ready to execute the command using the HashMap and since the return type of this command is a Category object, we can cast the result of the execution of the command into the Category Object:

   com.sun.n1.sps.model.category.Category cat =
            (com.sun.n1.sps.model.category.Category) commandManager.execute("cat.add", arguments);

We now have the  Category object that can be  then introspected to  obtain  the  values of it's methods. Assuming, that we wish to modify the description of this Category, we would determine the Category's ID from it's getID() method and use pass that value to the 'cat.mod' command:

   // To reuse the HashMap, clear it's values
   arguments.clear();

   arguments.put("u", <user_name>);
   arguments.put("p", <user_password>);

   arguments.put("ID", cat.getID());
   arguments.put("desc", "boo");

   // 'cat.mod' returns us the modified Category object

    com.sun.n1.sps.model.category.Category catModified =
        (com.sun.n1.sps.model.category.Category) commandManager.execute("cat.mod", arguments);