Rhapsody Application Accessors

Customize behaviour

The behaviour can be customized in static mode

Theses accessors are provided by two plugins, located in your eclipse plugins folder a sub-folder.

The plugin corresponding to Rhapsody Application accessors is named com.sodius.mdw.metamodel.rhapsody.com_Iyyyymmdd
(where yyyymmdd is a timestamp like 20150913).

The plugin corresponding to Rhapsody On-Demand accessors is named com.sodius.mdw.metamodel.rhapsody.proxy_Iyyyymmdd

Open one of these folders and locate this configuration files: mdw.ini.

A second configuration mdw_nographics.ini is exclusively dedicated to the accessor Rhapsody Application (no graphics).

Edit one of this file according to your needs.

The behaviour can be customized in runtime mode

An example in Java to write a model into Rhapsody.

We use here the class com.sodius.mdw.core.model.Model as parameter:

    private static void writeModel(Model source) throws CoreException {

        Application app = (Application) source.getInstances("Application").first();
        
        // Always get active project only !
        Project proj = app.getActiveProject();
           
        com.sodius.mdw.metamodel.rhapsody.Package newPkg = source.create("Package");
           
        newPkg.setName("Hello");
           
        proj.getPackages().add(newPkg);
        
        //Setuping the update writer
        List modifiedUnits = new ArrayList();
        modifiedUnits.add(newPkg);
        source.getMetamodel().getModelWriterDescriptor("Rhapsody Application")
                  .setProperty("unitsToReplace", modifiedUnits);
        
        // Update model in Rhapsody
        source.write("Rhapsody Application", null);        
    }
	

The same process implemented in a TGL or MQL:

  public ruleset UpdateModel(in source : rhapsody) {

	  public rule myRule() {
		var app : rhapsody.Application = source.getInstances("Application").first();
		
		// Always get active project only !
		var proj : rhapsody.Project = app.activeProject;
		   
		var newPkg : rhapsody.Package = source.create("Package");
		   
			newPkg.name = "Hello";
		   
		proj.packages.add(newPkg);
		
		//Setuping the update writer
		var modifiedUnits : java.util.List = java.util.ArrayList.new();
		modifiedUnits.add(newPkg);
		context.getWorkbench().getMetamodelManager()
			  .getMetamodel("rhapsody").getModelWriterDescriptor("Rhapsody Application")
				  .setProperty("unitsToReplace", modifiedUnits);
		
		// Update model in Rhapsody
		model.write("Rhapsody Application", null);
	}
  }
	

Another example in Java to read a model from Rhapsody.

We use here the class com.sodius.mdw.core.model.Model as parameter:

    private static void readModel(Model model) throws CoreException {
        // Change reading behaviour
        model.getMetamodel().getModelReaderDescriptor("Rhapsody Application").setProperty("exportAllTags", true);
        model.getMetamodel().getModelReaderDescriptor("Rhapsody Application").setProperty("exportDiagrams", false);

        model.read("Rhapsody Application", null);
    }
    

Redirect the log trace

1) To a log file in a Java command-line or Eclipse.ini:

        -Dcom.sodius.rhapsody.log=D:/trace.log
	

1) To a log file in a TGL or MQL script:

    context.getWorkbench().getMetamodelManager()
        .getMetamodel("rhapsody")
            .getModelReaderDescriptor("Rhapsody Application")
                .setProperty("com.sodius.rhapsody.log", "D:/trace.log");
	

2) To a log file in a Java source:

    model.getMetamodel()
        .getModelReaderDescriptor("Rhapsody Application")
            .setProperty("com.sodius.rhapsody.log", "D:/trace.log");
	

3) To an object implementing the interface com.sodius.mdw.core.util.log.Logger:

    workbench.getConfiguration().setLogger(new MyLogger((...));
	

Or also:

    model.getMetamodel()
    	.getModelReaderDescriptor("Rhapsody Application")
	  		.setProperty("customLogger", (new MyLogger((...));
	

4) A complete example with On-Demand accessor and using preloader in Java:

    MDWorkbench workbench = MDWorkbenchFactory.create();
    FileLogger logger = new FileLogger(new File("D:/trace.log"));
    logger.setLevel(Level.DEBUG);
    try {
        workbench.getConfiguration().setLogger(logger);
        Model model = workbench.getMetamodelManager().getMetamodel("rhapsody").readModel("Rhapsody On-Demand", null);
        ProxyPreloader preloader = new ProxyPreloader(model, logger);
        preloader.preload();
    } catch (CoreException e) {
        logger.error(e.getMessage(), e);
    }