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.
If you are just interested in assigned value, you don't need to cast the constraint. You can call assignedValue() of CPrimitive, which is implemented in all concrete primitive constraints, to get the value as Object (you would need to check if the value is null or not before you take the string presentation of it). But if you need to know more about the constraint, e.g. valid range, you have to deal with concrete classes since the details are different from one subclass to another. > > 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 There is similar recursive logic for object creation part in createObject() of CComplextObject and createAttribute() of CAttribute. Maybe you can find some inspiration for your problem. > 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. > > Regards, > > Mattias Forss (MSc student) > > Medical Informatics group at the Department of Biomedical Engineering > Link?pings universitet, Sweden - If you have any questions about using this list, please send a message to d.lloyd at openehr.org

