protected virtual ConstraintBindingSet[] CloneConstraintBindingSet(EiffelStructures.table.HASH_TABLE_REFERENCE_REFERENCE o)
        {
            ConstraintBindingSet[] result = null;

            if (o != null && o.count() > 0)
            {
                result = new ConstraintBindingSet[o.count()];
                o.start();

                for (int i = 1; i <= result.Length; i++)
                {
                    ConstraintBindingSet constraintBindingSet = new ConstraintBindingSet();
                    constraintBindingSet.terminology = o.key_for_iteration().ToString();
                    EiffelStructures.table.Impl.HASH_TABLE_REFERENCE_REFERENCE adlTerms = o.item_for_iteration() as EiffelStructures.table.Impl.HASH_TABLE_REFERENCE_REFERENCE;
                    CONSTRAINT_BINDING_ITEM[] localTerms = new CONSTRAINT_BINDING_ITEM[adlTerms.count()];
                    adlTerms.start();

                    for (int j = 1; j <= adlTerms.count(); j++)
                    {
                        openehr.common_libs.basic.Impl.URI term = adlTerms.item_for_iteration() as openehr.common_libs.basic.Impl.URI;
                        CONSTRAINT_BINDING_ITEM localTerm = new CONSTRAINT_BINDING_ITEM();
                        localTerm.code = adlTerms.key_for_iteration().ToString();
                        localTerm.value = adlTerms.item_for_iteration().ToString();
                        localTerms[j - 1] = localTerm;
                        adlTerms.forth();
                    }

                    constraintBindingSet.items = localTerms;
                    result[i - 1] = constraintBindingSet;
                    o.forth();
                }
            }

            return result;
        }
        protected virtual CodeDefinitionSet[] CloneCodeDefinitions(EiffelStructures.table.HASH_TABLE_REFERENCE_REFERENCE o)
        {
            CodeDefinitionSet[] result = null;

            if (o != null)
            {
                result = new CodeDefinitionSet[o.count()];
                o.start();

                for (int i = 1; i <= result.Length; i++)
                {
                    CodeDefinitionSet codeDefinitionSet = new CodeDefinitionSet();
                    codeDefinitionSet.language = o.key_for_iteration().ToString();
                    EiffelStructures.table.Impl.HASH_TABLE_REFERENCE_REFERENCE adlTerms = o.item_for_iteration() as EiffelStructures.table.Impl.HASH_TABLE_REFERENCE_REFERENCE;
                    SortedList<string, ARCHETYPE_TERM> localTerms = new SortedList<string, ARCHETYPE_TERM>();
                    adlTerms.start();

                    for (int j = 1; j <= adlTerms.count(); j++)
                    {
                        openehr.openehr.am.archetype.ontology.Impl.ARCHETYPE_TERM term = adlTerms.item_for_iteration() as openehr.openehr.am.archetype.ontology.Impl.ARCHETYPE_TERM;
                        ARCHETYPE_TERM localTerm = new ARCHETYPE_TERM();
                        localTerm.code = term.code().ToString();
                        localTerm.items = CloneHashTableAny(term.items());
                        localTerms.Add(localTerm.code, localTerm);
                        adlTerms.forth();
                    }

                    codeDefinitionSet.items = new ARCHETYPE_TERM[localTerms.Count];
                    localTerms.Values.CopyTo(codeDefinitionSet.items, 0);
                    CleanUpCodeDefinitionSet(codeDefinitionSet);
                    result[i - 1] = codeDefinitionSet;
                    o.forth();
                }
            }

            return result;
        }
        protected virtual ASSERTION[] CloneAssertion(EiffelStructures.list.ARRAYED_LIST_REFERENCE adlList)
        {
            ASSERTION[] result = null;

            if (adlList != null)
            {
                result = new ASSERTION[adlList.count()];

                for (int i = 1; i <= adlList.count(); i++)
                {
                    openehr.openehr.am.archetype.assertion.ASSERTION assert = adlList.i_th(i) as openehr.openehr.am.archetype.assertion.ASSERTION;
                    ASSERTION localAssertion = new ASSERTION();

                    if (assert.tag() != null)
                        localAssertion.tag = assert.tag().ToString();

                    // 0..1 string_expression string
                    //localAssertion.string_expression  (not implemented in adl object)

                    if (assert.expression() != null)
                        localAssertion.expression = CloneExprItem(assert.expression());

                    // 0..* variables ASSERTION_VARIABLE (not implememented in adl object)                            

                    result[i - 1] = localAssertion;
                }
            }

            return result;
        }
        protected virtual TermBindingSet[] CloneTermBindingSet(EiffelStructures.table.HASH_TABLE_REFERENCE_REFERENCE o)
        {
            TermBindingSet[] result = null;

            if (o != null && o.count() > 0)
            {
                result = new TermBindingSet[o.count()];
                o.start();

                for (int i = 1; i <= o.count(); i++)
                {
                    TermBindingSet termBindingSet = new TermBindingSet();
                    termBindingSet.terminology = o.key_for_iteration().ToString();

                    EiffelStructures.table.Impl.HASH_TABLE_REFERENCE_REFERENCE adlTerms = o.item_for_iteration() as EiffelStructures.table.Impl.HASH_TABLE_REFERENCE_REFERENCE;
                    SortedList<string, TERM_BINDING_ITEM> localTerms = new SortedList<string, TERM_BINDING_ITEM>();
                    adlTerms.start();

                    for (int j = 1; j <= adlTerms.count(); j++)
                    {
                        openehr.openehr.rm.data_types.text.CODE_PHRASE term = adlTerms.item_for_iteration() as openehr.openehr.rm.data_types.text.CODE_PHRASE;

                        if (term != null)
                        {
                            TERM_BINDING_ITEM localTerm = new TERM_BINDING_ITEM();
                            localTerm.code = adlTerms.key_for_iteration().ToString();
                            CODE_PHRASE codePhrase = new CODE_PHRASE();
                            codePhrase.code_string = term.code_string().ToString();

                            if (term.code_string() != null)
                            {
                                TERMINOLOGY_ID terminologyId = new TERMINOLOGY_ID();
                                terminologyId.value = term.terminology_id().value().ToString();
                                codePhrase.terminology_id = terminologyId;
                            }

                            localTerm.value = codePhrase;
                            localTerms.Add(localTerm.code, localTerm);
                        }

                        adlTerms.forth();
                    }

                    termBindingSet.items = new TERM_BINDING_ITEM[localTerms.Count];
                    localTerms.Values.CopyTo(termBindingSet.items, 0);
                    result[i - 1] = termBindingSet;
                    o.forth();
                }
            }

            return result;
        }
        protected virtual StringDictionaryItem[] CloneHashTableAny(EiffelStructures.table.HASH_TABLE_REFERENCE_REFERENCE o)
        {
            StringDictionaryItem[] result = null;

            if (o != null && o.count() > 0)
            {
                SortedList<string, StringDictionaryItem> dictionaryItem = new SortedList<string, StringDictionaryItem>();
                o.start();

                while (!o.off())
                {
                    StringDictionaryItem item = new StringDictionaryItem();
                    item.id = o.key_for_iteration().ToString();
                    item.Value = o.item_for_iteration().ToString();
                    dictionaryItem.Add(item.id, item);
                    o.forth();
                }

                result = new StringDictionaryItem[dictionaryItem.Count];
                dictionaryItem.Values.CopyTo(result, 0);
            }

            return result;
        }