Custom File Adapter

This development guide walks through major steps to develop a custom file adapter as an InterPSS plugin to import custom data files into InterPSS. It is assumed that the reader has some Java development experience and knows how to use NetBeans Java development IDE.

Please note: The sample discussed in this document currently is only available in the latest InterPSS DEV release.

Introduction

Traditionally, a power system simulation program has a fixed format for creating data files as the input. InterPSS has a very flexible and extensible simulation engine with a published Java API. InterPSS does not a fixed format for the input. Instead, InterPSS provides a set of plugins, we call them input File Adapters, for inputting data in particular format into InterPSS. It is also quite easy to develop your own custom file adapter to load your data in your own format into InterPSS.

Create Custom File Adapter

Under InterPSS installation location, there is a plugin directory with a NetBeans project, which serves as a place-hold for custom plugins. We recommend you put your custom Java code in this location. Of course, if you are an experienced Java developer, you can put your Java code in any place as far it is available in the classpath.

Open NetBeans Java Project

Lauch NetBeans IED, select File/Open Project ... to open the existing custom.plugin project.

Create Custom File Adapter Class

Create a new Java package and a Java class. In our case, we create a FileAdapter_Sample class under org.interpss.sample.plugin.exchange package. In a complex situation, you may need to use some utility or helper classes.

Implement Adapter

To load a custom data file into InterPSS, you need to implement the IpssFileAdapter interface. You can extend the IpssFileAdapterBase class, which has some default implementation of some the interface methods, as follows.

public class FileAdapter_Sample extends IpssFileAdapterBase {

...

}

FileAdapter_Sample, as an example, provides implementation to load the data file plugin/samples/Ieee14Bus.dat into InterPSS for loadflow study. Please read the source code to exam the implementation. You may need also to read InterPSS Core Library Java API to understand the implementation details.

Import Data Into InterPSS

public void load(SimuContext simuCtx, String filepath, IPSSMsgHub msg) {

//...

}

To import a file in a custom data format into InterPSS, you need to implement the load() method. Basically, you are giving with the filepath for the file. You are support to load the simulation info stored in the file and create a SimuContext object. The IPSSMsgHub object is for sending notifications (status, warning, or error) to InterPSS.

Export Data from InterPSS

public boolean save(String filepath, SimuContext simuCtx, IPSSMsgHub msg) {

//...

}

To export InterPSS simulation object model information stored in the SimuContext object into a file in certain custom data format, you need to implement the save() method. Basically, you are giving with the filepath for the file. You are support to save the simulation info the file. The IPSSMsgHub object is for sending notifications (status, warning, or error) to InterPSS.

Built Jar File

After completing coding and testing, use Build/Build Main Project to build the distribution jar file. Make sure that the custom.plugin is the main project in NetBeans IDE and the build is succssful.

Plugin to InterPSS

Plugin the custom file adapter into InterPSS as a plugin is quite simple. All you need to do is to modify the /properties/springConfig/customAdapterContext.xml under your InterPSS installation directory.

First add a Spring framework "bean" description of your plugin with a unique bean id. In this case, "*.dat" is used as the custom data file extension. fileFilerString is used to filter files when open a file selection dialog.

<bean id="fileAdapterSample"

class="org.interpss.sample.plugin.exchange.FileAdapter_Sample"

scope="singleton"

p:name="Sample File Adapter"

p:fileFilterString="dat"

p:extension="dat"

p:description="A sample file adapter for importing data for Loadflow" />

Then add a reference to the bean in the customFileAdapterList, as follows:

<bean id="customFileAdapterList"

...

<list>

<ref bean="fileAdapterPSSEFormat"/>

...

<ref bean="fileAdapterSample"/>

</list>

Import Data

Restart InterPSS, add New Project, select Add Custom Data File to launch the Add New Project dialog box. The Sample File Adapter, which we named our sample file adapter in the configuration XML file (p:name="Sample File Adapter"), should be available to use.

Export Data

Currently to use your custom adapter to export InterPSS object model info, you can write few lines of InterPSS Custom Run Scripts using Java. The following are some sample scripts:

package <package>; // do not modify this line

import org.interpss.PluginSpringAppContext;

import org.interpss.editor.ui.IOutputTextDialog;

import org.interpss.editor.ui.UISpringAppContext;

import com.interpss.common.msg.IPSSMsgHub;

import com.interpss.simu.ISimuCaseRunner;

import com.interpss.simu.SimuContext;

import com.interpss.simu.io.IpssFileAdapter;

public class <classname> implements ISimuCaseRunner { // do not modify this line

public boolean runCase(SimuContext simuCtx, IPSSMsgHub msg) {

IpssFileAdapter adapter = PluginSpringAppContext.getCustomFileAdapterByName("Sample File Adapter");

try {

adapter.save("output/ipss_export.dat", simuCtx, msg);

} catch (Exception e) {

System.err.println(e.toString());

}

return true;

}

public void displaySummaryResult(SimuContext simuCtx) {

IOutputTextDialog dialog = UISpringAppContext.getOutputTextDialog("Custom Run Output");

dialog.display("output/ipss_export.dat");

}

}

The custom adapter, named "Sample File Adapter" in the configuration file, is used to export the object model info. The exporting info is saved to a file output/ipss_export.dat. Then the exported file is reloaded into InterPSS display dialog Window. By running the above scripts, using Run/Custom Run Scripts menuitem, you will see the export info displayed as follows. You can use the SaveAs button to save the info to any location.

The purpose of exporting InterPSS object model info most likely is to feed the info to another application. The Integrate InterPSS with Other Applications guide walks you through how to seamlessly integrate InterPSS with other applications.