# Path: xtuml/meta.py
# def navigate_any(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
# 
#     The resulting query will return an instance or None.
#     '''
#     return NavOneChain(instance_or_set)
# 
# Path: xtuml/meta.py
# def navigate_any(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
# 
#     The resulting query will return an instance or None.
#     '''
#     return NavOneChain(instance_or_set)
# 
# Path: xtuml/meta.py
# def navigate_many(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
#     
#     The resulting query will return a set of instances.
#     '''
#     return NavChain(instance_or_set)
# 
# Path: bridgepoint/ooaofooa.py
# class OoaOfOoaException(Exception):
# class Domain(xtuml.MetaModel):
# class ModelLoader(xtuml.ModelLoader):
#     def __init__(self, id_generator=None):
#     def add_symbol(self, name, handle):
#     def find_symbol(self, name):
# def is_contained_in(pe_pe, root):
# def is_global(pe_pe):
# def get_defining_component(pe_pe):
# def get_attribute_type(o_attr):
# def _get_data_type_name(s_dt):
# def _get_related_attributes(r_rgo, r_rto):
# def mk_enum(s_edt):
# def mk_bridge(metamodel, s_brg):
# def mk_external_entity(metamodel, s_ee):
# def mk_function(metamodel, s_sync):
# def mk_constant(cnst_syc):
# def mk_operation(metaclass, o_tfr):
# def mk_derived_attribute(metaclass, o_dbattr):
# def mk_class(m, o_obj, derived_attributes=False):
# def mk_simple_association(m, r_simp):
# def mk_linked_association(m, r_assoc):
#     def _mk_assoc(side1, side2):
# def mk_subsuper_association(m, r_subsup):
# def mk_derived_association(m, r_comp):
# def mk_association(m, r_rel):
# def mk_component(bp_model, c_c=None, derived_attributes=False):
#     def __init__(self, load_globals=True):
#     def filename_input(self, path_or_filename):
#     def build_component(self, name=None, derived_attributes=False):
# def _mk_loader(resource, load_globals):
# def load_metamodel(resource=None, load_globals=True):
# def load_component(resource, name=None, load_globals=True):
# def delete_globals(m, disconnect=False):
#     EE = collections.namedtuple(s_ee.Key_Lett, names)


import sys
import optparse
import logging
import xtuml
import xml.etree.ElementTree as ET
import xml.dom.minidom
from xtuml import navigate_any as nav_any
from xtuml import navigate_any as nav_one
from xtuml import navigate_many as nav_many
from bridgepoint import ooaofooa

def build_type(s_dt):
    '''
    Build a partial xsd tree out of a S_DT and its sub types S_CDT, S_EDT, S_SDT and S_UDT.
    '''
    s_cdt = nav_one(s_dt).S_CDT[17]()
    if s_cdt:
        return build_core_type(s_cdt)
    
    s_edt = nav_one(s_dt).S_EDT[17]()
    if s_edt:
        return build_enum_type(s_edt)
    
    s_udt = nav_one(s_dt).S_UDT[17]()
    if s_udt:
        return build_user_type(s_udt)
    
#    s_sdt = nav_one(s_dt).S_SDT[17]()
#    if s_sdt:
#        return build_struct_type(s_sdt)


def build_class(o_obj):
    '''
    Build an xsd complex element out of a O_OBJ, including its O_ATTR.
    '''
    cls = ET.Element('xs:element', name=o_obj.key_lett, minOccurs='0', maxOccurs='unbounded')
    attributes = ET.SubElement(cls, 'xs:complexType')
    for o_attr in nav_many(o_obj).O_ATTR[102]():
        o_attr_ref = get_refered_attribute(o_attr)

# Path: xtuml/meta.py
# def navigate_any(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
# 
#     The resulting query will return an instance or None.
#     '''
#     return NavOneChain(instance_or_set)
# 
# Path: xtuml/meta.py
# def navigate_any(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
# 
#     The resulting query will return an instance or None.
#     '''
#     return NavOneChain(instance_or_set)
# 
# Path: xtuml/meta.py
# def navigate_many(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
#     
#     The resulting query will return a set of instances.
#     '''
#     return NavChain(instance_or_set)
# 
# Path: bridgepoint/ooaofooa.py
# class OoaOfOoaException(Exception):
# class Domain(xtuml.MetaModel):
# class ModelLoader(xtuml.ModelLoader):
#     def __init__(self, id_generator=None):
#     def add_symbol(self, name, handle):
#     def find_symbol(self, name):
# def is_contained_in(pe_pe, root):
# def is_global(pe_pe):
# def get_defining_component(pe_pe):
# def get_attribute_type(o_attr):
# def _get_data_type_name(s_dt):
# def _get_related_attributes(r_rgo, r_rto):
# def mk_enum(s_edt):
# def mk_bridge(metamodel, s_brg):
# def mk_external_entity(metamodel, s_ee):
# def mk_function(metamodel, s_sync):
# def mk_constant(cnst_syc):
# def mk_operation(metaclass, o_tfr):
# def mk_derived_attribute(metaclass, o_dbattr):
# def mk_class(m, o_obj, derived_attributes=False):
# def mk_simple_association(m, r_simp):
# def mk_linked_association(m, r_assoc):
#     def _mk_assoc(side1, side2):
# def mk_subsuper_association(m, r_subsup):
# def mk_derived_association(m, r_comp):
# def mk_association(m, r_rel):
# def mk_component(bp_model, c_c=None, derived_attributes=False):
#     def __init__(self, load_globals=True):
#     def filename_input(self, path_or_filename):
#     def build_component(self, name=None, derived_attributes=False):
# def _mk_loader(resource, load_globals):
# def load_metamodel(resource=None, load_globals=True):
# def load_component(resource, name=None, load_globals=True):
# def delete_globals(m, disconnect=False):
#     EE = collections.namedtuple(s_ee.Key_Lett, names)


# Path: bridgepoint/gen_xsd_schema.py
import sys
import optparse
import logging
import xtuml
import xml.etree.ElementTree as ET
import xml.dom.minidom
from xtuml import navigate_any as nav_any
from xtuml import navigate_any as nav_one
from xtuml import navigate_many as nav_many
from bridgepoint import ooaofooa


def build_type(s_dt):
    '''
    Build a partial xsd tree out of a S_DT and its sub types S_CDT, S_EDT, S_SDT and S_UDT.
    '''
    s_cdt = nav_one(s_dt).S_CDT[17]()
    if s_cdt:
        return build_core_type(s_cdt)
    
    s_edt = nav_one(s_dt).S_EDT[17]()
    if s_edt:
        return build_enum_type(s_edt)
    
    s_udt = nav_one(s_dt).S_UDT[17]()
    if s_udt:
        return build_user_type(s_udt)
    
#    s_sdt = nav_one(s_dt).S_SDT[17]()
#    if s_sdt:
#        return build_struct_type(s_sdt)


def build_class(o_obj):
    '''
    Build an xsd complex element out of a O_OBJ, including its O_ATTR.
    '''
    cls = ET.Element('xs:element', name=o_obj.key_lett, minOccurs='0', maxOccurs='unbounded')
    attributes = ET.SubElement(cls, 'xs:complexType')
    for o_attr in nav_many(o_obj).O_ATTR[102]():
        o_attr_ref = get_refered_attribute(o_attr)

        s_dt = nav_one(o_attr_ref).S_DT[114]()