Using Java objects in EOL

As it is the case with all languages, model management languages have a particular scope of applicability. So, while a model-transformation language is expected to be efficient at navigating and modifying models, it is not really expected to be able e.g. to perform complex string comparison efficiently or to access an external system (e.g. a DBMS).

However, there are cases where such functionality is desirable in model management. For example, complex string comparison is required when comparing models (e.g. to merge them later) and DBMS connectivity is required if you want to validate your class model against a live database (e.g. to verify that the database contains one table per class). To enable users implement such functionality EOL (and all the languages atop it) provides support for instantiating Java objects using the built-in Native data-type and calling their methods. Two short examples follow:

Example 1: Opening a JFrame

In this example we use EOL to instantiate a JFrame, set its title and bounds and make it visible

var jframe := new Native('javax.swing.JFrame');
jframe.setBounds(0,0,100,100);
-- Equivalent to jframe.setTitle('Opened from EOL');
jframe.title := 'Opened from EOL';
jframe.visible := true;

Example 2: Comparing Strings

In this example we reuse the Simmetrics Java library to perform fuzzy string matching in the context of a model comparison:

pre {
    var simmetrics := new Native
      (’org.epsilon.ecl.tools.textcomparison.simmetrics.SimMetricsTool’);
}
rule FuzzyTree2Tree
    match l : T1!Tree
    with r : T2!Tree {

    compare : l.label.fuzzyMatch(r.label) and
         l.parent.matches(r.parent) and
         l.children.matches(r.children)
}

operation String fuzzyMatch(other : String) : Boolean {
    return simmetrics.similarity(self,other,’Levenshtein’) > 0.5;
}
About these ads
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s