Mattias Forss wrote: > Hello, > > I have some questions about the archetype definition. Currently, I am > using the java parser to get an archetype object and from that object > I get the archetype definition, which is a CComplexObject. I then pass > this object to a recursive function of mine to get hold of some node > id's, reference model type names, reference model attribute names and > so on. In the function I first get the attributes of the complex > object, then I get the children of each attribute and finally I also > get some of the children's actual values in the case they > aren't complex objects that have to be passed to the function again.
> > Sadly, I haven't found another way to get the children's actual > values, than doing a lot of type casting, i.e. to get the value of an > object of the type DvBoolean I first have to check if the child is a > CPrimitiveObject to get the CPrimitive and then I have to check if the > CPrimitive is a CBoolean to get the DvBoolean and finally I can get > the actual value of the boolean. I think this is rather tedious, and I > would be glad if anyone knows an easier way to do this. In general, you should never have to do this in an object-oriented system - that's what polymorphism is about. See the function "is_valid" in the ARCHETYPE_CONSTRAINT class at http://my.openehr.org/wsvn/ref_impl_eiffel/TRUNK/libraries/openehr/src/am/archetype/constraint_model/archetype_constraint.e?op=file&rev=0&sc=0 as an example. A quite powerful use of this approach is to in the pattern I used in the Eiffel implementation to do serialisation, which is to use an iterator which goes through every node in the structure, and it calls each item's serialiser function, whatever that might be. See the iterator at: http://my.openehr.org/wsvn/ref_impl_eiffel/TRUNK/libraries/common_libs/src/structures/object_graph/og_iterator.e?op=file&rev=0&sc=0 The class SERIALISABLE http://my.openehr.org/wsvn/ref_impl_eiffel/TRUNK/libraries/common_libs/src/structures/syntax/serialiser/serialisable.e?op=file&rev=0&sc=0 is inherited by all of the C_ATTRIBUTE, C_OBJECT classes (see e.g. 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). The iterator then is able to go through a tree of objects, and call the relevant serialiser functions. If you are not afraid of Eiffel, you can download all the Eiffel software from the subversion repository, and the IDE from eiffel.com, for free, and look properly at the software construction. See http://svn.openehr.org/ref_impl_eiffel/TRUNK/project_page.htm for details. > > In the recursive function I've just described I also try to build a > tree structure of the java type DefaultMutableTreeNode in order to to > display the archetype definition in a swing object called JTree. I > have almost got it right, but I have problems with the levels of the > nodes because I cannot simply do recursion over the CComplexObject > that represents the definition since I have to get its attributes and > the attributes' children (e.g. to see if the children are another > CComplexObject), and thus this gets complicated and the assembled > final tree is somewhat messed up. I would be glad if anybody had any > ideas or advice about this problem and I hope my questions aren't too > stupid. don't worry they're not. The problem you are grappling here is quite a general one to do with trees which are alternating object/attribute trees, rather than just trees of one kind of node. These object/attribute trees turn up in many places, including object databases, XML processors and so on. They are the reason I wrote a whole library called Object Graph, at http://my.openehr.org/wsvn/ref_impl_eiffel/TRUNK/libraries/common_libs/src/structures/object_graph/?rev=0&sc=0 All the structures such as C_OBJECT/C_ATTRIBUTE structures all have OG_OBJECT or OG_ATTRIBUTE_NODE behind them. It may seem comnplex, but it is what is needed to make this kind of object/attribute stucture processing work. The nice thing is, it can be re-used for the C_* structures, for dADL data structures, for XML structures and many others. hope this helps. - thomas beale > > Regards, > > Mattias Forss (MSc student) > > Medical Informatics group at the Department of Biomedical Engineering > Link?pings universitet, Sweden -- ___________________________________________________________________________________ CTO Ocean Informatics (http://www.OceanInformatics.biz) Research Fellow, University College London (http://www.chime.ucl.ac.uk) Chair Architectural Review Board, openEHR (http://www.openEHR.org) - If you have any questions about using this list, please send a message to d.lloyd at openehr.org

