Topic
  • 6 replies
  • Latest Post - ‏2012-06-08T13:48:58Z by SystemAdmin
SystemAdmin
SystemAdmin
14225 Posts

Pinned topic Comparing Models in RSA-RTE (RSA RealTime Edition)

‏2012-06-01T19:13:53Z |
I am trying to compare two models (.emx) using code. I am familiar with the visual tool to do this (selecting two models, right click, compare with, each other) and I want to be able to perform this same operation using code.

I am working on a plugin, and I need to have the differences between the two models, that I can then iterate over and work with them. I have no idea where to even start, so any help would be greatly appreciated.
Thanks,
Updated on 2012-06-08T13:48:58Z at 2012-06-08T13:48:58Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    14225 Posts

    Re: Comparing Models in RSA-RTE (RSA RealTime Edition)

    ‏2012-06-04T15:20:57Z  
    I am fairly certain that it makes no difference that I am using the RealTime Edition, and that the model compare is the same as in RSA, so any insight would be helpful.

    Anyone?
  • vikas400
    vikas400
    3 Posts

    Re: Comparing Models in RSA-RTE (RSA RealTime Edition)

    ‏2012-06-05T11:59:46Z  
    Yes RSART uses the same model compare as RSA.

    To do it using code you need to do the following actions

    1) Create the resource for the two emx file.
    Get input stream
    Resource res = ResourceUtil.create(path, UMLPackage.eINSTANCE.getModel(), 0);//emf api
    res.load(inputStream, null);//emf api

    2) Create IInputOutputDescriptor from the resource. ( for both resource)

    3) Use MergeFacade.startVisualCompare with the arguments created from 2) ( or silent merge function etc).
  • SystemAdmin
    SystemAdmin
    14225 Posts

    Re: Comparing Models in RSA-RTE (RSA RealTime Edition)

    ‏2012-06-07T16:22:36Z  
    • vikas400
    • ‏2012-06-05T11:59:46Z
    Yes RSART uses the same model compare as RSA.

    To do it using code you need to do the following actions

    1) Create the resource for the two emx file.
    Get input stream
    Resource res = ResourceUtil.create(path, UMLPackage.eINSTANCE.getModel(), 0);//emf api
    res.load(inputStream, null);//emf api

    2) Create IInputOutputDescriptor from the resource. ( for both resource)

    3) Use MergeFacade.startVisualCompare with the arguments created from 2) ( or silent merge function etc).
    Hi there,

    Thanks for your reply, but I guess I could have been clearer in my question. I am not looking to invoke the visual compare from code, I am simply looking to compare them and have a list of differences returned that I can then use to perform other tasks.

    A bit of context: I am comparing two models, an original version and an evolved version, and the goal is to determine how they differ, and update the test cases of the original model according to those differences.

    Is there any way to do this in RSA-RTE?
  • JAQR_Adrian_Kowalik
    JAQR_Adrian_Kowalik
    8 Posts

    Re: Comparing Models in RSA-RTE (RSA RealTime Edition)

    ‏2012-06-07T21:37:33Z  
    Hi there,

    Thanks for your reply, but I guess I could have been clearer in my question. I am not looking to invoke the visual compare from code, I am simply looking to compare them and have a list of differences returned that I can then use to perform other tasks.

    A bit of context: I am comparing two models, an original version and an evolved version, and the goal is to determine how they differ, and update the test cases of the original model according to those differences.

    Is there any way to do this in RSA-RTE?
    Hi Eric,
    I know a long way to do it but it requires a lot of work. There is probably simpler way. Probably someone already did that.
    It depends on how detailed information you want to check out. I mean you could do it by comparing Model contents.
    For example take 2 packages as an input (org.eclipse.uml2.uml.Package is generalization of Model).
    You can get all elements owned by package (including other packages) using package.getOwnedElements() and so on. You can compare names of the elements, attributes and other stuff. Just look at org.eclipse.uml2.uml.
    For example to check if in package "myPackage" there is class named "MyFirstClass":

    EList<Element> elementsList = myPackage.getOwnedElements();
    Iterator<Element> elementsListIterator = elementsList.iterator();
    Element element;
    while(elementsListIterator.hasNext()){
    element = elementsListIterator.next();
    if(element instanceof Class){
    if(((Class) element).getName().equals("MyFirstClass")){
    DoFreakyStuffOnTheMonitor("We Found MyFirstClass");
    }
    }
    You can use Recursion to check contents of packages in packages. You should also remember that not only packages contain elements. Collaborations for example also can keep some elements but not as owned elements. You can learn more about UML classes by reading documentation.
    Well I am very nooby in programming and you probably know that already, but just in case I can help i am writing this.
    Good luck!
  • JAQR_Adrian_Kowalik
    JAQR_Adrian_Kowalik
    8 Posts

    Re: Comparing Models in RSA-RTE (RSA RealTime Edition)

    ‏2012-06-07T21:40:47Z  
    Hi Eric,
    I know a long way to do it but it requires a lot of work. There is probably simpler way. Probably someone already did that.
    It depends on how detailed information you want to check out. I mean you could do it by comparing Model contents.
    For example take 2 packages as an input (org.eclipse.uml2.uml.Package is generalization of Model).
    You can get all elements owned by package (including other packages) using package.getOwnedElements() and so on. You can compare names of the elements, attributes and other stuff. Just look at org.eclipse.uml2.uml.
    For example to check if in package "myPackage" there is class named "MyFirstClass":

    EList<Element> elementsList = myPackage.getOwnedElements();
    Iterator<Element> elementsListIterator = elementsList.iterator();
    Element element;
    while(elementsListIterator.hasNext()){
    element = elementsListIterator.next();
    if(element instanceof Class){
    if(((Class) element).getName().equals("MyFirstClass")){
    DoFreakyStuffOnTheMonitor("We Found MyFirstClass");
    }
    }
    You can use Recursion to check contents of packages in packages. You should also remember that not only packages contain elements. Collaborations for example also can keep some elements but not as owned elements. You can learn more about UML classes by reading documentation.
    Well I am very nooby in programming and you probably know that already, but just in case I can help i am writing this.
    Good luck!
    Sorry for my poor English.
  • SystemAdmin
    SystemAdmin
    14225 Posts

    Re: Comparing Models in RSA-RTE (RSA RealTime Edition)

    ‏2012-06-08T13:48:58Z  
    Hi there,

    Thanks for your reply, but I guess I could have been clearer in my question. I am not looking to invoke the visual compare from code, I am simply looking to compare them and have a list of differences returned that I can then use to perform other tasks.

    A bit of context: I am comparing two models, an original version and an evolved version, and the goal is to determine how they differ, and update the test cases of the original model according to those differences.

    Is there any way to do this in RSA-RTE?
    Hey all, thanks for the help.

    I actually found the answer on another forum, but thought I would post here, in case anyone else has the same question.

    I am using the emf compare of the models, that does the matching, and then differencing the match, and getting a list of differences, that I can use.


    String path1 = "someModel.emx";
    String path2 = "anotherModel.emx";

    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,new XMIResourceFactoryImpl());

    ResourceSet resourceSet1 = new ResourceSetImpl();
    ResourceSet resourceSet2 = new ResourceSetImpl();

    try {

    EObject model1 = ModelUtils.load(new File(path1), resourceSet1);
    EObject model2 = ModelUtils.load(new File(path2), resourceSet2);

    MatchModel match = MatchService.doMatch(model2, model1, Collections.<String, Object> emptyMap());

    DiffModel diff = DiffService.doDiff(match);

    EList<DiffElement> diffs = diff.getDifferences();

    print(diffs, 0);

    } catch (IOException e) {
    e.printStackTrace();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }