Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » RE: EMF Compare of two Domain Specific Models
|
Re: EMF Compare of two Domain Specific Models [message #122662 is a reply to message #122657] |
Mon, 19 May 2008 12:30 |
|
This is a multi-part message in MIME format.
--------------080206090801000009050208
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Mark,
I think I will need a little more informations here... What is the exact
use case? You're using a main() method to launch EMF Compare on two
models in the same Eclipse where you registered A.ecore MetaModel? Or
did you try registering and reading your model files in another Eclipse?
AFAIK, AM3 registers the metamodel in the global EMF registry through
EPackage.Registry. If it is the case -and you're using EMF Compare in
the same Eclipse instance-, the comparison should run smoothly since we
simply delegate the resource loading Resource#load() which should in
turn use this registry (Ed might be able to confirm/infirm this).
You didn't provide us the code you use to compare models, I believe you
tried the snippet I gave to Lars sometime before this :
EObject model1 = ModelUtils.load(model1, resourceSet);
EObject model2 = ModelUtils.load(model2, resourceSet);
MatchModel match = MatchService.doMatch(model1, model2,
Collections.<String, Object> emptyMap());
DiffModel diff = DiffService.doDiff(match, false);
You'll probably need to register the metamodel yourself in order to have
your resources loaded as expected. This can be achieved by a code like :
// Assuming the first root of the metamodel is an EPackage
EPackage model = (EPackage)ModelUtils.load(metamodel, resourceSet);
// In your example, nsURI should be http://www.abc.com/#A
EPackage.Registry.INSTANCE.put(nsURI, model);
This should be made before you load the two other models.
Cheers,
Laurent Goubet
Obeo
Mark Melia a
|
|
|
Re: EMF Compare of two Domain Specific Models [message #122667 is a reply to message #122662] |
Mon, 19 May 2008 14:05 |
Mark Melia Messages: 142 Registered: July 2009 |
Senior Member |
|
|
Hi Laurent,
That was it, I just needed to register the metamodel in the code as you
said - thanks!!!
One more thing I am now getting an error
org.eclipse.emf.compare.FactoryException: The feature name does not exist
in LearningContext - I am not sure what is going on here?
LearningContext is an eClass in the metamodel - A.ecore and does not have
a name attribute. B.ecore has an instance of the LearningContext - this
too does not have a name attribute in its definition.
By the way I am using the main method as described below, when you were
helping me before.
public static void main(String[] args) {
try {
final ResourceSet modelResourceSet = new ResourceSetImpl();
// Assuming the first root of the metamodel is an EPackage
EPackage model = (EPackage)ModelUtils.load(new
File("/home/mmelia/workspace3/AATest/model/A.ecore"), modelResourceSet);
// In your example, nsURI should be http://www.abc.com/#A
EPackage.Registry.INSTANCE.put("http://dcu.ie/#A", model);
Resource model1 = ModelUtils.load(new
File("/home/mmelia/workspace3/AATest/model/B.ecore"),
modelResourceSet).eResource();
Resource model2 =
ModelUtils.load(URI.createFileURI("/home/mmelia/workspace3/AATest/model/C.ecore "),modelResourceSet).eResource();
final MatchModel match = MatchService.doResourceMatch(model1, model2,
null);
// Detects differences
final DiffModel diff = DiffService.doDiff(match);//EXCEPTION HERE
// Merges all differences from model1 to model2
MergeService.merge(diff.getOwnedElements(), true);
} catch (Exception exception) {
exception.printStackTrace();
}
}
laurent Goubet wrote:
> Mark,
> I think I will need a little more informations here... What is the exact
> use case? You're using a main() method to launch EMF Compare on two
> models in the same Eclipse where you registered A.ecore MetaModel? Or
> did you try registering and reading your model files in another Eclipse?
> AFAIK, AM3 registers the metamodel in the global EMF registry through
> EPackage.Registry. If it is the case -and you're using EMF Compare in
> the same Eclipse instance-, the comparison should run smoothly since we
> simply delegate the resource loading Resource#load() which should in
> turn use this registry (Ed might be able to confirm/infirm this).
> You didn't provide us the code you use to compare models, I believe you
> tried the snippet I gave to Lars sometime before this :
> EObject model1 = ModelUtils.load(model1, resourceSet);
> EObject model2 = ModelUtils.load(model2, resourceSet);
> MatchModel match = MatchService.doMatch(model1, model2,
> Collections.<String, Object> emptyMap());
> DiffModel diff = DiffService.doDiff(match, false);
> You'll probably need to register the metamodel yourself in order to have
> your resources loaded as expected. This can be achieved by a code like :
> // Assuming the first root of the metamodel is an EPackage
> EPackage model = (EPackage)ModelUtils.load(metamodel, resourceSet);
> // In your example, nsURI should be http://www.abc.com/#A
> EPackage.Registry.INSTANCE.put(nsURI, model);
> This should be made before you load the two other models.
> Cheers,
> Laurent Goubet
> Obeo
> Mark Melia a écrit :
>> Hi all,
>>
>> I am trying to merge two DSLs together using EMF Compare. I have 3 ecore
>> models, A.ecore (namespace - http://www.abc.com/#A), B.ecore and
>> C.ecore. A.ecore is the metamodel of B.ecore and C.ecore. I want to
>> merge B.ecore and C.ecore, and I am using EMF compare to do this. I
>> register A.ecore as a metamodel using AM3 - this works as I can see
>> B.ecore and C.ecore using the Ecore Model Editor. When I run my EMF
>> Compare program I get the following error - any ideas (thanks in advance
>> :)):
>> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with
>> uri 'http://www.abc.com/#A' not found.
>> (file:/home/mmelia/workspace3/AATest/model/B.ecore, 3, 101)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL oadImpl.java:83)
>>
>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:191)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1414)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1210)
>>
>> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :335)
>> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :217)
>> at test.Test.main(Test.java:25)
>> Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package
>> with uri 'http://www.abc.com/#A' not found.
>> (file:/home/mmelia/workspace3/AATest/model/B.ecore, 3, 101)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2566)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:2398)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1276)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1445)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1010)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:83)
>>
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:992)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:712)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(AbstractSAXParser.java:501)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(AbstractXMLDocumentParser.java:179)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator. emptyElement(XMLDTDValidator.java:788)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.j ava:1337)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl. java:1289)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(XMLDocumentFragmentSca nnerImpl.java:3084)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(XMLDocumentScannerImpl.java:645)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 508)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:807)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:737)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:107)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1205)
>>
>> at
>>
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(SAXParserImpl.java:522)
>>
>> at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
>> .. 6 more
>>
|
|
|
Re: EMF Compare of two Domain Specific Models [message #122673 is a reply to message #122667] |
Mon, 19 May 2008 14:34 |
|
This is a multi-part message in MIME format.
--------------090302040706040905030508
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Mark,
Such exception usually mean your model isn't valid : you have defined
"LearningContext" in your metamodel with a set of attributes/references
which does not include an attribute named "name", yet in your model you
have created an instance of LearningContext and defined a "name" on it.
When registering your metamodel through AM3, can you open both of the
models your comparing in the ecore editor? If yes, you probably don't
register the good metamodel through code
("/home/mmelia/workspace3/AATest/model/A.ecore"). Otherwise, you'll need
to change the XML of your model to delete the wrong "name" attribute to
validate it.
Another option would be to set the loading option
"XMLResource.OPTION_RECORD_UNKNOWN_FEATURE" to true for your model ...
but this is a dangerous way to go since EMF will then simply ignore all
feature it doesn't know about and save them back only if you specify
this option for model.save() as well.
Laurent Goubet
Obeo
Mark Melia a
|
|
|
Re: EMF Compare of two Domain Specific Models [message #122677 is a reply to message #122673] |
Mon, 19 May 2008 16:23 |
Mark Melia Messages: 142 Registered: July 2009 |
Senior Member |
|
|
Hi Laurent,
Again thanks for your help!
I fixed up the models, so that they both have the same root model element
this solved this problem. I think EMF Compare needs to have a common point
of reference in order to work out the differences in the models - perhaps
you could correct me if I am wrong here?
Thanks,
Mark
laurent Goubet wrote:
> Mark,
> Such exception usually mean your model isn't valid : you have defined
> "LearningContext" in your metamodel with a set of attributes/references
> which does not include an attribute named "name", yet in your model you
> have created an instance of LearningContext and defined a "name" on it.
> When registering your metamodel through AM3, can you open both of the
> models your comparing in the ecore editor? If yes, you probably don't
> register the good metamodel through code
> ("/home/mmelia/workspace3/AATest/model/A.ecore"). Otherwise, you'll need
> to change the XML of your model to delete the wrong "name" attribute to
> validate it.
> Another option would be to set the loading option
> "XMLResource.OPTION_RECORD_UNKNOWN_FEATURE" to true for your model ...
> but this is a dangerous way to go since EMF will then simply ignore all
> feature it doesn't know about and save them back only if you specify
> this option for model.save() as well.
> Laurent Goubet
> Obeo
> Mark Melia a écrit :
>> Hi Laurent,
>>
>> That was it, I just needed to register the metamodel in the code as you
>> said - thanks!!!
>> One more thing I am now getting an error
>> org.eclipse.emf.compare.FactoryException: The feature name does not
>> exist in LearningContext - I am not sure what is going on here?
>>
>> LearningContext is an eClass in the metamodel - A.ecore and does not
>> have a name attribute. B.ecore has an instance of the LearningContext -
>> this too does not have a name attribute in its definition.
>>
>> By the way I am using the main method as described below, when you were
>> helping me before.
>>
>> public static void main(String[] args) {
>> try {
>> final ResourceSet modelResourceSet = new ResourceSetImpl();
>> // Assuming the first root of the metamodel is an EPackage
>> EPackage model = (EPackage)ModelUtils.load(new
>> File("/home/mmelia/workspace3/AATest/model/A.ecore"), modelResourceSet);
>> // In your example, nsURI should be http://www.abc.com/#A
>> EPackage.Registry.INSTANCE.put("http://dcu.ie/#A", model);
>>
>>
>> Resource model1 = ModelUtils.load(new
>> File("/home/mmelia/workspace3/AATest/model/B.ecore"),
>> modelResourceSet).eResource(); Resource model2 =
>>
ModelUtils.load(URI.createFileURI("/home/mmelia/workspace3/AATest/model/C.ecore "),modelResourceSet).eResource();
>>
>>
>> final MatchModel match =
>> MatchService.doResourceMatch(model1, model2, null);
>> // Detects differences
>> final DiffModel diff = DiffService.doDiff(match);//EXCEPTION
>> HERE
>> // Merges all differences from model1 to model2
>> MergeService.merge(diff.getOwnedElements(), true);
>> } catch (Exception exception) {
>> exception.printStackTrace();
>> }
>> }
>>
>>
>>
>> laurent Goubet wrote:
>>
>>> Mark,
>>
>>> I think I will need a little more informations here... What is the
>>> exact use case? You're using a main() method to launch EMF Compare on
>>> two models in the same Eclipse where you registered A.ecore MetaModel?
>>> Or did you try registering and reading your model files in another
>>> Eclipse?
>>
>>> AFAIK, AM3 registers the metamodel in the global EMF registry through
>>> EPackage.Registry. If it is the case -and you're using EMF Compare in
>>> the same Eclipse instance-, the comparison should run smoothly since
>>> we simply delegate the resource loading Resource#load() which should
>>> in turn use this registry (Ed might be able to confirm/infirm this).
>>
>>> You didn't provide us the code you use to compare models, I believe
>>> you tried the snippet I gave to Lars sometime before this :
>>
>>> EObject model1 = ModelUtils.load(model1, resourceSet);
>>> EObject model2 = ModelUtils.load(model2, resourceSet);
>>
>>> MatchModel match = MatchService.doMatch(model1, model2,
>>> Collections.<String, Object> emptyMap());
>>> DiffModel diff = DiffService.doDiff(match, false);
>>
>>> You'll probably need to register the metamodel yourself in order to
>>> have your resources loaded as expected. This can be achieved by a code
>>> like :
>>
>>> // Assuming the first root of the metamodel is an EPackage
>>> EPackage model = (EPackage)ModelUtils.load(metamodel, resourceSet);
>>> // In your example, nsURI should be http://www.abc.com/#A
>>> EPackage.Registry.INSTANCE.put(nsURI, model);
>>
>>> This should be made before you load the two other models.
>>
>>> Cheers,
>>> Laurent Goubet
>>> Obeo
>>
>>> Mark Melia a écrit :
>>>> Hi all,
>>>>
>>>> I am trying to merge two DSLs together using EMF Compare. I have 3
>>>> ecore models, A.ecore (namespace - http://www.abc.com/#A), B.ecore
>>>> and C.ecore. A.ecore is the metamodel of B.ecore and C.ecore. I want
>>>> to merge B.ecore and C.ecore, and I am using EMF compare to do this.
>>>> I register A.ecore as a metamodel using AM3 - this works as I can see
>>>> B.ecore and C.ecore using the Ecore Model Editor. When I run my EMF
>>>> Compare program I get the following error - any ideas (thanks in
>>>> advance :)):
>>>> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package
>>>> with uri 'http://www.abc.com/#A' not found.
>>>> (file:/home/mmelia/workspace3/AATest/model/B.ecore, 3, 101)
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL oadImpl.java:83)
>>
>>>>
>>>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:191)
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1414)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1210)
>>
>>>>
>>>> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :335)
>>>> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :217)
>>>> at test.Test.main(Test.java:25)
>>>> Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException:
>>>> Package with uri 'http://www.abc.com/#A' not found.
>>>> (file:/home/mmelia/workspace3/AATest/model/B.ecore, 3, 101)
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2566)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:2398)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1276)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1445)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1010)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:83)
>>
>>>>
>>>> at
>>>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:992)
>>>>
>>>> at
>>>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:712)
>>>>
>>>> at
>>>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(AbstractSAXParser.java:501)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(AbstractXMLDocumentParser.java:179)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator. emptyElement(XMLDTDValidator.java:788)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.j ava:1337)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl. java:1289)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(XMLDocumentFragmentSca nnerImpl.java:3084)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(XMLDocumentScannerImpl.java:645)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 508)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:807)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:737)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:107)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1205)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(SAXParserImpl.java:522)
>>
>>>>
>>>> at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
>>>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
>>>> .. 6 more
>>>>
>>
>>
|
|
|
Re: EMF Compare of two Domain Specific Models [message #122687 is a reply to message #122677] |
Tue, 20 May 2008 06:39 |
|
This is a multi-part message in MIME format.
--------------020506060000080808050007
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Mark,
When models have multiple roots, EMF Compare will try and match them as
it would for the roots' contents. If no roots can be matched together,
it will assume the two "first" roots are "identical" and begin matching
their respective contents; so EMF Compare does not need a common point
of reference to figure out differences (you can even compare a .ecore
with a .uml... I doubt the differences will be meaningful though ;)).
Laurent Goubet
Obeo
Mark Melia a
|
|
|
Re: EMF Compare of two Domain Specific Models [message #618066 is a reply to message #122657] |
Mon, 19 May 2008 12:30 |
|
This is a multi-part message in MIME format.
--------------080206090801000009050208
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Mark,
I think I will need a little more informations here... What is the exact
use case? You're using a main() method to launch EMF Compare on two
models in the same Eclipse where you registered A.ecore MetaModel? Or
did you try registering and reading your model files in another Eclipse?
AFAIK, AM3 registers the metamodel in the global EMF registry through
EPackage.Registry. If it is the case -and you're using EMF Compare in
the same Eclipse instance-, the comparison should run smoothly since we
simply delegate the resource loading Resource#load() which should in
turn use this registry (Ed might be able to confirm/infirm this).
You didn't provide us the code you use to compare models, I believe you
tried the snippet I gave to Lars sometime before this :
EObject model1 = ModelUtils.load(model1, resourceSet);
EObject model2 = ModelUtils.load(model2, resourceSet);
MatchModel match = MatchService.doMatch(model1, model2,
Collections.<String, Object> emptyMap());
DiffModel diff = DiffService.doDiff(match, false);
You'll probably need to register the metamodel yourself in order to have
your resources loaded as expected. This can be achieved by a code like :
// Assuming the first root of the metamodel is an EPackage
EPackage model = (EPackage)ModelUtils.load(metamodel, resourceSet);
// In your example, nsURI should be http://www.abc.com/#A
EPackage.Registry.INSTANCE.put(nsURI, model);
This should be made before you load the two other models.
Cheers,
Laurent Goubet
Obeo
Mark Melia a
|
|
|
Re: EMF Compare of two Domain Specific Models [message #618067 is a reply to message #122662] |
Mon, 19 May 2008 14:05 |
Mark Melia Messages: 142 Registered: July 2009 |
Senior Member |
|
|
Hi Laurent,
That was it, I just needed to register the metamodel in the code as you
said - thanks!!!
One more thing I am now getting an error
org.eclipse.emf.compare.FactoryException: The feature name does not exist
in LearningContext - I am not sure what is going on here?
LearningContext is an eClass in the metamodel - A.ecore and does not have
a name attribute. B.ecore has an instance of the LearningContext - this
too does not have a name attribute in its definition.
By the way I am using the main method as described below, when you were
helping me before.
public static void main(String[] args) {
try {
final ResourceSet modelResourceSet = new ResourceSetImpl();
// Assuming the first root of the metamodel is an EPackage
EPackage model = (EPackage)ModelUtils.load(new
File("/home/mmelia/workspace3/AATest/model/A.ecore"), modelResourceSet);
// In your example, nsURI should be http://www.abc.com/#A
EPackage.Registry.INSTANCE.put("http://dcu.ie/#A", model);
Resource model1 = ModelUtils.load(new
File("/home/mmelia/workspace3/AATest/model/B.ecore"),
modelResourceSet).eResource();
Resource model2 =
ModelUtils.load(URI.createFileURI("/home/mmelia/workspace3/AATest/model/C.ecore "),modelResourceSet).eResource();
final MatchModel match = MatchService.doResourceMatch(model1, model2,
null);
// Detects differences
final DiffModel diff = DiffService.doDiff(match);//EXCEPTION HERE
// Merges all differences from model1 to model2
MergeService.merge(diff.getOwnedElements(), true);
} catch (Exception exception) {
exception.printStackTrace();
}
}
laurent Goubet wrote:
> Mark,
> I think I will need a little more informations here... What is the exact
> use case? You're using a main() method to launch EMF Compare on two
> models in the same Eclipse where you registered A.ecore MetaModel? Or
> did you try registering and reading your model files in another Eclipse?
> AFAIK, AM3 registers the metamodel in the global EMF registry through
> EPackage.Registry. If it is the case -and you're using EMF Compare in
> the same Eclipse instance-, the comparison should run smoothly since we
> simply delegate the resource loading Resource#load() which should in
> turn use this registry (Ed might be able to confirm/infirm this).
> You didn't provide us the code you use to compare models, I believe you
> tried the snippet I gave to Lars sometime before this :
> EObject model1 = ModelUtils.load(model1, resourceSet);
> EObject model2 = ModelUtils.load(model2, resourceSet);
> MatchModel match = MatchService.doMatch(model1, model2,
> Collections.<String, Object> emptyMap());
> DiffModel diff = DiffService.doDiff(match, false);
> You'll probably need to register the metamodel yourself in order to have
> your resources loaded as expected. This can be achieved by a code like :
> // Assuming the first root of the metamodel is an EPackage
> EPackage model = (EPackage)ModelUtils.load(metamodel, resourceSet);
> // In your example, nsURI should be http://www.abc.com/#A
> EPackage.Registry.INSTANCE.put(nsURI, model);
> This should be made before you load the two other models.
> Cheers,
> Laurent Goubet
> Obeo
> Mark Melia a écrit :
>> Hi all,
>>
>> I am trying to merge two DSLs together using EMF Compare. I have 3 ecore
>> models, A.ecore (namespace - http://www.abc.com/#A), B.ecore and
>> C.ecore. A.ecore is the metamodel of B.ecore and C.ecore. I want to
>> merge B.ecore and C.ecore, and I am using EMF compare to do this. I
>> register A.ecore as a metamodel using AM3 - this works as I can see
>> B.ecore and C.ecore using the Ecore Model Editor. When I run my EMF
>> Compare program I get the following error - any ideas (thanks in advance
>> :)):
>> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with
>> uri 'http://www.abc.com/#A' not found.
>> (file:/home/mmelia/workspace3/AATest/model/B.ecore, 3, 101)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL oadImpl.java:83)
>>
>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:191)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1414)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1210)
>>
>> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :335)
>> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :217)
>> at test.Test.main(Test.java:25)
>> Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package
>> with uri 'http://www.abc.com/#A' not found.
>> (file:/home/mmelia/workspace3/AATest/model/B.ecore, 3, 101)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2566)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:2398)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1276)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1445)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1010)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:83)
>>
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:992)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:712)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(AbstractSAXParser.java:501)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(AbstractXMLDocumentParser.java:179)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator. emptyElement(XMLDTDValidator.java:788)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.j ava:1337)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl. java:1289)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(XMLDocumentFragmentSca nnerImpl.java:3084)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(XMLDocumentScannerImpl.java:645)
>>
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 508)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:807)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:737)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:107)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1205)
>>
>> at
>>
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(SAXParserImpl.java:522)
>>
>> at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
>> .. 6 more
>>
|
|
|
Re: EMF Compare of two Domain Specific Models [message #618068 is a reply to message #122667] |
Mon, 19 May 2008 14:34 |
|
This is a multi-part message in MIME format.
--------------090302040706040905030508
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Mark,
Such exception usually mean your model isn't valid : you have defined
"LearningContext" in your metamodel with a set of attributes/references
which does not include an attribute named "name", yet in your model you
have created an instance of LearningContext and defined a "name" on it.
When registering your metamodel through AM3, can you open both of the
models your comparing in the ecore editor? If yes, you probably don't
register the good metamodel through code
("/home/mmelia/workspace3/AATest/model/A.ecore"). Otherwise, you'll need
to change the XML of your model to delete the wrong "name" attribute to
validate it.
Another option would be to set the loading option
"XMLResource.OPTION_RECORD_UNKNOWN_FEATURE" to true for your model ...
but this is a dangerous way to go since EMF will then simply ignore all
feature it doesn't know about and save them back only if you specify
this option for model.save() as well.
Laurent Goubet
Obeo
Mark Melia a
|
|
|
Re: EMF Compare of two Domain Specific Models [message #618069 is a reply to message #122673] |
Mon, 19 May 2008 16:23 |
Mark Melia Messages: 142 Registered: July 2009 |
Senior Member |
|
|
Hi Laurent,
Again thanks for your help!
I fixed up the models, so that they both have the same root model element
this solved this problem. I think EMF Compare needs to have a common point
of reference in order to work out the differences in the models - perhaps
you could correct me if I am wrong here?
Thanks,
Mark
laurent Goubet wrote:
> Mark,
> Such exception usually mean your model isn't valid : you have defined
> "LearningContext" in your metamodel with a set of attributes/references
> which does not include an attribute named "name", yet in your model you
> have created an instance of LearningContext and defined a "name" on it.
> When registering your metamodel through AM3, can you open both of the
> models your comparing in the ecore editor? If yes, you probably don't
> register the good metamodel through code
> ("/home/mmelia/workspace3/AATest/model/A.ecore"). Otherwise, you'll need
> to change the XML of your model to delete the wrong "name" attribute to
> validate it.
> Another option would be to set the loading option
> "XMLResource.OPTION_RECORD_UNKNOWN_FEATURE" to true for your model ...
> but this is a dangerous way to go since EMF will then simply ignore all
> feature it doesn't know about and save them back only if you specify
> this option for model.save() as well.
> Laurent Goubet
> Obeo
> Mark Melia a écrit :
>> Hi Laurent,
>>
>> That was it, I just needed to register the metamodel in the code as you
>> said - thanks!!!
>> One more thing I am now getting an error
>> org.eclipse.emf.compare.FactoryException: The feature name does not
>> exist in LearningContext - I am not sure what is going on here?
>>
>> LearningContext is an eClass in the metamodel - A.ecore and does not
>> have a name attribute. B.ecore has an instance of the LearningContext -
>> this too does not have a name attribute in its definition.
>>
>> By the way I am using the main method as described below, when you were
>> helping me before.
>>
>> public static void main(String[] args) {
>> try {
>> final ResourceSet modelResourceSet = new ResourceSetImpl();
>> // Assuming the first root of the metamodel is an EPackage
>> EPackage model = (EPackage)ModelUtils.load(new
>> File("/home/mmelia/workspace3/AATest/model/A.ecore"), modelResourceSet);
>> // In your example, nsURI should be http://www.abc.com/#A
>> EPackage.Registry.INSTANCE.put("http://dcu.ie/#A", model);
>>
>>
>> Resource model1 = ModelUtils.load(new
>> File("/home/mmelia/workspace3/AATest/model/B.ecore"),
>> modelResourceSet).eResource(); Resource model2 =
>>
ModelUtils.load(URI.createFileURI("/home/mmelia/workspace3/AATest/model/C.ecore "),modelResourceSet).eResource();
>>
>>
>> final MatchModel match =
>> MatchService.doResourceMatch(model1, model2, null);
>> // Detects differences
>> final DiffModel diff = DiffService.doDiff(match);//EXCEPTION
>> HERE
>> // Merges all differences from model1 to model2
>> MergeService.merge(diff.getOwnedElements(), true);
>> } catch (Exception exception) {
>> exception.printStackTrace();
>> }
>> }
>>
>>
>>
>> laurent Goubet wrote:
>>
>>> Mark,
>>
>>> I think I will need a little more informations here... What is the
>>> exact use case? You're using a main() method to launch EMF Compare on
>>> two models in the same Eclipse where you registered A.ecore MetaModel?
>>> Or did you try registering and reading your model files in another
>>> Eclipse?
>>
>>> AFAIK, AM3 registers the metamodel in the global EMF registry through
>>> EPackage.Registry. If it is the case -and you're using EMF Compare in
>>> the same Eclipse instance-, the comparison should run smoothly since
>>> we simply delegate the resource loading Resource#load() which should
>>> in turn use this registry (Ed might be able to confirm/infirm this).
>>
>>> You didn't provide us the code you use to compare models, I believe
>>> you tried the snippet I gave to Lars sometime before this :
>>
>>> EObject model1 = ModelUtils.load(model1, resourceSet);
>>> EObject model2 = ModelUtils.load(model2, resourceSet);
>>
>>> MatchModel match = MatchService.doMatch(model1, model2,
>>> Collections.<String, Object> emptyMap());
>>> DiffModel diff = DiffService.doDiff(match, false);
>>
>>> You'll probably need to register the metamodel yourself in order to
>>> have your resources loaded as expected. This can be achieved by a code
>>> like :
>>
>>> // Assuming the first root of the metamodel is an EPackage
>>> EPackage model = (EPackage)ModelUtils.load(metamodel, resourceSet);
>>> // In your example, nsURI should be http://www.abc.com/#A
>>> EPackage.Registry.INSTANCE.put(nsURI, model);
>>
>>> This should be made before you load the two other models.
>>
>>> Cheers,
>>> Laurent Goubet
>>> Obeo
>>
>>> Mark Melia a écrit :
>>>> Hi all,
>>>>
>>>> I am trying to merge two DSLs together using EMF Compare. I have 3
>>>> ecore models, A.ecore (namespace - http://www.abc.com/#A), B.ecore
>>>> and C.ecore. A.ecore is the metamodel of B.ecore and C.ecore. I want
>>>> to merge B.ecore and C.ecore, and I am using EMF compare to do this.
>>>> I register A.ecore as a metamodel using AM3 - this works as I can see
>>>> B.ecore and C.ecore using the Ecore Model Editor. When I run my EMF
>>>> Compare program I get the following error - any ideas (thanks in
>>>> advance :)):
>>>> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package
>>>> with uri 'http://www.abc.com/#A' not found.
>>>> (file:/home/mmelia/workspace3/AATest/model/B.ecore, 3, 101)
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL oadImpl.java:83)
>>
>>>>
>>>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:191)
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1414)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1210)
>>
>>>>
>>>> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :335)
>>>> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :217)
>>>> at test.Test.main(Test.java:25)
>>>> Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException:
>>>> Package with uri 'http://www.abc.com/#A' not found.
>>>> (file:/home/mmelia/workspace3/AATest/model/B.ecore, 3, 101)
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2566)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:2398)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1276)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1445)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1010)
>>
>>>>
>>>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:83)
>>
>>>>
>>>> at
>>>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:992)
>>>>
>>>> at
>>>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:712)
>>>>
>>>> at
>>>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(AbstractSAXParser.java:501)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(AbstractXMLDocumentParser.java:179)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator. emptyElement(XMLDTDValidator.java:788)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.j ava:1337)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl. java:1289)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(XMLDocumentFragmentSca nnerImpl.java:3084)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(XMLDocumentScannerImpl.java:645)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 508)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:807)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:737)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:107)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1205)
>>
>>>>
>>>> at
>>
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(SAXParserImpl.java:522)
>>
>>>>
>>>> at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
>>>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
>>>> .. 6 more
>>>>
>>
>>
|
|
|
Re: EMF Compare of two Domain Specific Models [message #618071 is a reply to message #122677] |
Tue, 20 May 2008 06:39 |
|
This is a multi-part message in MIME format.
--------------020506060000080808050007
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Mark,
When models have multiple roots, EMF Compare will try and match them as
it would for the roots' contents. If no roots can be matched together,
it will assume the two "first" roots are "identical" and begin matching
their respective contents; so EMF Compare does not need a common point
of reference to figure out differences (you can even compare a .ecore
with a .uml... I doubt the differences will be meaningful though ;)).
Laurent Goubet
Obeo
Mark Melia a
|
|
|
Goto Forum:
Current Time: Fri Apr 26 03:43:56 GMT 2024
Powered by FUDForum. Page generated in 0.04852 seconds
|