Difference between revisions of "Extending the Rodin Database"

From Event-B
Jump to: navigation, search
m (Get the value corresponding to the attribute of an element)
m (Get the value corresponding to the attribute of an element)
Line 76: Line 76:
 
* <code>boolean IInternalElement.getAttributeValue(IAttributeType.Boolean)</code>
 
* <code>boolean IInternalElement.getAttributeValue(IAttributeType.Boolean)</code>
  
* <code>IRodinElement IInternalElement. getAttributeValue(IAttributeType.Handle)</code>
+
* <code>IRodinElement IInternalElement.getAttributeValue(IAttributeType.Handle)</code>
  
* <code>int IInternalElement. getAttributeValue(IAttributeType.Integer)</code>
+
* <code>int IInternalElement.getAttributeValue(IAttributeType.Integer)</code>
  
* <code>long IInternalElement. getAttributeValue(IAttributeType.Long)</code>
+
* <code>long IInternalElement.getAttributeValue(IAttributeType.Long)</code>
  
* <code>String IInternalElement. getAttributeValue(IAttributeType.String)</code>
+
* <code>String IInternalElement.getAttributeValue(IAttributeType.String)</code>
  
 
As an example, we can use the following code to set our previously declared attribute of an internal element (e.g. <code>elem</code>)
 
As an example, we can use the following code to set our previously declared attribute of an internal element (e.g. <code>elem</code>)

Revision as of 18:48, 24 March 2010

There are different ways to extend the Rodin Database:

  • adding a new element.
  • adding a new attribute.

Adding a New Element

Adding a New Attribute

Declare a New Attribute

The extension point org.rodinp.core.attributeTypes to declare a new attribute.

In the example below, we assume that the extensions are developed within a plug-in project with name org.eventb.developer.examples

The following extension declares a new string attribute.

<extension
        point="org.rodinp.core.attributeTypes">
     <attributeType
           id="stringAttr"
           kind="string"
           name="%eventBStringAttribute">
     </attributeType>
 </extension>
  • The attribute has an ID (which should be always unique) which also contain the project name, i.e. org.eventb.developer.examples.stringAttr. This unique ID will be used for access the value corresponding to this attribute of an element later.
  • The name of the attribute is a string that could be externalised to be used for displaying to the users in the future.
  • There are five different attribute kinds: boolean, handle, integer, long, string.

Access (Programmatically) the Newly Created Attribute

After declaring the attribute with the ID and the kind of the attribute, we need to access the value corresponding to the attribute of any internal element.

Getting the corresponding Java attribute kind

Firstly, we need to get the corresponding Java attribute kind.

  • boolean: org.rodinp.core.IAttributeType.Boolean
  • handle: org.rodinp.core.IAttributeType.Handle
  • integer: org.rodinp.core.IAttributeType.Integer
  • long: org.rodinp.core.IAttributeType.Long
  • string: org.rodinp.core.IAttributeType.String

The following methods get the corresponding Java attribute kind, given an unique ID and the kind (as declared via the extension point).

  • org.rodinp.core.IAttributeType.Boolean RodinCore.getBoolAttrType(String ID)
  • org.rodinp.core.IAttributeType.Handle RodinCore.getHandleAttrType(String ID)
  • org.rodinp.core.IAttributeType.Integer RodinCore.getIntegerAttrType(String ID)
  • org.rodinp.core.IAttributeType.Long RodinCore.getLongAttrType(String ID)
  • org.rodinp.core.IAttributeType.String RodinCore.getStringAttrType(String ID)

Note: There is a general method for getting the Java attribute kind given an unique ID (without knowing in advance the kind as declared via the extension point).

  • org.rodinp.core.IAttributeType RodinCore.getAttrubuteType(String ID)

As an example with the previously declare attribute, we can use the following code to get the attribute type:

 org.rodinp.core.IAttributeType.String attrType = RodinCore.getStringAttrType("org.eventb.developer.examples");

Check for existence of the attribute for an element

Given an internal element (i.e. IInternalElement), and given an attribute type (i.e. IAttributeType), method boolean IInternalElement.hasAttribute(IAttributeType) checks for the existence of this attribute for the input element.

Get the value corresponding to the attribute of an element

Depending on the Java attribute kind, we have different methods for getting the value corresponding to the attribute of an internal element (i.e. IInternalElement).

  • boolean IInternalElement.getAttributeValue(IAttributeType.Boolean)
  • IRodinElement IInternalElement.getAttributeValue(IAttributeType.Handle)
  • int IInternalElement.getAttributeValue(IAttributeType.Integer)
  • long IInternalElement.getAttributeValue(IAttributeType.Long)
  • String IInternalElement.getAttributeValue(IAttributeType.String)

As an example, we can use the following code to set our previously declared attribute of an internal element (e.g. elem)

String attrValue = elem.getAttributeValue(attrType);

Set the value corresponding to the attribute of an element

Depending on the Java attribute kind, we have different methods for setting the value corresponding to the attribute of an internal element (i.e. IInternalElement).

  • void setAttributeValue(IAttributeType.Boolean, boolean, IProgressMonitor)
  • void setAttributeValue(IAttributeType.Handle, IRodinElement, IProgressMonitor)
  • void setAttributeValue(IAttributeType.Integer, int, IProgressMonitor)
  • void setAttributeValue(IAttributeType.Long, long, IProgressMonitor)
  • void setAttributeValue(IAttributeType.String, String, IProgressMonitor)

As an example, we can use the following code to set our previously declared attribute of an internal element (e.g. elem)

elem.setAttributeValue(attrType, "My new value", new NullProgressMonitor());