#!/usr/bin/env python
# -*- coding: utf-8 -*- 

#
# Generated Wed Nov 14 12:49:10 2012 by generateDS.py version 2.7c.
#

import sys
import getopt
import re as re_

import cybox.bindings.cybox_core_1_0 as cybox_core_binding
import stix.bindings.stix_common_0_2 as stix_common_binding
import cybox.bindings.cybox_common_types_1_0 as cybox_common_binding

etree_ = None
Verbose_import_ = False
(   XMLParser_import_none, XMLParser_import_lxml,
    XMLParser_import_elementtree
    ) = range(3)
XMLParser_import_library = None
try:
    # lxml
    from lxml import etree as etree_
    XMLParser_import_library = XMLParser_import_lxml
    if Verbose_import_:
        print("running with lxml.etree")
except ImportError:
    try:
        # cElementTree from Python 2.5+
        import xml.etree.cElementTree as etree_
        XMLParser_import_library = XMLParser_import_elementtree
        if Verbose_import_:
            print("running with cElementTree on Python 2.5+")
    except ImportError:
        try:
            # ElementTree from Python 2.5+
            import xml.etree.ElementTree as etree_
            XMLParser_import_library = XMLParser_import_elementtree
            if Verbose_import_:
                print("running with ElementTree on Python 2.5+")
        except ImportError:
            try:
                # normal cElementTree install
                import cElementTree as etree_
                XMLParser_import_library = XMLParser_import_elementtree
                if Verbose_import_:
                    print("running with cElementTree")
            except ImportError:
                try:
                    # normal ElementTree install
                    import elementtree.ElementTree as etree_
                    XMLParser_import_library = XMLParser_import_elementtree
                    if Verbose_import_:
                        print("running with ElementTree")
                except ImportError:
                    raise ImportError("Failed to import ElementTree from any known place")

def parsexml_(*args, **kwargs):
    if (XMLParser_import_library == XMLParser_import_lxml and
        'parser' not in kwargs):
        # Use the lxml ElementTree compatible parser so that, e.g.,
        #   we ignore comments.
        kwargs['parser'] = etree_.ETCompatXMLParser()
    doc = etree_.parse(*args, **kwargs)
    return doc

#
# User methods
#
# Calls to the methods in these classes are generated by generateDS.py.
# You can replace these methods by re-implementing the following class
#   in a module named generatedssuper.py.

try:
    from generatedssuper import GeneratedsSuper
except ImportError, exp:

    class GeneratedsSuper(object):
        def gds_format_string(self, input_data, input_name=''):
            return input_data
        def gds_validate_string(self, input_data, node, input_name=''):
            return input_data
        def gds_format_integer(self, input_data, input_name=''):
            return '%d' % input_data
        def gds_validate_integer(self, input_data, node, input_name=''):
            return input_data
        def gds_format_integer_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_integer_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    fvalue = float(value)
                except (TypeError, ValueError), exp:
                    raise_parse_error(node, 'Requires sequence of integers')
            return input_data
        def gds_format_float(self, input_data, input_name=''):
            return '%f' % input_data
        def gds_validate_float(self, input_data, node, input_name=''):
            return input_data
        def gds_format_float_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_float_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    fvalue = float(value)
                except (TypeError, ValueError), exp:
                    raise_parse_error(node, 'Requires sequence of floats')
            return input_data
        def gds_format_double(self, input_data, input_name=''):
            return '%e' % input_data
        def gds_validate_double(self, input_data, node, input_name=''):
            return input_data
        def gds_format_double_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_double_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    fvalue = float(value)
                except (TypeError, ValueError), exp:
                    raise_parse_error(node, 'Requires sequence of doubles')
            return input_data
        def gds_format_boolean(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_boolean(self, input_data, node, input_name=''):
            return input_data
        def gds_format_boolean_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_boolean_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                if value not in ('true', '1', 'false', '0', ):
                    raise_parse_error(node, 'Requires sequence of booleans ("true", "1", "false", "0")')
            return input_data
        def gds_str_lower(self, instring):
            return instring.lower()
        def get_path_(self, node):
            path_list = []
            self.get_path_list_(node, path_list)
            path_list.reverse()
            path = '/'.join(path_list)
            return path
        Tag_strip_pattern_ = re_.compile(r'\{.*\}')
        def get_path_list_(self, node, path_list):
            if node is None:
                return
            tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag)
            if tag:
                path_list.append(tag)
            self.get_path_list_(node.getparent(), path_list)
        def get_class_obj_(self, node, default_class=None):
            class_obj1 = default_class
            if 'xsi' in node.nsmap:
                classname = node.get('{%s}type' % node.nsmap['xsi'])
                if classname is not None:
                    names = classname.split(':')
                    if len(names) == 2:
                        classname = names[1]
                    class_obj2 = globals().get(classname)
                    if class_obj2 is not None:
                        class_obj1 = class_obj2
            return class_obj1
        def gds_build_any(self, node, type_name=None):
            return None


