# Bug in RM builder? (getParent) + Incomplete Common IM spec?

**URL:** https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618
**Category:** Reference Implementation: Java (archive)
**Created:** [18 January 2007 16:52 UTC](https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618 "2007-01-18T16:52:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![erik.sundvall](https://discourse.openehr.org/user_avatar/discourse.openehr.org/erik.sundvall/32/1961_2.png) [@erik.sundvall](https://discourse.openehr.org/u/erik.sundvall)
#### Post date: [18 January 2007 16:52 UTC](https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618/1 "2007-01-18T16:52:45Z")

</div>

Hi Rong! (+Tom)

Mattias mentioned that the two of you (MF+RC) had chatted about the  
issue that the parent is set null instead of the real parent in the  
AOM by the parser. I now had a look at the RMObjectBuilder and found a  
similar issue. Is it not so that RM objects that inherit from  
Locatable should know (have a reference to or be able to look up)  
their parent if they have one (i.e all non root objects)?

A question to Tom:  
Why is parent optional (0..1) in the spec, is it only because root  
nodes don't have parents or is it because parent can be ignored by  
implementations? Maybe some text and possibly an invariant statement  
in the spec could make this more clear?

I guess the RMObjectBuilder should be the right place to attach  
children and parents?

If you add the two code lines below to the end of the method  
testBuildComposition() in the unit test class  
org.openehr.build.EHRBuildTest you will find the error by the last  
test.

&nbsp;&nbsp;assertEquals("section", section(), composition.getContent().get(0));  
//passes fine  
&nbsp;&nbsp;assertEquals("parent", composition,  
composition.getContent().get(0).getParent()); //fails

I might have misunderstood things here, but I guess that one in  
addition to constructors has to use the protected setter setParent()  
(inherited from Locatable) during the build process.

This also brings me to the question if the current java-ref-impl  
implementation strives for strong or weak immutability?

See strong/weak differences here:  
[http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html](http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html)  
(continues)  
[http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html?page=2](http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html?page=2)  
and  
[http://www.javaranch.com/newsletter/Apr2003/immutable.htm](http://www.javaranch.com/newsletter/Apr2003/immutable.htm) (middle of page)

The reason I ask is that we are experimenting with mutable/immutable  
class pairs and converters.

Best regards,  
Erik Sundvall  
[http://www.imt.liu.se/~erisu/](http://www.imt.liu.se/~erisu/)

---

<div class="post-metadata">

### Author: ![thomas.beale](https://discourse.openehr.org/user_avatar/discourse.openehr.org/thomas.beale/32/35_2.png) [@thomas.beale](https://discourse.openehr.org/u/thomas.beale)
#### Post date: [18 January 2007 17:14 UTC](https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618/2 "2007-01-18T17:14:04Z")

</div>

Erik Sundvall wrote:

> Hi Rong! (+Tom)
> 
> Mattias mentioned that the two of you (MF+RC) had chatted about the  
> issue that the parent is set null instead of the real parent in the  
> AOM by the parser. I now had a look at the RMObjectBuilder and found a  
> similar issue. Is it not so that RM objects that inherit from  
> Locatable should know (have a reference to or be able to look up)  
> their parent if they have one (i.e all non root objects)?
> 
> A question to Tom:  
> Why is parent optional (0..1) in the spec, is it only because root  
> nodes don't have parents or is it because parent can be ignored by  
> &nbsp;&nbsp;

it's mainly because of the reason being discussed elsewhere - it cannot  
usually be sensibly supplied on creation.

> implementations? Maybe some text and possibly an invariant statement  
> in the spec could make this more clear?  
> &nbsp;&nbsp;

- thomas

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [19 January 2007 09:22 UTC](https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618/3 "2007-01-19T09:22:48Z")

</div>

> Hi Rong! (+Tom)
> 
> Mattias mentioned that the two of you (MF+RC) had chatted about the  
> issue that the parent is set null instead of the real parent in the

Yes, now I think I will go for no “parent” in the constructor + addChild() solution (thanks for the tip, Tom).

> AOM by the parser. I now had a look at the RMObjectBuilder and found a  
> similar issue. Is it not so that RM objects that inherit from  
> Locatable should know (have a reference to or be able to look up)  
> their parent if they have one (i.e all non root objects)?
> 
> A question to Tom:  
> Why is parent optional (0..1) in the spec, is it only because root  
> nodes don’t have parents or is it because parent can be ignored by  
> implementations? Maybe some text and possibly an invariant statement  
> in the spec could make this more clear?
> 
> I guess the RMObjectBuilder should be the right place to attach  
> children and parents?

> If you add the two code lines below to the end of the method  
> testBuildComposition() in the unit test class  
> org.openehr.build.EHRBuildTest you will find the error by the last  
> test.
> 
> assertEquals(“section”, section(), composition.getContent().get(0));  
> //passes fine  
> assertEquals(“parent”, composition,  
> composition.getContent().get(0).getParent()); //fails

Thanks for reporting this. It will be on the to-do list.

Right now, updating the AOM and the parser; the work on rm-builder will start later preferably with input on common kernel API.

> I might have misunderstood things here, but I guess that one in  
> addition to constructors has to use the protected setter setParent()  
> (inherited from Locatable) during the build process.
> 
> This also brings me to the question if the current java-ref-impl  
> implementation strives for strong or weak immutability?

For RM/AOM, both I guess depends on the context.

> See strong/weak differences here:  
> [http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html](http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html)  
> (continues)  
> [http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html?page=2](http://www.javaworld.com/javaworld/javaqa/2002-12/01-qa-1206-immutable.html?page=2)  
> and  
> [http://www.javaranch.com/newsletter/Apr2003/immutable.htm](http://www.javaranch.com/newsletter/Apr2003/immutable.htm) (middle of page)
> 
> The reason I ask is that we are experimenting with mutable/immutable  
> class pairs and converters.

Look forward to your result on this. 🙂

/Rong

---

<div class="post-metadata">

### Author: ![erik.sundvall](https://discourse.openehr.org/user_avatar/discourse.openehr.org/erik.sundvall/32/1961_2.png) [@erik.sundvall](https://discourse.openehr.org/u/erik.sundvall)
#### Post date: [19 January 2007 13:49 UTC](https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618/4 "2007-01-19T13:49:18Z")

</div>

Could you (Tom or Rong) explain this (the content of addChild etc)  
further or point to some explaining text on the net?

Best regards,  
Erik Sundvall  
[http://www.imt.liu.se/~erisu/](http://www.imt.liu.se/~erisu/)

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [20 January 2007 20:20 UTC](https://discourse.openehr.org/t/bug-in-rm-builder-getparent-incomplete-common-im-spec/14618/5 "2007-01-20T20:20:09Z")

</div>

Check this out  
[http://my.openehr.org/wsvn/ref\_impl\_eiffel/TRUNK/libraries/openehr/src/am/archetype/constraint\_model/c\_attribute.e?op=file&rev=0&sc=0](http://my.openehr.org/wsvn/ref_impl_eiffel/TRUNK/libraries/openehr/src/am/archetype/constraint_model/c_attribute.e?op=file&rev=0&sc=0)

/Rong
