Reuse Extension Language Reference
The Reuse Extension Language provides means to bind composition systems defined in the Composition System Specification Language to a concrete language that is defined by an Ecore metamodel. They are specified in files with the extension rex.
Examples
Several examples can be found in the Applications section. Here are some direct links to rex files:
REX File Structure
Header
The header of a reuse extension has the following schema:
componentmodel ID
implements compositionSystemID
epackages <epackage> +
rootclass rootelementMetaclass
{ fragmentRoleBindings + }
- ID Gives an unique ID to the Reuse Extension.
- compositionSystemID The ID of the Composition System Specification that is implemented by this component model (defined in the Composition System Specification Language). If no specific composition system specification should be implemented, org.reuseware.lib.systems.default can be used.
- epackage The Ecore metamodel package(s) for which the extension is defined (identified by the packages' NsURIs).
- rootelementMetaclass The metaclass of the root element of models for which this component model is valid (e.g., Model for UML or EPackage for Ecore).
Fragment Role Bindings
A reuse extension consists of a set of fragment role bindings which again consist of a set of port type bindings which define the addressable point derivation rules.
fragment role roleName {
portTypeBinding +
}
port portTypeName {
addressablePointDerivationRule +
}
- roleName Name of a fragment role defined in the composition system identified above.
- portTypeName Name of a port type defined in the fragment role.
Addressable Point Derivation Rules
Addressable point derivation rules define how addressable points (i.e, Hooks, Slots, Prototypes and Anchors) that lay behind each port are found in a fragment. They are defined using the following schema:
metaclass.feature? is addressablePointType if $OCLExpression$? {
point expr = $OCLExpression$ ?
port expr = $OCLExpression$ ?
value expr = $OCLExpression$ ?
begin expr = $OCLExpression$ ?
end expr = $OCLExpression$ ?
}
- metaclass refers to an EClass defined in an EPackage that was declared in the header of the reuse extension. The rule applies to instances of that metaclass.
- reference refers to an EStructuralFeature defined on the corresponding EClass. If a feature is defined, the feature itself (in case of Hooks and Slots) or the elements referred by the reference (in case of Prototypes and Anchors) are considered instead of the element holding the reference.
- addressablePointType defines which type of addressable point the metaclass extension introduces. Valid values are:
- hook
- prototype
- slot
- anchor
- value hook
- value prototype
- each OCLExpression is a fully compliant OCL expression that is defined in the context of the given metaclass. There are different usages for OCL expressions. Check the web for information and tutorials about OCL. A good starting point can be the OCL portal.
- is OCLExpression defines further restrictions on the instances of the metaclass for which this metaclass extension applies. Has to return a boolean value.
- port OCLExpression determines to which port the addressable points that are defined through this metaclass extension belong. A port is identified by its name which is computed by this expressions. It is only required for ports with a dynamic port type since ports of static ports types are named after their type. It has to return a string value.
- point OCLExpression gives a unique name to an addressable point within a port. If only one addressable point of one type belongs to a port, point naming is not required. Has to return a string value.
- value OCLExpression is only applicable for value prototypes and defines how a value is extracted from the fragment. It has to return a primitive value (i.e., String, Integer, Boolean).
- idx OCLExpressions are only applicable for value hooks and define a position in a String EAttribute that already contains a value. The part of the value between begin and end index will then be replaced when the hook is bound. These expressions have to return a positive integer value.
Advanced Topics
OCL: Operations on Strings
In addition to the standard OCL String API, the flavor of OCL in reuse extensions supports the complete Java String API. This means that operations like startsWith() or indexOf() can be used on Strings. Refer to the Javadoc for Strings to learn about the supported methods:
Java String API
OCL: Refer to Container
Sometimes one needs to navigate from an element to its container in an OCL expression. The OCL flavor used in reuse extensions supports the eContainer() method to obtain a container. After using that method, the container needs to be manually casted to the correct type using oclAsType().
The following could be used to obtain the UML Package that contains the UML Class myClass:
myClass.eContainer().oclAsType(UML::Package)
OCL: Metamodel Packages
Inside OCL expressions, you can refer to a class defined in a different EPackage than the one identified in the header. This might be required when using oclIsTypeOf() or oclIsKindOf().
EPackageNsPrefix :: EClassName
For example...
myElement.oclIsTypeOf(uml::Class)
...checks if myElement is an UML Class.
OCL: Handle Enumerations
To refer to a Literal of an Enumeration, use the following schema:
EPackageNsPrefix :: EEnumName :: EEnumLiteralName