Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Concordance(Use concordance in a modelling environment)
Concordance [message #1417350] Fri, 05 September 2014 08:33 Go to next message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hi,

I want to use Concordance as a framework to monitor the cross references in a modelling environment. To do this, I have to use as an extension point org.eclipse.epsilon.concordance.core.ModelChangeListener and also create a class that implements ModelChangeListener, right?? So I have some questions....

1. I've debugged and noticed that when I insert a model that is not .xmi (eg .figcom) concordance is not detected that kind of file, I'm doing something wrong ?? or is it something that needs to be configured?
2. I want if a model is deleted, all references to this model were also deleted. I have to extends DefaultModelChangeListener to access the index? What is the best way?

I'm using Eclipse Luna, 64 bit. Thanks for any help.

Cheers,
Anthony

Re: Concordance [message #1419971 is a reply to message #1417350] Tue, 09 September 2014 10:15 Go to previous messageGo to next message
Maarten Bezemer is currently offline Maarten BezemerFriend
Messages: 117
Registered: February 2012
Senior Member
Hello Anthony,

Sorry for this late reply (I was on holidays).

About your first question:
Concordance uses the list of registered models to see whether a new model is added to the workspace. If the model (file) is recognized (by (registered) file extension) then a notification is issued to let the concordance clients know about the newly added/discovered model.
This is done in org.eclipse.epsilon.concordance.dt.ConcordanceBuilder#incrementalBuild() and the check whether the added file is a registered model is done in org.eclipse.epsilon.concordance.dtResourceCategoriser#isModel().

I do not know what you did wrong without having more details. But, make sure your model (file extensions) is registered in EMF so
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().keySet()

shows your file extension in the list, otherwise Concordance will not handle your model.

Furthermore, be sure that your model is part of a project that has the 'Concordance Nature', as Concordance ignores all other projects (to spare resources). But, I suppose you already did this, as other models did seem to work..?



About your second question:
When you create a Concordance client by extending DefaultModelChangeListener (or basically implementing ModelChangeListener), you can use use the following code to visit all (cross)references with the changed (deleted in your case) model, using:
@Override
public void modelChanged(IConcordanceModel model)
{
    index.visitAllCrossReferencesWithTarget(model, myCrossReferenceVisitor);
}


Your implementation of CrossReferenceVisitor#visit() now is called for all known references to 'model'. Use the method parameter to obtain the actual EMF object that contains the reference, for example using:
Resource resource = crossReference.source.getResource();
EObject object = resource.getEObject(crossReference.source.uriFragment);


For a complete example (from which I took the code snippets) see my PortReconsiler client: https://trac.ce.utwente.nl/TERRA/browser/plugins/nl.utwente.ce.terra/src/nl/utwente/ce/terra/concordance/PortReconciler.java
It does not delete references when a model is deleted, but it updates model elements when another model is changed. But changing a reference or setting it to 'null' is basically the same thing, I suppose Smile

Another example is the ExternalModelsReconciler client: https://trac.ce.utwente.nl/TERRA/browser/plugins/nl.utwente.ce.terra/src/nl/utwente/ce/terra/concordance/ExternalModelsReconciler.java
It does not remove references when a model is deleted, instead it triggers model validation (so the user get an error about the missing model and can decide what to do about it). But, when a model is moved it does update the reference to the model using UpdateSubmodelsVisitor.



If you have other questions or things are not clear yet, feel free to ask!

Cheers,
Maarten
Re: Concordance [message #1422246 is a reply to message #1419971] Fri, 12 September 2014 14:50 Go to previous messageGo to next message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hello Maarten,

Thanks for the reply, is very useful and helped me to further understand the framework. But I don't get it to work yet. I think that concordance is not capturing the references I add, programatically into the model. When I add a reference I have to take something into account? Would I have to insert a reference with some concordance function? The problem is that index.visitAllCrossReferencesWithTarget don't visit the all references with the deleted model. Thanks!

Cheers,
Anthony

Re: Concordance [message #1423942 is a reply to message #1422246] Mon, 15 September 2014 07:58 Go to previous messageGo to next message
Maarten Bezemer is currently offline Maarten BezemerFriend
Messages: 117
Registered: February 2012
Senior Member
Hi Anthony,

As far as I know Concordance should automatically pickup any EMF references to elements of other models/files. This is done by the CrossReferenceAnalyser class of Concordance, which is in turn used by ConcordanceModelBase when it is asked to provide all cross references.
If you do not use explicit EMF references for your cross references, the CrossReferenceAnalyser won't find your references.

TERRA for example references to complete models/files (using IPath instances), therefore Concordance is not able to find these references. I created a custom cross reference analyser class: https://trac.ce.utwente.nl/TERRA/browser/plugins/nl.utwente.ce.terra/src/nl/utwente/ce/terra/concordance/TERRACrossReferenceAnalyser.java
This class finds the cross references I use in my models in the determineCrossReferences() method.

In order to actually use my custom cross reference analyser class, I extended the ConcordanceModelBase class in order to use the custom analyser, see https://trac.ce.utwente.nl/TERRA/browser/plugins/nl.utwente.ce.terra/src/nl/utwente/ce/terra/concordance/EditingDomainModel.java (note that is does some other things, for this example the getAllCrossReferences() method is most interesting).

Next, in order to use the custom IConcordanceModel-based class you need to create a factory to spawn instances of the class https://trac.ce.utwente.nl/TERRA/browser/plugins/nl.utwente.ce.terra/src/nl/utwente/ce/terra/concordance/EditingDomainModelFactory.java and register this factory to Concordance:
   <extension
         point="org.eclipse.epsilon.concordance.core.ConcordanceModelFactory">
      <factory
            factory="nl.utwente.ce.terra.concordance.EditingDomainModelFactory">
      </factory>
   </extension>


It is a bit much work to extend Concordance with such custom functionality, but it was the only way I could think of without breaking existing Concordance APIs... (I am the one who added this way of extending Concordance)

Hopefully this helps you further understanding Concordance.
If there are still/again some unknown factors, please let me know!

Cheers,
Maarten
Re: Concordance [message #1436056 is a reply to message #1423942] Thu, 02 October 2014 10:22 Go to previous messageGo to next message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hello Maarten,

Sorry to bother you again but I have other questions. I followed your instructions but there are things I should be doing wrong. So, my questions are:

1. I started to program modelRemoved, using index.visitAllCrossReferencesWithTarget and use EcoreUtil.delete(eObject); when the uri in the resource is equal with the deleted one. So two problems arises. The first one, is that in the problems view I get an error "Dangling reference ..." but I check the file and the reference is already deleted, so I would like that there was no notification. The other issue is that in the file the references changed from "platform:/resource/project/test.xmi" to "test.xmi". Concordance has something to do with it?

2. Maybe this is a silly question, sorry for that.To find the cross references, I create the custom cross references analyser. Here what I find weird is that I used
Iterator<EObject> iter = sourceModel.getEmfResource(true).getAllContents(); and to find if the object is an eproxyuri I use EcoreUtil.getURI(object) and here's a little trick,
if(!object_uri.fragment().contains("@")){// The URI of the archive must have no fragments
addCrossReference(sourceModel,xrefs,object_uri);
There's a better way right? it would be reasonable to use eProxyURI, right?

Thanks in advance!!

Cheers,
Anthony



[Updated on: Thu, 02 October 2014 11:42]

Report message to a moderator

Re: Concordance [message #1440836 is a reply to message #1436056] Wed, 08 October 2014 23:26 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Anthony,

Could you please put together a minimal example and a list of steps that we need to follow to reproduce these problems locally? Regarding your second question, would EObject.eIsProxy() be of any help?

Cheers,
Dimitris
Re: Concordance [message #1441098 is a reply to message #1440836] Thu, 09 October 2014 08:59 Go to previous messageGo to next message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hi Dimitris,

The first thing I did was to register the extension point:

<extension
       point="org.eclipse.epsilon.concordance.core.ModelChangeListener">
    <listener
          class="org.eclipse.modular.wt.concordance.ModularReconcilerReferences">
    </listener>
 </extension>
 <extension
       point="org.eclipse.epsilon.concordance.core.ConcordanceModelFactory">
    <factory
          factory="org.eclipse.modular.wt.concordance.ModularModelFactory">
    </factory>
 </extension>


So I create the class ModularModelFactory to determine the cross references(I use platform URL protocol, "platform://resource/project/...") After that the class ModularDomain, and the most interesting methods are getEmfResource and getAllCrossReferences(). The last one method call determineCrossReferences(final IConcordanceModel sourceModel)(class ModularCrossReferenceAnalyser), then I have to search for the references in the resource, checking each object and to do that, I used object_uri.fragment().contains("@") to identify if the object is stored in the file or is a reference.(that's why I do the second question, maybe is ok)

So the last class is ModularReconcilerReferences and the method modelRemoved I used index.visitAllCrossReferencesWithTarget to visit all the cross references and delete them. In visit method I check every object and essentially if internal_object.eProxyURI().toString().equals(target_uri) so I delete the object(EcoreUtil.delete(eObject)) and after all references are deleted (resource.save(null)) By doing this happens about the first question.

About my second question again in ModularReconcilerReferences I used eObject.eIsProxy() but in ModularCrossReferenceAnalyser I used object_uri.fragment().contains("@") and I don't know why in this class doesn't work for me.

Attached files with classes. Thanks!!

Cheers,
Anthony

  • Attachment: code.rar
    (Size: 2.92KB, Downloaded 95 times)
Re: Concordance [message #1441265 is a reply to message #1441098] Thu, 09 October 2014 13:28 Go to previous messageGo to next message
Maarten Bezemer is currently offline Maarten BezemerFriend
Messages: 117
Registered: February 2012
Senior Member
Hi,

You minimal example does not compile/execute, its plugin.xml is missing and you did not provide steps to reproduce the problem.
Furthermore, could you try to explain what you are trying do? It looks to me you are trying to find referenced object and remove the reference when the referenced object is deleted? If this is the case, this is basically done by the build-in CrossReferenceReconciler Concordance client. Difference is that it adds error markers for dangling cross references, whereas you want delete the references. So make use of that code/example and replace the marker creation with deleting a reference.

I'll try to point out some things/oddities that I noticed during my manual inspection of your code.

When I look at your code (in ModularCrossReferenceAnalyser#determineCrossReferences()) you seem to look for EObjects that are defined in/part of another model?
But you check whether the object uri is unequal to the model uri, which is always the case as the
object_uri = model_uri+'path in model' (as fragment)

Next, you check if the fragment does not contain an '@'. Does the '@' indicate that it is an object from another model? If so, you should remove the '!' as it actually should contain the '@'.

When you add a cross reference, you create a sourceElement using the source model and the URI of the source model. This is wrong, you should use the URI of the element that contains the cross reference!! Which is object_uri.fragment(). The targetElement should point to the other model which is not object_uri, but something else. (I suppose it would be object.eProxyURI(), but I am not familiar with proxied objects...)

As you do not create correct cross references (wrong source and target elements), the CrossReferenceVisitor won't find the cross references (in the modelRemoved() method).

When you verify my comments, try to sue a debugger to see whether your code to find cross references indeed calls addCrossReference().
If not, your detection code is wrong (which I suspect).
If it does call the method, the way of adding cross references is wrong (which I am quite sure of).

If you confirmed that both points are correct/fixed, you should debug ModularReconcilerReferences by placing a breakpoint at modelRemoved() and visit(), to see that these methods are called, if not something else is wrong with your cross references...


On a last note, next time try to provide a minimal example that can be complied and executed: In your case provide a complete plugin with its plugin.xml and all required classes (FileUtils is missing, although I suppose you copied it from TERRA, so I can guess what it contains... Wink )
This way we can (more) easily see what is wrong and do not require to manually debug your code (without executing it...). As this takes/took a lot (too much when looking back...) of time, I won't do this a next time!

Cheers,
Maarten
Re: Concordance [message #1441952 is a reply to message #1441265] Fri, 10 October 2014 12:01 Go to previous messageGo to next message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hello Marteen,

First of all, apologize for the minimal example, this time I attached the project that you can compile and an example of models. I have checked your comments and I've changed the code according to your instructions. In the example, I try to delete the references when the file refereced is deleted. So, you were right about sourceElement
and I've changed sourceModel.getEmfResource(false).getURIFragment(object) and I debug and indeed calls addCrossReference(). Also I debug ModularReconcilerReferences and find the object, but when I deleted the reference all the references in the file change from "platform:/resource/project/test.xmi" to "test.xmi" and in the problems view I still get an error of "Dangling reference ...". How can I solve this?
project: org.manage.references.concordance
workspace_runtime: org.manage.references.concordance/workspace_runtime there is a folder called example which I used for do the test. i think that know you can compiled and executed without a problem.

Thanks again for your help and time, I really appreciate it!!

Cheers,
Anthony
Re: Concordance [message #1445454 is a reply to message #1441952] Wed, 15 October 2014 13:07 Go to previous messageGo to next message
Maarten Bezemer is currently offline Maarten BezemerFriend
Messages: 117
Registered: February 2012
Senior Member
Hi,

I tried your example plugin and saw you managed to fix the concordance client which removes the model elements that point to deleted files. It seems to be working fine!

The dangling reference error you get for free from the CrossReferenceReconciler client (example client of Concordance provided by the org.eclipse.epsilon.concordance.clients plugin). You cannot get rid of these example clients at the time being (see http://www.eclipse.org/forums/index.php/t/519378/ where I ask about them).

So, you need to trigger the client somehow to remove the error marker after ModularReconcilerReferences#DeleteModelVisitor#visit() changed the model (and removed the dangling reference).
I do not know how to do so exactly, in my application I circumvented this problem by using IPath instances to refer to other model( file)s, which are not picked up by the CrossReferenceReconciler... Wink Rolling Eyes
(I had other reasons to use IPaths insread of EMF (href) references, so I circumvented this problem by accident)

Maybe it is a bug after all that these client cannot be deactivated/deinstalled...?
You could open a bug report telling about this problem and the (other) developers can think about this.

Hopefully someone else can help you with this problem...

Cheers,
Maarten
Re: Concordance [message #1450234 is a reply to message #1445454] Wed, 22 October 2014 08:21 Go to previous message
Antonio Garmendia is currently offline Antonio GarmendiaFriend
Messages: 93
Registered: May 2014
Member
Hi Marteen,

Thanks for the replies and to check my code. I've seen what you're saying and the way seems better for me is to delete the marker using MarkerManager.removemarker and to update the database ConcordancePlugin.getDefault().getModelChangeReporter().reportChange. I think it works fine...Thanks for your help!

Cheers,
Anthony
Previous Topic:[EOL/ECL] Hot to read a stereotype property from a collection
Next Topic:[EOL] [EVL] Escape character
Goto Forum:
  


Current Time: Thu Apr 25 21:58:48 GMT 2024

Powered by FUDForum. Page generated in 0.03782 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top