#
# If you have installed IPython you can uncomment and use the following.
# IPython is available from http://ipython.scipy.org/.
#

## from IPython.Shell import IPShellEmbed
## args = ''
## ipshell = IPShellEmbed(args,
##     banner = 'Dropping into IPython',
##     exit_msg = 'Leaving Interpreter, back to program.')

# Then use the following line where and when you want to drop into the
# IPython shell:
#    ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')

#
# Globals
#

ExternalEncoding = 'ascii'
Tag_pattern_ = re_.compile(r'({.*})?(.*)')
String_cleanup_pat_ = re_.compile(r"[\n\r\s]+")
Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)')

#
# Support/utility functions.
#

def showIndent(outfile, level, pretty_print=True):
    if pretty_print:
        for idx in range(level):
            outfile.write('    ')

def quote_xml(inStr):
    if not inStr:
        return ''
    s1 = (isinstance(inStr, basestring) and inStr or
          '%s' % inStr)
    s1 = s1.replace('&', '&amp;')
    s1 = s1.replace('<', '&lt;')
    s1 = s1.replace('>', '&gt;')
    return s1

def quote_attrib(inStr):
    s1 = (isinstance(inStr, basestring) and inStr or
          '%s' % inStr)
    s1 = s1.replace('&', '&amp;')
    s1 = s1.replace('<', '&lt;')
    s1 = s1.replace('>', '&gt;')
    if '"' in s1:
        if "'" in s1:
            s1 = '"%s"' % s1.replace('"', "&quot;")
        else:
            s1 = "'%s'" % s1
    else:
        s1 = '"%s"' % s1
    return s1

def quote_python(inStr):
    s1 = inStr
    if s1.find("'") == -1:
        if s1.find('\n') == -1:
            return "'%s'" % s1
        else:
            return "'''%s'''" % s1
    else:
        if s1.find('"') != -1:
            s1 = s1.replace('"', '\\"')
        if s1.find('\n') == -1:
            return '"%s"' % s1
        else:
            return '"""%s"""' % s1

def get_all_text_(node):
    if node.text is not None:
        text = node.text
    else:
        text = ''
    for child in node:
        if child.tail is not None:
            text += child.tail
    return text

def find_attr_value_(attr_name, node):
    attrs = node.attrib
    attr_parts = attr_name.split(':')
    value = None
    if len(attr_parts) == 1:
        value = attrs.get(attr_name)
    elif len(attr_parts) == 2:
        prefix, name = attr_parts
        namespace = node.nsmap.get(prefix)
        if namespace is not None:
            value = attrs.get('{%s}%s' % (namespace, name, ))
    return value


class GDSParseError(Exception):
    pass

def raise_parse_error(node, msg):
    if XMLParser_import_library == XMLParser_import_lxml:
        msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, )
    else:
        msg = '%s (element %s)' % (msg, node.tag, )
    raise GDSParseError(msg)


