Home » Modeling » Epsilon » Concordance(Use concordance in a modelling environment)
|
Re: Concordance [message #1419971 is a reply to message #1417350] |
Tue, 09 September 2014 10:15 |
Maarten Bezemer 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
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 #1423942 is a reply to message #1422246] |
Mon, 15 September 2014 07:58 |
Maarten Bezemer 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 |
Antonio Garmendia 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 |
|
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 |
Antonio Garmendia 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 |
Maarten Bezemer 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... )
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
|
|
| | | |
Goto Forum:
Current Time: Thu Apr 25 21:58:48 GMT 2024
Powered by FUDForum. Page generated in 0.03782 seconds
|