How to read Rodin projects and elements programmatically: Difference between revisions
From Event-B
Jump to navigationJump to search
imported>Maria |
imported>Maria |
||
Line 23: | Line 23: | ||
} | } | ||
</code> | </code> | ||
And this method returns all existing <code>IContextRoot</code>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> | |||
[[Category:Developer documentation]] | [[Category:Developer documentation]] | ||
[[Category:Rodin Platform]] | [[Category:Rodin Platform]] |
Revision as of 14:09, 28 October 2008
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 IRodinProject
s.
How to read a Machine or a Context
Machines and Contexts are accessed through IMachineRoot
and IContextRoot
respectively. Those roots are stored in IRodinFile
s.
The following method returns all existing IMachineRoot
s 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 IContextRoot
s 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()]);
}