class MixedContainer:
    # Constants for category:
    CategoryNone = 0
    CategoryText = 1
    CategorySimple = 2
    CategoryComplex = 3
    # Constants for content_type:
    TypeNone = 0
    TypeText = 1
    TypeString = 2
    TypeInteger = 3
    TypeFloat = 4
    TypeDecimal = 5
    TypeDouble = 6
    TypeBoolean = 7
    def __init__(self, category, content_type, name, value):
        self.category = category
        self.content_type = content_type
        self.name = name
        self.value = value
    def getCategory(self):
        return self.category
    def getContenttype(self, content_type):
        return self.content_type
    def getValue(self):
        return self.value
    def getName(self):
        return self.name
    def export(self, outfile, level, name, namespace, pretty_print=True):
        if self.category == MixedContainer.CategoryText:
            # Prevent exporting empty content as empty lines.
            if self.value.strip(): 
                outfile.write(self.value)
        elif self.category == MixedContainer.CategorySimple:
            self.exportSimple(outfile, level, name)
        else:    # category == MixedContainer.CategoryComplex
            self.value.export(outfile, level, namespace, name, pretty_print)
    def exportSimple(self, outfile, level, name):
        if self.content_type == MixedContainer.TypeString:
            outfile.write('<%s>%s</%s>' % (self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeInteger or \
                self.content_type == MixedContainer.TypeBoolean:
            outfile.write('<%s>%d</%s>' % (self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeFloat or \
                self.content_type == MixedContainer.TypeDecimal:
            outfile.write('<%s>%f</%s>' % (self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeDouble:
            outfile.write('<%s>%g</%s>' % (self.name, self.value, self.name))
    def exportLiteral(self, outfile, level, name):
        if self.category == MixedContainer.CategoryText:
            showIndent(outfile, level)
            outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \
                (self.category, self.content_type, self.name, self.value))
        elif self.category == MixedContainer.CategorySimple:
            showIndent(outfile, level)
            outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \
                (self.category, self.content_type, self.name, self.value))
        else:    # category == MixedContainer.CategoryComplex
            showIndent(outfile, level)
            outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \
                (self.category, self.content_type, self.name,))
            self.value.exportLiteral(outfile, level + 1)
            showIndent(outfile, level)
            outfile.write(')\n')


class MemberSpec_(object):
    def __init__(self, name='', data_type='', container=0):
        self.name = name
        self.data_type = data_type
        self.container = container
    def set_name(self, name): self.name = name
    def get_name(self): return self.name
    def set_data_type(self, data_type): self.data_type = data_type
    def get_data_type_chain(self): return self.data_type
    def get_data_type(self):
        if isinstance(self.data_type, list):
            if len(self.data_type) > 0:
                return self.data_type[-1]
            else:
                return 'xs:string'
        else:
            return self.data_type
    def set_container(self, container): self.container = container
    def get_container(self): return self.container

def _cast(typ, value):
    if typ is None or value is None:
        return value
    return typ(value)

#
# Data representation classes.
#

class ImpactType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, Description=None, ImpactConfidence=None):
        self.Description = Description
        self.ImpactConfidence = ImpactConfidence
    def factory(*args_, **kwargs_):
        if ImpactType.subclass:
            return ImpactType.subclass(*args_, **kwargs_)
        else:
            return ImpactType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Description(self): return self.Description
    def set_Description(self, Description): self.Description = Description
    def get_ImpactConfidence(self): return self.ImpactConfidence
    def set_ImpactConfidence(self, ImpactConfidence): self.ImpactConfidence = ImpactConfidence
    def export(self, outfile, level, namespace_='COA:', name_='ImpactType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = []
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='ImpactType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='COA:', name_='ImpactType'):
        pass
    def exportChildren(self, outfile, level, namespace_='COA:', name_='ImpactType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Description is not None:
            self.Description.export(outfile, level, namespace_, name_='Description', pretty_print=pretty_print)
        if self.ImpactConfidence is not None:
            self.ImpactConfidence.export(outfile, level, namespace_, name_='ImpactConfidence', pretty_print=pretty_print)
    def hasContent_(self):
        if (
            self.Description is not None or
            self.ImpactConfidence is not None
            ):
            return True
        else:
            return False
    def exportLiteral(self, outfile, level, name_='ImpactType'):
        level += 1
        self.exportLiteralAttributes(outfile, level, [], name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.Description is not None:
            showIndent(outfile, level)
            outfile.write('Description=model_.StructuredTextType(\n')
            self.Description.exportLiteral(outfile, level, name_='Description')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.ImpactConfidence is not None:
            showIndent(outfile, level)
            outfile.write('ImpactConfidence=model_.ConfidenceType(\n')
            self.ImpactConfidence.exportLiteral(outfile, level, name_='ImpactConfidence')
            showIndent(outfile, level)
            outfile.write('),\n')
    def build(self, node):
        self.buildAttributes(node, node.attrib, [])
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Description':
            obj_ = cybox_common_binding.StructuredTextType.factory()
            obj_.build(child_)
            self.set_Description(obj_)
        elif nodeName_ == 'ImpactConfidence':
            obj_ = stix_common_binding.ConfidenceType.factory()
            obj_.build(child_)
            self.set_ImpactConfidence(obj_)
# end class ImpactType


class CostType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, Description=None, CostConfidence=None):
        self.Description = Description
        self.CostConfidence = CostConfidence
    def factory(*args_, **kwargs_):
        if CostType.subclass:
            return CostType.subclass(*args_, **kwargs_)
        else:
            return CostType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Description(self): return self.Description
    def set_Description(self, Description): self.Description = Description
    def get_CostConfidence(self): return self.CostConfidence
    def set_CostConfidence(self, CostConfidence): self.CostConfidence = CostConfidence
    def export(self, outfile, level, namespace_='COA:', name_='CostType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = []
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='CostType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='COA:', name_='CostType'):
        pass
    def exportChildren(self, outfile, level, namespace_='COA:', name_='CostType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Description is not None:
            self.Description.export(outfile, level, namespace_, name_='Description', pretty_print=pretty_print)
        if self.CostConfidence is not None:
            self.CostConfidence.export(outfile, level, namespace_, name_='CostConfidence', pretty_print=pretty_print)
    def hasContent_(self):
        if (
            self.Description is not None or
            self.CostConfidence is not None
            ):
            return True
        else:
            return False
    def exportLiteral(self, outfile, level, name_='CostType'):
        level += 1
        self.exportLiteralAttributes(outfile, level, [], name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.Description is not None:
            showIndent(outfile, level)
            outfile.write('Description=model_.StructuredTextType(\n')
            self.Description.exportLiteral(outfile, level, name_='Description')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.CostConfidence is not None:
            showIndent(outfile, level)
            outfile.write('CostConfidence=model_.ConfidenceType(\n')
            self.CostConfidence.exportLiteral(outfile, level, name_='CostConfidence')
            showIndent(outfile, level)
            outfile.write('),\n')
    def build(self, node):
        self.buildAttributes(node, node.attrib, [])
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Description':
            obj_ = cybox_common_binding.StructuredTextType.factory()
            obj_.build(child_)
            self.set_Description(obj_)
        elif nodeName_ == 'CostConfidence':
            obj_ = stix_common_binding.ConfidenceType.factory()
            obj_.build(child_)
            self.set_CostConfidence(obj_)
# end class CostType


class EfficacyType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, Description=None, EfficacyConfidence=None):
        self.Description = Description
        self.EfficacyConfidence = EfficacyConfidence
    def factory(*args_, **kwargs_):
        if EfficacyType.subclass:
            return EfficacyType.subclass(*args_, **kwargs_)
        else:
            return EfficacyType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Description(self): return self.Description
    def set_Description(self, Description): self.Description = Description
    def get_EfficacyConfidence(self): return self.EfficacyConfidence
    def set_EfficacyConfidence(self, EfficacyConfidence): self.EfficacyConfidence = EfficacyConfidence
    def export(self, outfile, level, namespace_='COA:', name_='EfficacyType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = []
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='EfficacyType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='COA:', name_='EfficacyType'):
        pass
    def exportChildren(self, outfile, level, namespace_='COA:', name_='EfficacyType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Description is not None:
            self.Description.export(outfile, level, namespace_, name_='Description', pretty_print=pretty_print)
        if self.EfficacyConfidence is not None:
            self.EfficacyConfidence.export(outfile, level, namespace_, name_='EfficacyConfidence', pretty_print=pretty_print)
    def hasContent_(self):
        if (
            self.Description is not None or
            self.EfficacyConfidence is not None
            ):
            return True
        else:
            return False
    def exportLiteral(self, outfile, level, name_='EfficacyType'):
        level += 1
        self.exportLiteralAttributes(outfile, level, [], name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.Description is not None:
            showIndent(outfile, level)
            outfile.write('Description=model_.StructuredTextType(\n')
            self.Description.exportLiteral(outfile, level, name_='Description')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.EfficacyConfidence is not None:
            showIndent(outfile, level)
            outfile.write('EfficacyConfidence=model_.ConfidenceType(\n')
            self.EfficacyConfidence.exportLiteral(outfile, level, name_='EfficacyConfidence')
            showIndent(outfile, level)
            outfile.write('),\n')
    def build(self, node):
        self.buildAttributes(node, node.attrib, [])
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Description':
            obj_ = cybox_common_binding.StructuredTextType.factory()
            obj_.build(child_)
            self.set_Description(obj_)
        elif nodeName_ == 'EfficacyConfidence':
            obj_ = stix_common_binding.ConfidenceType.factory()
            obj_.build(child_)
            self.set_EfficacyConfidence(obj_)
# end class EfficacyType



class COAType(GeneratedsSuper):
    """The CourseOfActionType characterizes a Course of Action to be taken
    in regards to one of more cyber threats. NOTE: This is an
    initial, rough draft for a schematic implementation for this
    construct and will require a good deal of review and
    refinement.Specifies a globally unique identifier for this COA.
    Specifies a globally unique identifier of a COA specified
    elsewhere.Specifies the relevant STIX-COA schema version for
    this content."""
    subclass = None
    superclass = None
    def __init__(self, idref=None, id=None, version=None, Stage=None, Type=None, Description=None, Objective=None, StructuredCOA=None, Impact=None, Cost=None, Efficacy=None):
        self.idref = _cast(None, idref)
        self.id = _cast(None, id)
        self.version = _cast(None, version)
        self.Stage = Stage
        self.Type = Type
        self.Description = Description
        self.Objective = Objective
        self.StructuredCOA = StructuredCOA
        self.Impact = Impact
        self.Cost = Cost
        self.Efficacy = Efficacy
    def factory(*args_, **kwargs_):
        if COAType.subclass:
            return COAType.subclass(*args_, **kwargs_)
        else:
            return COAType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Stage(self): return self.Stage
    def set_Stage(self, Stage): self.Stage = Stage
    def get_Type(self): return self.Type
    def set_Type(self, Type): self.Type = Type
    def get_Description(self): return self.Description
    def set_Description(self, Description): self.Description = Description
    def get_Objective(self): return self.Objective
    def set_Objective(self, Objective): self.Objective = Objective
    def get_StructuredCOA(self): return self.StructuredCOA
    def set_StructuredCOA(self, StructuredCOA): self.StructuredCOA = StructuredCOA
    def get_Impact(self): return self.Impact
    def set_Impact(self, Impact): self.Impact = Impact
    def get_Cost(self): return self.Cost
    def set_Cost(self, Cost): self.Cost = Cost
    def get_Efficacy(self): return self.Efficacy
    def set_Efficacy(self, Efficacy): self.Efficacy = Efficacy
    def get_idref(self): return self.idref
    def set_idref(self, idref): self.idref = idref
    def get_id(self): return self.id
    def set_id(self, id): self.id = id
    def get_version(self): return self.version
    def set_version(self, version): self.version = version
    def export(self, outfile, level, namespace_='COA:', name_='COAType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = []
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='COAType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='COA:', name_='COAType'):
        if self.idref is not None and 'idref' not in already_processed:
            already_processed.append('idref')
            outfile.write(' idref=%s' % (quote_attrib(self.idref), ))
        if self.id is not None and 'id' not in already_processed:
            already_processed.append('id')
            outfile.write(' id=%s' % (quote_attrib(self.id), ))
        if self.version is not None and 'version' not in already_processed:
            already_processed.append('version')
            outfile.write(' version=%s' % (self.gds_format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))
    def exportChildren(self, outfile, level, namespace_='COA:', name_='COAType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Stage is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sStage>%s</%sStage>%s' % ('COA:', self.gds_format_string(quote_xml(self.Stage).encode(ExternalEncoding), input_name='Stage'), 'COA:', eol_))
        if self.Type is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sType>%s</%sType>%s' % ('COA:', self.gds_format_string(quote_xml(self.Type).encode(ExternalEncoding), input_name='Type'), 'COA:', eol_))
        if self.Description is not None:
            self.Description.export(outfile, level, 'COA:', name_='Description', pretty_print=pretty_print)
        if self.Objective is not None:
            self.Objective.export(outfile, level, 'COA:', name_='Objective', pretty_print=pretty_print)
        if self.StructuredCOA is not None:
            self.StructuredCOA.export(outfile, level, 'COA:', name_='StructuredCOA', pretty_print=pretty_print)
        if self.Impact is not None:
            self.Impact.export(outfile, level, 'COA:', name_='Impact', pretty_print=pretty_print)
        if self.Cost is not None:
            self.Cost.export(outfile, level, 'COA:', name_='Cost', pretty_print=pretty_print)
        if self.Efficacy is not None:
            self.Efficacy.export(outfile, level, 'COA:', name_='Efficacy', pretty_print=pretty_print)
    def hasContent_(self):
        if (
            self.Stage is not None or
            self.Type is not None or
            self.Description is not None or
            self.Objective is not None or
            self.StructuredCOA is not None or
            self.Impact is not None or
            self.Cost is not None or
            self.Efficacy is not None
            ):
            return True
        else:
            return False
    def exportLiteral(self, outfile, level, name_='COAType'):
        level += 1
        self.exportLiteralAttributes(outfile, level, [], name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        if self.idref is not None and 'idref' not in already_processed:
            already_processed.append('idref')
            showIndent(outfile, level)
            outfile.write('idref = %s,\n' % (self.idref,))
        if self.id is not None and 'id' not in already_processed:
            already_processed.append('id')
            showIndent(outfile, level)
            outfile.write('id = %s,\n' % (self.id,))
        if self.version is not None and 'version' not in already_processed:
            already_processed.append('version')
            showIndent(outfile, level)
            outfile.write('version = "%s",\n' % (self.version,))
    def exportLiteralChildren(self, outfile, level, name_):
        if self.Stage is not None:
            showIndent(outfile, level)
            outfile.write('Stage=%s,\n' % quote_python(self.Stage).encode(ExternalEncoding))
        if self.Type is not None:
            showIndent(outfile, level)
            outfile.write('Type=%s,\n' % quote_python(self.Type).encode(ExternalEncoding))
        if self.Description is not None:
            showIndent(outfile, level)
            outfile.write('Description=model_.cybox_common_binding.StructuredTextType(\n')
            self.Description.exportLiteral(outfile, level, name_='Description')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.Objective is not None:
            showIndent(outfile, level)
            outfile.write('Objective=model_.ObjectiveType(\n')
            self.Objective.exportLiteral(outfile, level, name_='Objective')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.StructuredCOAType is not None:
            showIndent(outfile, level)
            outfile.write('StructuredCOAType=model_.StructuredCOAType(\n')
            self.StructuredCOAType.exportLiteral(outfile, level)
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.Impact is not None:
            showIndent(outfile, level)
            outfile.write('Impact=model_.ImpactType(\n')
            self.Impact.exportLiteral(outfile, level, name_='Impact')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.Cost is not None:
            showIndent(outfile, level)
            outfile.write('Cost=model_.CostType(\n')
            self.Cost.exportLiteral(outfile, level, name_='Cost')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.Efficacy is not None:
            showIndent(outfile, level)
            outfile.write('Efficacy=model_.EfficacyType(\n')
            self.Efficacy.exportLiteral(outfile, level, name_='Efficacy')
            showIndent(outfile, level)
            outfile.write('),\n')
    def build(self, node):
        self.buildAttributes(node, node.attrib, [])
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        value = find_attr_value_('idref', node)
        if value is not None and 'idref' not in already_processed:
            already_processed.append('idref')
            self.idref = value
        value = find_attr_value_('id', node)
        if value is not None and 'id' not in already_processed:
            already_processed.append('id')
            self.id = value
        value = find_attr_value_('version', node)
        if value is not None and 'version' not in already_processed:
            already_processed.append('version')
            self.version = value
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Stage':
            Stage_ = child_.text
            Stage_ = self.gds_validate_string(Stage_, node, 'Stage')
            self.Stage = Stage_
        elif nodeName_ == 'Type':
            Type_ = child_.text
            Type_ = self.gds_validate_string(Type_, node, 'Type')
            self.Type = Type_
        elif nodeName_ == 'Description':
            obj_ = cybox_common_binding.StructuredTextType.factory()
            obj_.build(child_)
            self.set_Description(obj_)
        elif nodeName_ == 'Objective':
            obj_ = ObjectiveType.factory()
            obj_.build(child_)
            self.set_Objective(obj_)
        elif nodeName_ == 'StructuredCOA':
            type_name_ = child_.attrib.get('{http://www.w3.org/2001/XMLSchema-instance}type')
            if type_name_ is None:
                type_name_ = child_.attrib.get('type')
            if type_name_ is not None:
                type_names_ = type_name_.split(':')
                if len(type_names_) == 1:
                    type_name_ = type_names_[0]
                else:
                    type_name_ = type_names_[1]
                class_ = globals()[type_name_]
                obj_ = class_.factory()
                obj_.build(child_)
            else:
                raise NotImplementedError(
                    'Class not implemented for <StructuredCOA> element')
            self.set_StructuredCOA(obj_)
        elif nodeName_ == 'Impact':
            obj_ = ImpactType.factory()
            obj_.build(child_)
            self.set_Impact(obj_)
        elif nodeName_ == 'Cost':
            obj_ = CostType.factory()
            obj_.build(child_)
            self.set_Cost(obj_)
        elif nodeName_ == 'Efficacy':
            obj_ = EfficacyType.factory()
            obj_.build(child_)
            self.set_Efficacy(obj_)
# end class COAType

class StructuredCOAType(GeneratedsSuper):
    """The StructuredCOAType enables the specification of a structured
    representation for the CourseOfAction potentially for automated
    consumption and implementation. This type is defined as an
    abstract type enabling the extension and inclusion of various
    formats of StructuredCOA specifications.Specifies a unique ID
    for this StructuredCOA.Specifies a reference to the ID for this
    StructuredCOA specified elsewhere.Specifies the type of
    StructuredCOA.Specifies a reference URL for a location
    characterizing the StructuredCOA type.Specifies a reference URL
    for the location of the StructuredCOA."""
    subclass = None
    superclass = None
    def __init__(self, typeReference=None, idref=None, type_=None, id=None, referenceLocation=None):
        self.typeReference = _cast(None, typeReference)
        self.idref = _cast(None, idref)
        self.type_ = _cast(None, type_)
        self.id = _cast(None, id)
        self.referenceLocation = _cast(None, referenceLocation)
        pass
    def factory(*args_, **kwargs_):
        if StructuredCOAType.subclass:
            return StructuredCOAType.subclass(*args_, **kwargs_)
        else:
            return StructuredCOAType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_typeReference(self): return self.typeReference
    def set_typeReference(self, typeReference): self.typeReference = typeReference
    def get_idref(self): return self.idref
    def set_idref(self, idref): self.idref = idref
    def get_type(self): return self.type_
    def set_type(self, type_): self.type_ = type_
    def get_id(self): return self.id
    def set_id(self, id): self.id = id
    def get_referenceLocation(self): return self.referenceLocation
    def set_referenceLocation(self, referenceLocation): self.referenceLocation = referenceLocation
    def export(self, outfile, level, namespace_='COA:', name_='StructuredCOAType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = []
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='StructuredCOAType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='COA:', name_='StructuredCOAType'):
        if self.typeReference is not None and 'typeReference' not in already_processed:
            already_processed.append('typeReference')
            outfile.write(' typeReference=%s' % (self.gds_format_string(quote_attrib(self.typeReference).encode(ExternalEncoding), input_name='typeReference'), ))
        if self.idref is not None and 'idref' not in already_processed:
            already_processed.append('idref')
            outfile.write(' idref=%s' % (quote_attrib(self.idref), ))
        if self.type_ is not None and 'type_' not in already_processed:
            already_processed.append('type_')
            outfile.write(' type=%s' % (self.gds_format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))
        if self.id is not None and 'id' not in already_processed:
            already_processed.append('id')
            outfile.write(' id=%s' % (quote_attrib(self.id), ))
        if self.referenceLocation is not None and 'referenceLocation' not in already_processed:
            already_processed.append('referenceLocation')
            outfile.write(' referenceLocation=%s' % (self.gds_format_string(quote_attrib(self.referenceLocation).encode(ExternalEncoding), input_name='referenceLocation'), ))
    def exportChildren(self, outfile, level, namespace_='COA:', name_='StructuredCOAType', fromsubclass_=False, pretty_print=True):
        pass
    def hasContent_(self):
        if (

            ):
            return True
        else:
            return False
    def exportLiteral(self, outfile, level, name_='StructuredCOAType'):
        level += 1
        self.exportLiteralAttributes(outfile, level, [], name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        if self.typeReference is not None and 'typeReference' not in already_processed:
            already_processed.append('typeReference')
            showIndent(outfile, level)
            outfile.write('typeReference = "%s",\n' % (self.typeReference,))
        if self.idref is not None and 'idref' not in already_processed:
            already_processed.append('idref')
            showIndent(outfile, level)
            outfile.write('idref = %s,\n' % (self.idref,))
        if self.type_ is not None and 'type_' not in already_processed:
            already_processed.append('type_')
            showIndent(outfile, level)
            outfile.write('type_ = "%s",\n' % (self.type_,))
        if self.id is not None and 'id' not in already_processed:
            already_processed.append('id')
            showIndent(outfile, level)
            outfile.write('id = %s,\n' % (self.id,))
        if self.referenceLocation is not None and 'referenceLocation' not in already_processed:
            already_processed.append('referenceLocation')
            showIndent(outfile, level)
            outfile.write('referenceLocation = "%s",\n' % (self.referenceLocation,))
    def exportLiteralChildren(self, outfile, level, name_):
        pass
    def build(self, node):
        self.buildAttributes(node, node.attrib, [])
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        value = find_attr_value_('typeReference', node)
        if value is not None and 'typeReference' not in already_processed:
            already_processed.append('typeReference')
            self.typeReference = value
        value = find_attr_value_('idref', node)
        if value is not None and 'idref' not in already_processed:
            already_processed.append('idref')
            self.idref = value
        value = find_attr_value_('type', node)
        if value is not None and 'type' not in already_processed:
            already_processed.append('type')
            self.type_ = value
        value = find_attr_value_('id', node)
        if value is not None and 'id' not in already_processed:
            already_processed.append('id')
            self.id = value
        value = find_attr_value_('referenceLocation', node)
        if value is not None and 'referenceLocation' not in already_processed:
            already_processed.append('referenceLocation')
            self.referenceLocation = value
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        pass
# end class StructuredCOAType

class ObjectiveType(GeneratedsSuper):
    """The ObjectiveType characterizes the objective of this
    CourseOfAction."""
    subclass = None
    superclass = None
    def __init__(self, Description=None, Target=None, ApplicabilityConfidence=None):
        self.Description = Description
        self.Target = Target
        self.ApplicabilityConfidence = ApplicabilityConfidence
    def factory(*args_, **kwargs_):
        if ObjectiveType.subclass:
            return ObjectiveType.subclass(*args_, **kwargs_)
        else:
            return ObjectiveType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Description(self): return self.Description
    def set_Description(self, Description): self.Description = Description
    def get_Target(self): return self.Target
    def set_Target(self, Target): self.Target = Target
    def get_ApplicabilityConfidence(self): return self.ApplicabilityConfidence
    def set_ApplicabilityConfidence(self, ApplicabilityConfidence): self.ApplicabilityConfidence = ApplicabilityConfidence
    def export(self, outfile, level, namespace_='COA:', name_='ObjectiveType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = []
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='ObjectiveType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='COA:', name_='ObjectiveType'):
        pass
    def exportChildren(self, outfile, level, namespace_='COA:', name_='ObjectiveType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Description is not None:
            self.Description.export(outfile, level, 'COA:', name_='Description', pretty_print=pretty_print)
        if self.Target is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sTarget>%s</%sTarget>%s' % ('COA:', self.gds_format_string(quote_xml(self.Target).encode(ExternalEncoding), input_name='Target'), 'COA:', eol_))
        if self.ApplicabilityConfidence is not None:
            self.ApplicabilityConfidence.export(outfile, level, 'COA:', name_='ApplicabilityConfidence', pretty_print=pretty_print)
    def hasContent_(self):
        if (
            self.Description is not None or
            self.Target is not None or
            self.ApplicabilityConfidence is not None
            ):
            return True
        else:
            return False
    def exportLiteral(self, outfile, level, name_='ObjectiveType'):
        level += 1
        self.exportLiteralAttributes(outfile, level, [], name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.Description is not None:
            showIndent(outfile, level)
            outfile.write('Description=model_.cybox_common_binding.StructuredTextType(\n')
            self.Description.exportLiteral(outfile, level, name_='Description')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.Target is not None:
            showIndent(outfile, level)
            outfile.write('Target=%s,\n' % quote_python(self.Target).encode(ExternalEncoding))
        if self.ApplicabilityConfidence is not None:
            showIndent(outfile, level)
            outfile.write('ApplicabilityConfidence=model_.stix_common_binding.ConfidenceType(\n')
            self.ApplicabilityConfidence.exportLiteral(outfile, level, name_='ApplicabilityConfidence')
            showIndent(outfile, level)
            outfile.write('),\n')
    def build(self, node):
        self.buildAttributes(node, node.attrib, [])
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Description':
            obj_ = cybox_common_binding.StructuredTextType.factory()
            obj_.build(child_)
            self.set_Description(obj_)
        elif nodeName_ == 'Target':
            Target_ = child_.text
            Target_ = self.gds_validate_string(Target_, node, 'Target')
            self.Target = Target_
        elif nodeName_ == 'ApplicabilityConfidence':
            obj_ = stix_common_binding.ConfidenceType.factory()
            obj_.build(child_)
            self.set_ApplicabilityConfidence(obj_)
# end class ObjectiveType

USAGE_TEXT = """
Usage: python <Parser>.py [ -s ] <in_xml_file>
"""

def usage():
    print(USAGE_TEXT)
    sys.exit(1)

def get_root_tag(node):
    tag = Tag_pattern_.match(node.tag).groups()[-1]
    rootClass = globals().get(tag)
    return tag, rootClass

def parse(inFileName):
    doc = parsexml_(inFileName)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'CourseOfAction'
        rootClass = COAType
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    sys.stdout.write('<?xml version="1.0" ?>\n')
    rootObj.export(sys.stdout, 0, name_=rootTag,
        namespacedef_='',
        pretty_print=True)
    return rootObj

def parseString(inString):
    from StringIO import StringIO
    doc = parsexml_(StringIO(inString))
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'CourseOfAction'
        rootClass = COAType
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    sys.stdout.write('<?xml version="1.0" ?>\n')
    rootObj.export(sys.stdout, 0, name_="CourseOfAction",
        namespacedef_='')
    return rootObj

def parseLiteral(inFileName):
    doc = parsexml_(inFileName)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'CourseOfAction'
        rootClass = COAType
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    sys.stdout.write('#from COA import *\n\n')
    sys.stdout.write('import COA as model_\n\n')
    sys.stdout.write('rootObj = model_.rootTag(\n')
    rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
    sys.stdout.write(')\n')
    return rootObj

def main():
    args = sys.argv[1:]
    if len(args) == 1:
        parse(args[0])
    else:
        usage()

if __name__ == '__main__':
    #import pdb; pdb.set_trace()
    main()

__all__ = [
    "COAType",
    "StructuredCOAType",
    "ObjectiveType"
    ]
