Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » (no subject)
(no subject) [message #687377] Fri, 03 June 2011 14:02
Federico Tomassetti is currently offline Federico TomassettiFriend
Messages: 190
Registered: July 2009
Location: Dublin
Senior Member

Hello, I am getting an HREFDanglingException that I would not expect to find...

I wrote a method that should get every dangling EObject and add it to the resource so that no dangling objects remain and the exception does not appear. This is the code... it doesn't work for some reason, can you spot it?



...
for (EObject eo : resource.getContents()){
inspect(eo,r);
}
resource.save(new HashMap<Object,Object>()); // -> DanglingHREFException!
...


private static void inspect(EObject eo, Resource r) {
if (eo==null) return;
if (eo.eResource()==null){
throw new IllegalArgumentException();
}
EClass ec = eo.eClass();
for (EReference er : ec.getEReferences()) {
if (er.isContainment()) {
if (er.isMany()) {
for (EObject sub : (List<EObject>) eo.eGet(er)) {
inspect(sub,r);
}
} else {
inspect((EObject) eo.eGet(er),r);
}
} else {
if (er.isMany()) {
for (EObject sub : (List<EObject>) eo.eGet(er)) {
if (sub.eResource() == null) {
r.getContents().add(sub);
inspect(sub, r);
}
}
} else {
EObject sub = (EObject) eo.eGet(er);
if (sub != null) {
if (sub.eResource() == null) {
r.getContents().add(sub);
inspect(sub, r);
}
}
}
}
}
}



I tried to catch the DanglingHREFException (which is inside an IOWrappedException). Unfortunately the exception does not contain a reference to the dangling eobject so I can not inspect it...

Federico
--
website: http://www.federico-tomassetti.it


Previous Topic:(no subject)
Next Topic:Re: [Teneo] MySQL does not create new tables on init
Goto Forum:
  


Current Time: Thu Sep 19 23:06:08 GMT 2019

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

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

Back to the top