xmlclass/xmlclass.py
author lbessard
Thu, 23 Aug 2007 09:23:32 +0200
changeset 76 5bac3213fea1
parent 75 82d371634f15
child 83 180e4a0160b2
permissions -rw-r--r--
xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     3
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     6
#
58
39cd981ff242 Changing file headers
lbessard
parents: 24
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     8
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    10
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    15
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58
39cd981ff242 Changing file headers
lbessard
parents: 24
diff changeset
    19
#General Public License for more details.
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    20
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    24
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    25
from xml.dom import minidom
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    26
import sys,re
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    27
from types import *
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    28
from datetime import *
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
    29
from new import classobj
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    30
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    31
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    32
Time and date definitions
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    33
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    34
TimeType = time(0,0,0).__class__
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    35
DateType = date(1,1,1).__class__
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    36
DateTimeType = datetime(1,1,1,0,0,0).__class__
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    37
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    38
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    39
Regular expression models for extracting dates and times from a string
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    40
"""
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
    41
time_model = re.compile('([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    42
date_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})')
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
    43
datetime_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})[ T]([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    44
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    45
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    46
This function calculates the number of whitespace for indentation
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    47
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    48
def getIndent(indent, balise):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    49
    first = indent * 2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    50
    second = first + len(balise) + 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    51
    return "\t".expandtabs(first), "\t".expandtabs(second)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    52
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    53
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    54
Function that extracts data from a node
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    55
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    56
def GetAttributeValue(attr):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    57
    if len(attr.childNodes) == 1:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    58
        return attr.childNodes[0].data.encode()
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    59
    else:
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 58
diff changeset
    60
        text = ""
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 58
diff changeset
    61
        for node in attr.childNodes:
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 58
diff changeset
    62
            if node.nodeName != "#text":
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 58
diff changeset
    63
                text += node.data.encode()
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 58
diff changeset
    64
        return text
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    65
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    66
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    67
Function that computes value from a python type (Only Boolean are critical because
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    68
there is no uppercase in plcopen)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    69
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    70
def ComputeValue(value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    71
    if type(value) == BooleanType:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    72
        if value:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    73
            return "true"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    74
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    75
            return "false"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    76
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    77
        return str(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    78
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    79
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    80
Function that extracts a value from a string following the xsd type given
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    81
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    82
def GetComputedValue(attr_type, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    83
    type_compute = attr_type[4:].replace("[]", "")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    84
    if type_compute == "boolean":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    85
         if value == "true":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    86
             return True
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    87
         elif value == "false":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    88
             return False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    89
         else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    90
            raise ValueError, "\"%s\" is not a valid boolean!"%value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    91
    elif type_compute in ["decimal","unsignedLong","long","integer"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    92
        return int(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    93
    elif type_compute in ["string","anyURI","NMTOKEN","language"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    94
        return value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    95
    elif type_compute == "time":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    96
        result = time_model.match(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    97
        if result:
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
    98
            values = result.groups()
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
    99
            time_values = [int(v) for v in values[:2]]
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   100
            seconds = float(values[2])
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   101
            time_values.extend([int(seconds), int((seconds % 1) * 1000000)])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   102
            return time(*time_values)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   103
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   104
            raise ValueError, "\"%s\" is not a valid time!"%value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   105
    elif type_compute == "date":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   106
        result = date_model.match(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   107
        if result:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   108
            date_values = [int(v) for v in result.groups()]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   109
            return date(*date_values)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   110
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   111
            raise ValueError, "\"%s\" is not a valid date!"%value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   112
    elif type_compute == "dateTime":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   113
        result = datetime_model.match(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   114
        if result:
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   115
            values = result.groups()
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   116
            datetime_values = [int(v) for v in values[:5]]
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   117
            seconds = float(values[5])
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   118
            datetime_values.extend([int(seconds), int((seconds % 1) * 1000000)])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   119
            return datetime(*datetime_values)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   120
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   121
            raise ValueError, "\"%s\" is not a valid datetime!"%value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   122
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   123
        print "Can't affect: %s"%type_compute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   124
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   125
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   126
"""
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   127
Class that generate class from an XML Tree 
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   128
"""
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   129
class ClassFactory:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   130
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   131
    def __init__(self, xsd_tree):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   132
        self.XML_Tree = xsd_tree
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   133
        
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   134
        # Dictionary for stocking Classes and Types definitions created from the XML tree
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   135
        self.XMLClassDefinitions = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   136
        
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   137
        # Dictionaries for stocking Classes and Types generated
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   138
        self.ComputedClasses = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   139
        self.ComputedTypes = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   140
        self.AlreadyComputed = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   141
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   142
    """
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   143
    This function recursively creates a definition of the classes and their attributes
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   144
    for plcopen from the xsd file of plcopen opened in a DOM model
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   145
    """
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   146
    def GenerateXSDClasses(self, tree, parent, sequence = False):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   147
        attributes = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   148
        inheritance = []
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   149
        if sequence:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   150
            order = []
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   151
        # The lists of attributes and inheritance of the node are generated from the childrens 
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   152
        for node in tree.childNodes:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   153
            # We make fun of #text elements and all other tags that don't are xsd tags
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   154
            if node.nodeName != "#text" and node.nodeName.startswith("xsd:"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   155
                recursion = False
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   156
                name = node.nodeName[4:].encode()
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   157
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   158
                # This tags defines an attribute of the class
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   159
                if name in ["element", "attribute"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   160
                    nodename = GetAttributeValue(node._attrs["name"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   161
                    if "type" in node._attrs:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   162
                        nodetype = GetAttributeValue(node._attrs["type"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   163
                        if nodetype.startswith("xsd"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   164
                            nodetype = nodetype.replace("xsd", "bse")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   165
                        elif nodetype.startswith("ppx"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   166
                            nodetype = nodetype.replace("ppx", "cls")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   167
                    else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   168
                        # The type of attribute is defines in the child tree so we generate a new class
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   169
                        # No name is defined so we create one from nodename and parent class name
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   170
                        # (because some different nodes can have the same name)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   171
                        if parent:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   172
                            classname = "%s_%s"%(parent, nodename)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   173
                        else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   174
                            classname = nodename
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   175
                        self.GenerateXSDClasses(node, classname)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   176
                        nodetype = "cls:%s"%classname
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   177
                    if name == "attribute":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   178
                        if "use" in node._attrs:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   179
                            use = GetAttributeValue(node._attrs["use"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   180
                        else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   181
                            use = "optional"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   182
                    if name == "element":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   183
                        # If a tag can be written more than one time we define a list attribute
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   184
                        if "maxOccurs" in node._attrs and GetAttributeValue(node._attrs["maxOccurs"]) == "unbounded":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   185
                            nodetype = "%s[]"%nodetype
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   186
                        if "minOccurs" in node._attrs and GetAttributeValue(node._attrs["minOccurs"]) == "0":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   187
                            use = "optional"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   188
                        else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   189
                            use = "required"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   190
                    attributes[nodename] = (nodetype, name, use)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   191
                    if sequence:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   192
                        order.append(nodename)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   193
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   194
                # This tag defines a new class
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   195
                elif name == "complexType" or name == "simpleType":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   196
                    if "name" in node._attrs:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   197
                        classname = GetAttributeValue(node._attrs["name"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   198
                        super, attrs = self.GenerateXSDClasses(node, classname)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   199
                    else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   200
                        classname = parent
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   201
                        super, attrs = self.GenerateXSDClasses(node, classname.split("_")[-1])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   202
                    # When all attributes and inheritances have been extracted, the
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   203
                    # values are added in the list of classes to create
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   204
                    if self.XMLClassDefinitions.get(classname, None) == None:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   205
                        self.XMLClassDefinitions[classname] = (super, attrs)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   206
                    elif self.XMLClassDefinitions[classname] != (super, attrs):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   207
                        print "A different class has already got %s for name"%classname
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   208
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   209
                # This tag defines an attribute that can have different types
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   210
                elif name == "choice":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   211
                    super, attrs = self.GenerateXSDClasses(node, parent)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   212
                    
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   213
                    if "ref" in attrs.keys():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   214
                        choices = attrs
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   215
                    else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   216
                        choices = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   217
                        for attr, (attr_type, xml_type, write_type) in attrs.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   218
                            choices[attr] = attr_type
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   219
                    if "maxOccurs" in node._attrs and GetAttributeValue(node._attrs["maxOccurs"]) == "unbounded":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   220
                        attributes["multichoice_content"] = choices
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   221
                        if sequence:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   222
                            order.append("multichoice_content")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   223
                    else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   224
                        attributes["choice_content"] = choices
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   225
                        if sequence:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   226
                            order.append("choice_content")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   227
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   228
                # This tag defines the order in which class attributes must be written
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   229
                # in plcopen xml file. We have to store this order like an attribute
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   230
                elif name in "sequence":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   231
                    super, attrs, order = self.GenerateXSDClasses(node, parent, True)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   232
                    if "maxOccurs" in node._attrs and GetAttributeValue(node._attrs["maxOccurs"]) == "unbounded":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   233
                        for attr, (attr_type, xml_type, write_type) in attrs.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   234
                            attrs[attr] = ("%s[]"%attr_type, xml_type, write_type)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   235
                    if "minOccurs" in node._attrs and GetAttributeValue(node._attrs["minOccurs"]) == "0":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   236
                        for attr, (attr_type, xml_type, write_type) in attrs.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   237
                            attrs[attr] = (attr_type, xml_type, "optional")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   238
                    inheritance.extend(super)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   239
                    attributes.update(attrs)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   240
                    attributes["order"] = order
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   241
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   242
                # This tag defines of types
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   243
                elif name == "group":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   244
                    if "name" in node._attrs:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   245
                        nodename = GetAttributeValue(node._attrs["name"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   246
                        super, attrs = self.GenerateXSDClasses(node, None)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   247
                        self.XMLClassDefinitions[nodename] = (super, {"group":attrs["choice_content"]})
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   248
                    elif "ref" in node._attrs:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   249
                        if "ref" not in attributes:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   250
                            attributes["ref"] = [GetAttributeValue(node._attrs["ref"])]
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   251
                        else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   252
                            attributes["ref"].append(GetAttributeValue(node._attrs["ref"]))
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   253
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   254
                # This tag define a base class for the node
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   255
                elif name == "extension":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   256
                    super = GetAttributeValue(node._attrs["base"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   257
                    if super.startswith("xsd"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   258
                        super = super.replace("xsd", "bse")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   259
                    elif super.startswith("ppx"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   260
                        super = super.replace("ppx", "cls")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   261
                    inheritance.append(super[4:])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   262
                    recursion = True
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   263
                    
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   264
                # This tag defines a restriction on the type of attribute
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   265
                elif name == "restriction":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   266
                    basetype = GetAttributeValue(node._attrs["base"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   267
                    if basetype.startswith("xsd"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   268
                        basetype = basetype.replace("xsd", "bse")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   269
                    elif basetype.startswith("ppx"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   270
                        basetype = basetype.replace("ppx", "cls")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   271
                    attributes["basetype"] = basetype
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   272
                    recursion = True
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   273
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   274
                # This tag defines an enumerated type
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   275
                elif name == "enumeration":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   276
                    if "enum" not in attributes:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   277
                        attributes["enum"] = [GetAttributeValue(node._attrs["value"])]
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   278
                    else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   279
                        attributes["enum"].append(GetAttributeValue(node._attrs["value"]))
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   280
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   281
                # This tags defines a restriction on a numerical value
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   282
                elif name in ["minInclusive","maxInclusive"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   283
                    if "limit" not in attributes:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   284
                        attributes["limit"] = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   285
                    if name == "minInclusive":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   286
                        attributes["limit"]["min"] = eval(GetAttributeValue(node._attrs["value"]))
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   287
                    elif name == "maxInclusive":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   288
                        attributes["limit"]["max"] = eval(GetAttributeValue(node._attrs["value"]))
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   289
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   290
                # This tag are not important but their childrens are. The childrens are then parsed. 
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   291
                elif name in ["complexContent", "schema"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   292
                    recursion = True
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   293
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   294
                # We make fun of xsd documentation
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   295
                elif name in ["annotation"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   296
                    pass
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   297
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   298
                else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   299
                    # Unable this line to print XSD element that is not yet supported 
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   300
                    #print name
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   301
                    self.GenerateXSDClasses(node, parent)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   302
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   303
                # Parse the childrens of node
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   304
                if recursion:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   305
                    super, attrs = self.GenerateXSDClasses(node, parent)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   306
                    inheritance.extend(super)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   307
                    attributes.update(attrs)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   308
        
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   309
        # if sequence tag have been found, order is returned
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   310
        if sequence:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   311
            return inheritance, attributes, order
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   312
        else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   313
            return inheritance, attributes
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   314
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   315
    """
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   316
    Funtion that returns the Python type and default value for a given type
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   317
    """
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   318
    def GetTypeInitialValue(self, attr_type):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   319
        type_compute = attr_type[4:].replace("[]", "")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   320
        if attr_type.startswith("bse:"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   321
            if type_compute == "boolean":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   322
                return BooleanType, "False"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   323
            elif type_compute in ["decimal","unsignedLong","long","integer"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   324
                return IntType, "0"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   325
            elif type_compute in ["string","anyURI","NMTOKEN"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   326
                return StringType, "\"\""
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   327
            elif type_compute == "time":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   328
                return TimeType, "time(0,0,0,0)"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   329
            elif type_compute == "date":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   330
                return DateType, "date(1,1,1)"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   331
            elif type_compute == "dateTime":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   332
                return DateTimeType, "datetime(1,1,1,0,0,0,0)"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   333
            elif type_compute == "language":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   334
                return StringType, "\"en-US\""
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   335
            else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   336
                print "Can't affect: %s"%type_compute
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   337
        elif attr_type.startswith("cls:"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   338
            if self.XMLClassDefinitions.get(type_compute, None) != None:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   339
                return self.XMLClassDefinitions[type_compute],"%s()"%type_compute
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   340
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   341
    """
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   342
    Methods that generate the classes
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   343
    """
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   344
    def CreateClasses(self):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   345
        self.GenerateXSDClasses(self.XML_Tree, None)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   346
        for classname in self.XMLClassDefinitions.keys():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   347
            self.CreateClass(classname)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   348
        for classname in self.XMLClassDefinitions.keys():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   349
            self.MarkUsedClasses(classname)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   350
        return self.ComputedClasses, self.ComputedTypes
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   351
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   352
    def CreateClass(self, classname):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   353
        # Checks that classe haven't been generated yet
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   354
        if not self.AlreadyComputed.get(classname, False) and classname in self.XMLClassDefinitions:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   355
            self.AlreadyComputed[classname] = True
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   356
            inheritance, attributes = self.XMLClassDefinitions[classname]
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   357
            #print classname, inheritance, attributes
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   358
            members = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   359
            bases = []
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   360
            
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   361
            # If inheritance classes haven't been generated
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   362
            for base in inheritance:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   363
                self.CreateClass(base)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   364
                bases.append(self.ComputedClasses[base])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   365
            
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   366
            # Checks that all attribute types are available 
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   367
            for attribute, type_attribute in attributes.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   368
                if attribute == "group":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   369
                    self.ComputedTypes[classname] = type_attribute
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   370
                elif attribute in ["choice_content","multichoice_content"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   371
                    element_types = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   372
                    for attr, value in type_attribute.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   373
                        if attr == "ref":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   374
                            for ref in value:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   375
                                self.CreateClass(ref[4:])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   376
                                element_types.update(self.ComputedTypes[ref[4:]])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   377
                        else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   378
                            element_types[attr] = value
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   379
                    members[attribute] = element_types
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   380
                else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   381
                    members[attribute] = type_attribute
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   382
                    if attribute == "enum":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   383
                        self.ComputedTypes["%s_enum"%classname] = type_attribute
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   384
                    elif attribute not in ["limit", "order"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   385
                        if type_attribute[0].startswith("cls:"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   386
                            type_compute = type_attribute[0][4:].replace("[]","")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   387
                            self.CreateClass(type_compute)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   388
            if "group" not in attributes:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   389
                bases = tuple(bases)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   390
                classmembers = {"IsBaseClass" : True}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   391
                initialValues = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   392
                for attr, values in members.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   393
                    if attr in ["order", "basetype"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   394
                        pass
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   395
                    
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   396
                    # Class is a enumerated type
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   397
                    elif attr == "enum":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   398
                        value_type, initial = self.GetTypeInitialValue(members["basetype"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   399
                        initialValues["value"] = "\"%s\""%values[0]
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   400
                        classmembers["value"] = values[0]
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   401
                        classmembers["setValue"] = generateSetEnumMethod(values, value_type)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   402
                        classmembers["getValue"] = generateGetMethod("value")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   403
                    
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   404
                    # Class is a limited type
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   405
                    elif attr == "limit":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   406
                        value_type, initial = self.GetTypeInitialValue(members["basetype"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   407
                        initial = 0
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   408
                        if "min" in values:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   409
                            initial = max(initial, values["min"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   410
                        if "max" in values:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   411
                            initial = min(initial, values["max"])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   412
                        initialValues["value"] = "%d"%initial
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   413
                        classmembers["value"] = initial
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   414
                        classmembers["setValue"] = generateSetLimitMethod(values, value_type)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   415
                        classmembers["getValue"] = generateGetMethod("value")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   416
                    
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   417
                    # Class has an attribute that can have different value types
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   418
                    elif attr == "choice_content":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   419
                        classmembers["content"] = None
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   420
                        initialValues["content"] = "None"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   421
                        classmembers["deleteContent"] = generateDeleteMethod("content")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   422
                        classmembers["setContent"] = generateSetChoiceMethod(values)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   423
                        classmembers["getContent"] = generateGetMethod("content")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   424
                    elif attr == "multichoice_content":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   425
                        classmembers["content"] = []
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   426
                        initialValues["content"] = "[]"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   427
                        classmembers["appendContent"] = generateAppendChoiceMethod(values)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   428
                        classmembers["insertContent"] = generateInsertChoiceMethod(values)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   429
                        classmembers["removeContent"] = generateRemoveMethod("content")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   430
                        classmembers["countContent"] = generateCountMethod("content")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   431
                        classmembers["setContent"] = generateSetMethod("content", ListType)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   432
                        classmembers["getContent"] = generateGetMethod("content")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   433
                    
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   434
                    # It's an attribute of the class
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   435
                    else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   436
                        attrname = attr[0].upper()+attr[1:]
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   437
                        attr_type, xml_type, write_type = values
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   438
                        value_type, initial = self.GetTypeInitialValue(attr_type)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   439
                        # Value of the attribute is a list
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   440
                        if attr_type.endswith("[]"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   441
                            classmembers[attr] = []
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   442
                            initialValues[attr] = "[]"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   443
                            classmembers["append"+attrname] = generateAppendMethod(attr, value_type)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   444
                            classmembers["insert"+attrname] = generateInsertMethod(attr, value_type)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   445
                            classmembers["remove"+attrname] = generateRemoveMethod(attr)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   446
                            classmembers["count"+attrname] = generateCountMethod(attr)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   447
                            classmembers["set"+attrname] = generateSetMethod(attr, ListType)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   448
                        else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   449
                            if write_type == "optional":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   450
                                classmembers[attr] = None
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   451
                                initialValues[attr] = "None"
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   452
                                classmembers["add"+attrname] = generateAddMethod(attr, initial, self.ComputedClasses)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   453
                                classmembers["delete"+attrname] = generateDeleteMethod(attr)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   454
                            else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   455
                                classmembers[attr] = initial
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   456
                                initialValues[attr] = initial
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   457
                            classmembers["set"+attrname] = generateSetMethod(attr, value_type)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   458
                        classmembers["get"+attrname] = generateGetMethod(attr)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   459
                classmembers["__init__"] = generateInitMethod(bases, initialValues, self.ComputedClasses)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   460
                classmembers["loadXMLTree"] = generateLoadXMLTree(bases, members, self.ComputedClasses)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   461
                classmembers["generateXMLText"] = generateGenerateXMLText(bases, members)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   462
                classmembers["getElementAttributes"] = generategetElementAttributes(bases, members)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   463
                classmembers["singleLineAttributes"] = True
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   464
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   465
                self.ComputedClasses[classname] = classobj(classname, bases, classmembers)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   466
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   467
    def MarkUsedClasses(self, classname):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   468
        # Checks that classe haven't been generated yet
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   469
        if classname in self.XMLClassDefinitions:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   470
            inheritance, attributes = self.XMLClassDefinitions[classname]
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   471
            
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   472
            # If inheritance classes haven't been generated
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   473
            for base in inheritance:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   474
                if base in self.ComputedClasses:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   475
                    self.ComputedClasses[base].IsBaseClass = False
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   476
                
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   477
            # Checks that all attribute types are available 
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   478
            for attribute, type_attribute in attributes.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   479
                if attribute in ["choice_content","multichoice_content"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   480
                    element_types = {}
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   481
                    for attr, value in type_attribute.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   482
                        if attr == "ref":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   483
                            for ref in value:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   484
                                element_types.update(self.ComputedTypes[ref[4:]])
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   485
                        else:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   486
                            element_types[attr] = value
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   487
                    for type_name in element_types.values():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   488
                        type_compute = type_name[4:].replace("[]","")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   489
                        if type_compute in self.ComputedClasses:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   490
                            self.ComputedClasses[type_compute].IsBaseClass = False
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   491
                elif attribute != "group":
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   492
                    if attribute not in ["enum", "limit", "order"]:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   493
                        if type_attribute[0].startswith("cls:"):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   494
                            type_compute = type_attribute[0][4:].replace("[]","")
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   495
                            if type_compute in self.ComputedClasses:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   496
                                self.ComputedClasses[type_compute].IsBaseClass = False
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   497
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   498
    """
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   499
    Methods that print the classes generated
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   500
    """
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   501
    def PrintClasses(self):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   502
        for classname, xmlclass in self.ComputedClasses.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   503
            print "%s : %s"%(classname, str(xmlclass))
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   504
        
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   505
    def PrintClassNames(self):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   506
        classnames = self.XMLClassDefinitions.keys()
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   507
        classnames.sort()
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   508
        for classname in classnames:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   509
            print classname
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   510
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   511
"""
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   512
Method that generate the method for loading an xml tree by following the
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   513
attributes list defined
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   514
"""
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   515
def generateLoadXMLTree(bases, members, classes):
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   516
    def loadXMLTreeMethod(self, tree):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   517
        # If class is derived, values of inheritance classes are loaded
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   518
        for base in bases:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   519
            base.loadXMLTree(self, tree)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   520
        # Class is a enumerated or limited value
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   521
        if "enum" in members.keys() or "limit" in members.keys():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   522
            attr_value = GetAttributeValue(tree)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   523
            attr_type = members["basetype"]
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   524
            val = GetComputedValue(attr_type, attr_value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   525
            self.setValue(val)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   526
        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   527
            
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   528
            # Load the node attributes if they are defined in the list
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   529
            for attrname, attr in tree._attrs.items():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   530
                if attrname in members.keys():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   531
                    attr_type, xml_type, write_type = members[attrname]
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   532
                    attr_value = GetAttributeValue(attr)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   533
                    if write_type != "optional" or attr_value != "":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   534
                        # Extracts the value
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   535
                        if attr_type.startswith("bse:"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   536
                            val = GetComputedValue(attr_type, attr_value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   537
                        elif attr_type.startswith("cls:"):
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   538
                            val = classes[attr_type[4:]]()
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   539
                            val.loadXMLTree(attr)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   540
                        setattr(self, attrname, val)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   541
            
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   542
            # Load the node childs if they are defined in the list
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   543
            for node in tree.childNodes:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   544
                name = node.nodeName
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   545
                # We make fun of #text elements
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   546
                if name != "#text":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   547
                    
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   548
                    # Class has an attribute that can have different value types
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   549
                    if "choice_content" in members.keys() and name in members["choice_content"].keys():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   550
                        attr_type = members["choice_content"][name]
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   551
                        # Extracts the value
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   552
                        if attr_type.startswith("bse:"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   553
                            attr_value = GetAttributeValue(node)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   554
                            if write_type != "optional" or attr_value != "":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   555
                                val = GetComputedValue(attr_type.replace("[]",""), attr_value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   556
                            else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   557
                                val = None
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   558
                        elif attr_type.startswith("cls:"):
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   559
                            val = classes[attr_type[4:].replace("[]","")]()
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   560
                            val.loadXMLTree(node)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   561
                        # Stock value in content attribute
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   562
                        if val:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   563
                            if attr_type.endswith("[]"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   564
                                if self.content:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   565
                                    self.content["value"].append(val)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   566
                                else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   567
                                    self.content = {"name":name,"value":[val]}
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   568
                            else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   569
                                self.content = {"name":name,"value":val}
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   570
                    
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   571
                    # Class has a list of attributes that can have different value types
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   572
                    elif "multichoice_content" in members.keys() and name in members["multichoice_content"].keys():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   573
                        attr_type = members["multichoice_content"][name]
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   574
                        # Extracts the value
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   575
                        if attr_type.startswith("bse:"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   576
                            attr_value = GetAttributeValue(node)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   577
                            if write_type != "optional" or attr_value != "":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   578
                                val = GetComputedValue(attr_type, attr_value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   579
                            else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   580
                                val = None
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   581
                        elif attr_type.startswith("cls:"):
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   582
                            val = classes[attr_type[4:]]()
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   583
                            val.loadXMLTree(node)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   584
                        # Add to content attribute list
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   585
                        if val:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   586
                            self.content.append({"name":name,"value":val})
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   587
                    
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   588
                    # The node child is defined in the list
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   589
                    elif name in members.keys():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   590
                        attr_type, xml_type, write_type = members[name]
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   591
                        # Extracts the value
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   592
                        if attr_type.startswith("bse:"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   593
                            attr_value = GetAttributeValue(node)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   594
                            if write_type != "optional" or attr_value != "":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   595
                                val = GetComputedValue(attr_type.replace("[]",""), attr_value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   596
                            else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   597
                                val = None
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   598
                        elif attr_type.startswith("cls:"):
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   599
                            val = classes[attr_type[4:].replace("[]","")]()
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   600
                            val.loadXMLTree(node)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   601
                        # Stock value in attribute
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   602
                        if val:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   603
                            if attr_type.endswith("[]"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   604
                                getattr(self, name).append(val)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   605
                            else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   606
                                setattr(self, name, val)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   607
    return loadXMLTreeMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   608
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   609
"""
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   610
Method that generates the method for generating an xml text by following the
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   611
attributes list defined
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   612
"""
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   613
def generateGenerateXMLText(bases, members):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   614
    def generateXMLTextMethod(self, name, indent, extras = {}, derived = False):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   615
        ind1, ind2 = getIndent(indent, name)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   616
        if not derived:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   617
            text = ind1 + "<%s"%name
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   618
        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   619
            text = ""
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   620
        if len(bases) > 0:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   621
            base_extras = {}
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   622
        if "order" in members.keys():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   623
            order = members["order"]
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   624
        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   625
            order = []
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   626
        if "choice_content" in members.keys() and "choice_content" not in order:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   627
            order.append("choice_content") 
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   628
        if "multichoice_content" in members.keys() and "multichoice_content" not in order:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   629
            order.append("multichoice_content") 
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   630
        size = 0
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   631
        first = True
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   632
        for attr, value in extras.items():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   633
            if not first and not self.singleLineAttributes:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   634
                text += "\n%s"%(ind2)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   635
            text += " %s=\"%s\""%(attr, ComputeValue(value))
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   636
            first = False
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   637
        for attr, values in members.items():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   638
            if attr in ["order","choice_content","multichoice_content"]:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   639
                pass
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   640
            elif attr in ["enum","limit"]:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   641
                if not derived:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   642
                    text += ">%s</%s>\n"%(ComputeValue(self.value),name)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   643
                else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   644
                    text += ComputeValue(self.value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   645
                return text
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   646
            elif values[1] == "attribute":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   647
                value = getattr(self, attr, None)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   648
                if value == "":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   649
                    value = None
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   650
                if values[2] != "optional" or value != None:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   651
                    if not first and not self.singleLineAttributes:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   652
                        text += "\n%s"%(ind2)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   653
                    if values[0].startswith("cls"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   654
                        if len(bases) > 0:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   655
                            base_extras[attr] = value.getValue()
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   656
                        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   657
                            text += " %s=\"%s\""%(attr, ComputeValue(value.getValue()))
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   658
                    else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   659
                        if len(bases) > 0:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   660
                            base_extras[attr] = value
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   661
                        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   662
                            text += " %s=\"%s\""%(attr, ComputeValue(value))
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   663
                    first = False
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   664
        if len(bases) > 0:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   665
            first, new_text = bases[0].generateXMLText(self, name, indent, base_extras, True)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   666
            text += new_text
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   667
        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   668
            first = True
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   669
        ind3, ind4 = getIndent(indent + 1, name)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   670
        for attr in order:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   671
            value = getattr(self, attr, None)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   672
            if attr == "choice_content":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   673
                if self.content:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   674
                    if first:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   675
                        text += ">\n"
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   676
                        first = False
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   677
                    value_type = members[attr][self.content["name"]]
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   678
                    if value_type.startswith("bse:"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   679
                        if value_type.endswith("[]"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   680
                            for content in self.content["value"]:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   681
                                text += ind1 + "<%s>%s</%s>\n"%(self.content["name"], ComputeValue(content), self.content["name"])
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   682
                        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   683
                            text += ind1 + "<%s>%s</%s>\n"%(self.content["name"], ComputeValue(self.content["value"]), self.content["name"])
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   684
                    elif value_type.endswith("[]"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   685
                        for content in self.content["value"]:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   686
                            text += content.generateXMLText(self.content["name"], indent + 1)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   687
                    else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   688
                        text += self.content["value"].generateXMLText(self.content["name"], indent + 1)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   689
            elif attr == "multichoice_content":
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   690
                if len(self.content) > 0:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   691
                    for element in self.content:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   692
                        if first:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   693
                            text += ">\n"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   694
                            first = False
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   695
                        value_type = members[attr][element["name"]]
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   696
                        if value_type.startswith("bse:"):
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   697
                            text += ind1 + "<%s>%s</%s>\n"%(element["name"], ComputeValue(element["value"]), element["name"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   698
                        else:
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   699
                            text += element["value"].generateXMLText(element["name"], indent + 1)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   700
            elif members[attr][2] != "optional" or value != None:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   701
                if members[attr][0].endswith("[]"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   702
                    if first and len(value) > 0:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   703
                        text += ">\n"
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   704
                        first = False
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   705
                    for element in value:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   706
                        if members[attr][0].startswith("bse:"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   707
                            text += ind3 + "<%s>%s</%s>\n"%(attr, ComputeValue(element), attr)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   708
                        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   709
                            text += element.generateXMLText(attr, indent + 1)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   710
                else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   711
                    if first:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   712
                        text += ">\n"
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   713
                        first = False
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   714
                    if members[attr][0].startswith("bse:"):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   715
                        text += ind3 + "<%s>%s</%s>\n"%(attr, ComputeValue(value), attr)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   716
                    else:
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   717
                        text += getattr(self, attr).generateXMLText(attr, indent + 1)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   718
        if not derived:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   719
            if first:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   720
                text += "/>\n"
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   721
            else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   722
                text += ind1 + "</%s>\n"%(name)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   723
            return text
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   724
        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   725
            return first, text
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   726
    return generateXMLTextMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   727
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   728
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   729
def generategetElementAttributes(bases, members):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   730
    def getElementAttributes(self):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   731
        attr_list = []
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   732
        for attr, values in members.items():
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   733
            if attr in ["order","choice_content","multichoice_content"]:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   734
                pass
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   735
            elif values[1] == "attribute":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   736
                if values[2] == "required":
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   737
                    require = True
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   738
                else:
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   739
                    require = False
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   740
                attr_hash ={"name": attr,"type": values[0] ,"value": getattr(self, attr, "") ,"require": require}
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   741
                attr_list.append(attr_hash)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   742
        return attr_list
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   743
    return getElementAttributes
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   744
    
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   745
"""
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   746
Methods that generates the different methods for setting and getting the attributes
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   747
"""
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   748
def generateInitMethod(bases, members, classes):
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   749
    def initMethod(self):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   750
        for base in bases:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   751
            base.__init__(self)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   752
        for attr, initial in members.items():
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   753
            setattr(self, attr, eval(initial, globals().update(classes)))
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   754
    return initMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   755
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   756
def generateSetMethod(attr, attr_type):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   757
    def setMethod(self, value):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   758
        setattr(self, attr, value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   759
    return setMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   760
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   761
def generateSetChoiceMethod(choice_type):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   762
    def setChoiceMethod(self, name, value):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   763
        self.content = {"name":name,"value":value}
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   764
    return setChoiceMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   765
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   766
def generateSetEnumMethod(enum, attr_type):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   767
    def setEnumMethod(self, value):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   768
        if value in enum:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   769
            self.value = value
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   770
        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   771
            raise ValueError, "%s is not a valid value. Must be in %s"%(value, str(enum))
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   772
    return setEnumMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   773
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   774
def generateSetLimitMethod(limit, attr_type):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   775
    def setMethod(self, value):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   776
        if "min" in limit and value < limit["min"]:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   777
            raise ValueError, "%s is not a valid value. Must be greater than %d"%(value, limit["min"])
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   778
        elif "max" in limit and value > limit["max"]:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   779
            raise ValueError, "%s is not a valid value. Must be smaller than %d"%(value, limit["max"])
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   780
        else:
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   781
            self.value = value
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   782
    return setMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   783
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   784
def generateGetMethod(attr):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   785
    def getMethod(self):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   786
        return getattr(self, attr, None)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   787
    return getMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   788
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   789
def generateAddMethod(attr, initial, classes):
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   790
    def addMethod(self):
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   791
        setattr(self, attr, eval(initial, globals().update(classes)))
75
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   792
    return addMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   793
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   794
def generateDeleteMethod(attr):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   795
    def deleteMethod(self):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   796
        setattr(self, attr, None)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   797
    return deleteMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   798
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   799
def generateAppendMethod(attr, attr_type):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   800
    def appendMethod(self, value):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   801
        getattr(self, attr).append(value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   802
    return appendMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   803
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   804
def generateInsertMethod(attr, attr_type):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   805
    def insertMethod(self, index, value):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   806
        getattr(self, attr).insert(index, value)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   807
    return insertMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   808
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   809
def generateAppendChoiceMethod(choice_types):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   810
    def appendMethod(self, name, value):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   811
        self.content.append({"name":name,"value":value})
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   812
    return appendMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   813
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   814
def generateInsertChoiceMethod(choice_types):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   815
    def insertMethod(self, index, name, value):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   816
        self.content.insert(index, {"name":name,"value":value})
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   817
    return insertMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   818
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   819
def generateRemoveMethod(attr):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   820
    def removeMethod(self, index):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   821
        getattr(self, attr).pop(index)
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   822
    return removeMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   823
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   824
def generateCountMethod(attr):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   825
    def countMethod(self):
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   826
        return len(getattr(self, attr))
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   827
    return countMethod
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   828
82d371634f15 Changed the way class are generated, using classobj from "new" module, instead of type inheritence.
etisserant
parents: 67
diff changeset
   829
"""
76
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   830
This function generate the classes from a class factory
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   831
"""
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   832
def GenerateClasses(factory, declare = False):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   833
    ComputedClasses, ComputedTypes = factory.CreateClasses()
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   834
    if declare:
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   835
        for ClassName, Class in pluginClasses.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   836
            sys._getframe(1).f_locals[ClassName] = Class
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   837
        for TypeName, Type in pluginTypes.items():
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   838
            sys._getframe(1).f_locals[TypeName] = Type
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   839
    return ComputedClasses, ComputedTypes
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   840
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   841
"""
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   842
This function opens the xsd file and generate the classes from the xml tree
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   843
"""
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   844
def GenerateClassesFromXSD(filename, declare = False):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   845
    xsdfile = open(filename, 'r')
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   846
    factory = ClassFactory(minidom.parse(xsdfile))
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   847
    xsdfile.close()
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   848
    return GenerateClasses(factory, declare)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   849
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   850
"""
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   851
This function generate the classes from the xsd given as a string
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   852
"""
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   853
def GenerateClassesFromXSDstring(xsdstring, declare = False):
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   854
    factory = ClassFactory(minidom.parseString(xsdstring))
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   855
    return GenerateClasses(factory, declare)
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   856
5bac3213fea1 xmlclass modified for allowing class definitions for multiple XSD files and indicating which classes are the base classes
lbessard
parents: 75
diff changeset
   857