Accessing NED and Message Types

We will modify our earlier Hello world example to print out the number of NED types in all open projects. Note that this is not the same as the number of NED files. Some NED files may contain more than one type while others contain none at all (e.g. package.ned). We can access the internal NED model via the NEDResources class.

Open the SampleAction.java file and modify its content:

public void run(IAction action) {
  MessageDialog.openInformation(
    window.getShell(), "NED Info",
    "Number of NED types: "+NEDResources.getInstance().
        getNedTypesFromAllProjects().size());
}

The parsed model of all NED files can be accessed via the NEDResources.getInstance() singleton object. The NEDResources class is the main entry point to access and manipulate the content of NED files. If you know the fully qualified name of a type, you can obtain its type descriptor (INedTypeInfo) using the getToplevelNedType() method. There are numerous other ways to access and query the NED types. Check the documentation of the NEDResources and INedTypeInfo class.

Similarly, you can access information about message files using the MsgResources.getInstance() method. Check the documentation of the IMsgTypeResolver and IMsgTypeInfo interfaces for further information.

Note

You have to add the org.omnetpp.ned.core and org.omnetpp.ned.model plug-ins to the project dependencies to access their classes.