Accessing Rational Rose from Java

Java/J2EE COM Interoperability Products Page

This example demonstrates how to access Rational Rose from Java. J-Integra® for COM is a Java interoperability component that bridges Java and Rational Rose. It provides bi-directional access of Java objects and COM components.

/* 
 * This example shows how you can access Rational Rose running under MS Windows from a 
 * pure Java client running on any operating system that supports a standard JVM, by 
 * using the J-Integra® pure Java-COM bridge (see http://j-integra.intrinsyc.com/). 
 * 
 * The program takes as a parameter a Rose model and from this model it creates an 
 * HTML file listing all the classes as an index with reference to their descriptions,  
 * and operations. 
 * 
 * To run this example, create a 'rose' subdirectory, and run J-Integra®'s 'com2java' 
 * tool, specifying the Rose type library (RationalRose.tlb from the Rose installation 
 * directory) as the input type library, 'rose' as the package name, and the rose subdirectory 
 * you created as the output directory. 
 * 
 * This Java client will run on any machine which has a standard JVM, such as a UNIX machine. 
 * 
 */ 
 
import rose.*; 
 
import java.io.*; 
 
public class RoseExample { 
 
  public static void main(String args[]) throws Exception { 
 
    // If running this Java client under MS windows then make sure the J-Integra® 'bin' directory 
    // is in your PATH, otherwise run DCOMCNFG on the machine running Rose (Start|Run|DCOMCNFG), 
    // grant a specific user default launch and access permissions, and uncomment the following 
    // line, specifying the appropriate domain/user/password 
    // com.linar.jintegra.AuthInfo.setDefault("NT DOMAIN", "NT USER", "NT PASSWORD"); 
     
    PrintWriter indexFile = null; 
 
    if (args.length != 1) { 
      System.err.println("Usage: java RoseExample roseModelFileName"); 
      return; 
    } 
 
    try { 
      indexFile = new PrintWriter(new FileWriter("index.html")); 
         
      // If talking to a Windows 95/98 machine, Rose must already be running.  Specify remote host 
      // name as a parameter if you want to access Rose remotely. 
      RoseModel roseModel = new RoseModel(); 
      RoseApplication roseApp = new RoseApplication(roseModel.getApplication()); 
 
      roseApp.openModel(args[0]); 
 
      IRoseModel myModel = roseApp.getCurrentModel(); 
      IRoseClassCollection allClasses = myModel.getAllClasses(); 
 
      indexFile.print("<HTML><HEAD><TITLE>All Rose classes" + 
                      "</TITLE></HEAD>\n<BODY>\n<H1>Index of classes for " 
                      + myModel.getName() + "</H1>\n<UL>\n"); 
       
      // print index 
      for (short classIndex = 1; classIndex <= allClasses.getCount(); classIndex++) { 
        IRoseClass currentClass = allClasses.getAt(classIndex); 
        String className = currentClass.getName(); 
 
        indexFile.print("<LI><A HREF=#" + className + ">" + 
                        className + " 
        </A > " + "\n 
        "); 
      } 
      indexFile.print("</UL>\n"); 
       
      // print class descriptions and operations 
      for (short classIndex = 1; classIndex <= allClasses.getCount(); classIndex++) { 
        IRoseClass currentClass = allClasses.getAt(classIndex); 
        String className = currentClass.getName(); 
 
        indexFile.print("<A NAME =" + className + ">\n"); 
        indexFile.print("<H1>" + className + "</H1>\n"); 
        indexFile.print("<H2>Description</H2>\n"); 
        indexFile.print("<P>" + currentClass.getDocumentation() + "</P>\n"); 
        indexFile.print("<H2>Operations</H2>\n<UL>\n"); 
 
        IRoseOperationCollection operations = currentClass.getOperations(); 
        for (short opIndex = 1; opIndex <= operations.getCount(); opIndex++) { 
          String opName = operations.getAt(opIndex).getName(); 
          indexFile.print("<LI>" + opName + "\n"); 
        } 
        indexFile.print("</UL>\n"); 
      } 
 
      indexFile.print("</BODY></HTML>"); 
      roseApp.exit(); 
      indexFile.close(); 
    } finally { 
      // Release any COM object references that have not already been released through 
      // standard garbage collection. 
      com.linar.jintegra.Cleaner.releaseAll(); 
    } 
  } 
}