How to read Rodin projects and elements programmatically: Difference between revisions

From Event-B
Jump to navigationJump to search
imported>Maria
New page: ==How to read a Rodin Project== You can access an existing Rodin project using <code>RodinCore.getRodinDB().getRodinProject("your_project_name")</code>. This returns a handle to an <code>I...
 
imported>Jrloria
No edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
check also [[Database]]
==How to read a Rodin Project==
==How to read a Rodin Project==
You can access an existing Rodin project using <code>RodinCore.getRodinDB().getRodinProject("your_project_name")</code>. This returns a handle to an <code>IRodinProject</code>. This project may or may not exist. Call <code>exists</code> on the resulting project to be sure.
You can access an existing Rodin project using <code>RodinCore.getRodinDB().getRodinProject("your_project_name")</code>. This returns a handle to an {{class|IRodinProject}}. This project may or may not exist. Call {{ident|exists}} on the resulting project to be sure.
 
An other option is calling <code>RodinCore.getRodinDB().getRodinProjects</code>, which returns an array with of all existing {{class|IRodinProject}}s.
 
==How to read a Machine or a Context==
Machines and Contexts are accessed through {{class|IMachineRoot}} and {{class|IContextRoot}} respectively. Those roots are stored in {{class|IRodinFile}}s.
 
The following method returns all existing {{class|IMachineRoot}}s of a project:
 
<code>
      public static IMachineRoot[] getMachineRootChildren(IRodinProject project) throws RodinDBException {
            ArrayList<IMachineRoot> result = new ArrayList<IMachineRoot>();
            for (IRodinElement element : project.getChildren()) {
                  if (element instanceof IRodinFile) {
                        IInternalElement root = ((IRodinFile) element).getRoot();
                        if (root instanceof IMachineRoot) {
                              result.add((IMachineRoot) root);
                        }
                  }
            }
            return result.toArray(new IMachineRoot[result.size()]);
      }
</code>
 
And this method returns all existing {{class|IContextRoot}}s of a project:
 
<code>
      public static IContextRoot[] getContextRootChildren(IRodinProject project) throws RodinDBException {
            ArrayList<IContextRoot> result = new ArrayList<IContextRoot>();
            for (IRodinElement element : project.getChildren()) {
                  if (element instanceof IRodinFile) {
                        IInternalElement root = ((IRodinFile) element).getRoot();
                        if (root instanceof IContextRoot) {
                              result.add((IContextRoot) root);
                        }
                  }
            }
            return result.toArray(new IContextRoot[result.size()]);
      }
</code>
 
==How to read Invariants, Events, Theorems etc.==
Once you have obtained an {{class|IMachineRoot}} or an {{class|IContextRoot}} it is very easy to access its child elements. There exist functions such as <code>getInvariants()</code> to obtain an array of all existing {{class|IInvariants}}. If you just want a specific element call a function of the form <code>getInvariant("your_invariant_name")</code>. Again this only returns a handle and does not guarantee that the element exists.
 
==How to read Proof Obligations==
For information on reading proof obligations, have a look at [[Accessing Proof Obligations]].


An other option is to call <code>RodinCore.getRodinDB().getRodinProjects</code>, which returns an array with of all existing <code>IRodinProject</code>s.
[[Category:Developer documentation]]
[[Category:Rodin Platform]]

Latest revision as of 14:12, 30 May 2009

check also Database

How to read a Rodin Project

You can access an existing Rodin project using RodinCore.getRodinDB().getRodinProject("your_project_name"). This returns a handle to an IRodinProject. This project may or may not exist. Call

exists

on the resulting project to be sure.

An other option is calling RodinCore.getRodinDB().getRodinProjects, which returns an array with of all existing IRodinProjects.

How to read a Machine or a Context

Machines and Contexts are accessed through IMachineRoot and IContextRoot respectively. Those roots are stored in IRodinFiles.

The following method returns all existing IMachineRoots of a project:

     public static IMachineRoot[] getMachineRootChildren(IRodinProject project) throws RodinDBException {
           ArrayList<IMachineRoot> result = new ArrayList<IMachineRoot>();
           for (IRodinElement element : project.getChildren()) {
                 if (element instanceof IRodinFile) {
                       IInternalElement root = ((IRodinFile) element).getRoot();
                       if (root instanceof IMachineRoot) {
                             result.add((IMachineRoot) root);
                       }
                 }
           }
           return result.toArray(new IMachineRoot[result.size()]);
     }

And this method returns all existing IContextRoots of a project:

     public static IContextRoot[] getContextRootChildren(IRodinProject project) throws RodinDBException {
           ArrayList<IContextRoot> result = new ArrayList<IContextRoot>();
           for (IRodinElement element : project.getChildren()) {
                 if (element instanceof IRodinFile) {
                       IInternalElement root = ((IRodinFile) element).getRoot();
                       if (root instanceof IContextRoot) {
                             result.add((IContextRoot) root);
                       }
                 }
           }
           return result.toArray(new IContextRoot[result.size()]);
     }

How to read Invariants, Events, Theorems etc.

Once you have obtained an IMachineRoot or an IContextRoot it is very easy to access its child elements. There exist functions such as getInvariants() to obtain an array of all existing IInvariants. If you just want a specific element call a function of the form getInvariant("your_invariant_name"). Again this only returns a handle and does not guarantee that the element exists.

How to read Proof Obligations

For information on reading proof obligations, have a look at Accessing Proof Obligations.