Orb/python/orb/XSDToPackageDef.py
author Jonathan Harrington <jonathan.harrington@nokia.com>
Wed, 11 Aug 2010 14:49:30 +0100
changeset 4 468f4c8d3d5b
permissions -rw-r--r--
Orb version 0.2.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     1
# Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     2
# This component and the accompanying materials are made available under the terms of the License 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     3
# "Eclipse Public License v1.0" which accompanies this distribution, 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     4
# and is available at the URL "http://www.eclipse.org/legal/epl-v10.html".
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     5
#
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     6
# Initial Contributors:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     7
# Nokia Corporation - initial contribution.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     8
#
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
     9
# Contributors:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    10
#
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    11
# Description:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    12
# Checks links in DITA XML and reports issues.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    13
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    14
"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    15
Created on 24 May 2010
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    16
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    17
@author: p2ross
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    18
"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    19
import os
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    20
import sys
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    21
import logging
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    22
#import pprint
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    23
#import fnmatch
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    24
#import re
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    25
import string
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    26
import time
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    27
from optparse import OptionParser#, check_choice
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    28
try:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    29
    from xml.etree import cElementTree as etree
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    30
except ImportError:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    31
    from xml.etree import ElementTree as etree
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    32
#import multiprocessing
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    33
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    34
__version__ = "0.1.0"
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    35
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    36
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    37
class XsdBase(object):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    38
    PREFIX = '{http://www.w3.org/2001/XMLSchema}'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    39
    def _addSchemaPrefix(self, theTag):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    40
        return '%s%s' % (self.PREFIX, theTag)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    41
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    42
    def _tagSchemaMatches(self, theN, theTag):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    43
        return theN.tag == self._addSchemaPrefix(theTag)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    44
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    45
    def _tagSchemaMatchesList(self, theN, theTagS):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    46
        for aTag in theTagS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    47
            if theN.tag == self._addSchemaPrefix(aTag):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    48
                return True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    49
        return False
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    50
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    51
    def _stripSchemaPrefix(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    52
        """Returns theNode.tag without the schema prefix."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    53
        return theN.tag[len(self.PREFIX):]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    54
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    55
class XsdNodeBase(XsdBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    56
    PREFIX = '{http://www.w3.org/2001/XMLSchema}'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    57
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    58
        super(XsdNodeBase, self).__init__()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    59
        self._name = theN.get('name')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    60
        self._ref = theN.get('ref')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    61
        # This will be prefix+element
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    62
        self._tag = theN.tag
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    63
        self._min = int(theN.get('minOccurs') or 1)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    64
        if theN.get('maxOccurs') == 'unbounded':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    65
            self._max = -1
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    66
        else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    67
            self._max = int(theN.get('maxOccurs') or 1)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    68
        logging.debug(
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    69
            'XsdNodeBase.__init__(): tag=%s, name=%s, ref=%s, min=%d, max=%d',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    70
            self.tag,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    71
            self._name,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    72
            self._ref,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    73
            self._min,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    74
            self._max,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    75
            )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    76
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    77
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    78
    def tag(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    79
        return self._tag[len(self.PREFIX):]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    80
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    81
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    82
    def attrRef(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    83
        return self._ref
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    84
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    85
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    86
    def attrName(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    87
        return self._name
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    88
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    89
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    90
    def isUnbounded(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    91
        return self._max == -1
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    92
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    93
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    94
    def minOccurs(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    95
        return self._min
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    96
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    97
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    98
    def maxOccurs(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
    99
        return self._max
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   100
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   101
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   102
    def boundedString(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   103
        """Returns a natural language description of bounds."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   104
        if self._min == 1 and self._max == 1:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   105
            return ''
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   106
        elif self._min == 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   107
            if self._max == 1:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   108
                # minOccurs="0" -> 'optional'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   109
                return 'optional'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   110
            elif self.isUnbounded:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   111
                # minOccurs="0" maxOccurs="unbounded" -> 'any number'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   112
                return 'any number'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   113
            else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   114
                # minOccurs="0" maxOccurs="42" -> 'up to 42'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   115
                return 'up to %d' % self._max
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   116
        elif self.isUnbounded:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   117
            # minOccurs="17" maxOccurs="unbounded" -> 'at least 17'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   118
            return 'at least %d' % self._min
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   119
        # minOccurs="17" maxOccurs="42" -> 'at least 17 and up to 42'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   120
        return 'at least %d, and up to %d' % (self._min, self._max)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   121
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   122
class Attribute(XsdNodeBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   123
    """Represents an element describing an attribute."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   124
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   125
        super(Attribute, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   126
        assert(self._tagSchemaMatches(theN, 'attribute'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   127
        self._default = theN.get('default')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   128
        self._use = theN.get('use')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   129
        
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   130
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   131
    def default(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   132
        return self._default
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   133
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   134
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   135
    def use(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   136
        return self._use
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   137
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   138
class RefBase(XsdNodeBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   139
    """Represents a reference to a group or element"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   140
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   141
        super(RefBase, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   142
        assert(self._tagSchemaMatchesList(theN, ('group', 'element')))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   143
        assert(self.attrRef is not None)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   144
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   145
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   146
    def isSequence(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   147
        return False
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   148
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   149
class RefSequence(XsdNodeBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   150
    """Holds information on an xs:all, xs:choice or xs:sequence."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   151
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   152
        super(RefSequence, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   153
        assert(self._tagSchemaMatchesList(theN, ('all', 'choice', 'sequence'))), 'Tag %s not in list' % theN.tag
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   154
        # List of class RefBase or, recursively, a class RefSequence
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   155
        self._refS = []
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   156
        self._type = self.tag
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   157
        for aChild in theN.getchildren():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   158
            if not self._tagSchemaMatchesList(aChild, ('group', 'all', 'choice', 'sequence')):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   159
                continue
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   160
            #self._type = self._stripSchemaPrefix(aChild)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   161
            if self._tagSchemaMatches(aChild, 'group'):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   162
                self._refS.append(RefBase(aChild))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   163
            elif self._tagSchemaMatchesList(
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   164
                        aChild,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   165
                        ('choice', 'sequence', 'any',)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   166
                    ):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   167
                self._refS.append(RefSequence(aChild))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   168
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   169
    def genRefs(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   170
        """Generates the list of RefBase or RefSequence"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   171
        for aRef in self._refS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   172
            yield aRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   173
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   174
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   175
    def numRefs(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   176
        return len(self._refS)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   177
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   178
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   179
    def refs(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   180
        return self._refS
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   181
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   182
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   183
    def isSequence(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   184
        return True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   185
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   186
    def qualifierString(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   187
        if self._type == 'all':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   188
            return '(any number, any order)'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   189
        elif self._type == 'choice':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   190
            return '(any number)'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   191
        elif self._type == 'sequence':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   192
            return ''
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   193
        return 'Unknown'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   194
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   195
    def joinString(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   196
        if self._type == 'all':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   197
            return ' or '
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   198
        elif self._type == 'choice':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   199
            return ' or '
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   200
        elif self._type == 'sequence':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   201
            return ' then '
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   202
        return ''
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   203
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   204
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   205
    def seqType(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   206
        return self._type
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   207
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   208
class DefBase(XsdNodeBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   209
    """Represents a definition of a group, element or complexType"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   210
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   211
        super(DefBase, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   212
        assert(self._tagSchemaMatchesList(theN, ('group', 'element', 'complexType'))), 'Tag %s not in list' % theN.tag
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   213
        assert(self.attrName is not None or self._tagSchemaMatches(theN, 'complexType'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   214
        # List of class RefBase of class RefSequence
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   215
        self._refS = []
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   216
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   217
    def genRefs(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   218
        """Generates the list of RefBase"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   219
        for aRef in self._refS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   220
            yield aRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   221
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   222
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   223
    def numRefs(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   224
        return len(self._refS)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   225
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   226
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   227
    def refs(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   228
        return self._refS
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   229
            
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   230
class GroupDef(DefBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   231
    """Represents the definition of a group i.e. <xs:group name="...">...</xs:group>.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   232
    See: http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-group"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   233
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   234
        super(GroupDef, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   235
        assert(theN.tag == self._addSchemaPrefix('group'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   236
        # http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-group
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   237
        # Content: (annotation?, (all | choice | sequence)?)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   238
        self._type = None
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   239
        for aChild in theN.getchildren():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   240
            if self._tagSchemaMatchesList(aChild, ('all', 'choice', 'sequence')):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   241
                self._type = self._stripSchemaPrefix(aChild)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   242
            else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   243
                # Unrecognised element or annotation
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   244
                continue
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   245
            if self._type is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   246
                # Read grand children and break
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   247
                for aGrandChild in aChild.getchildren():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   248
                    if aGrandChild.get('ref') is not None \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   249
                    and self._tagSchemaMatchesList(
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   250
                                aGrandChild,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   251
                                (
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   252
                                    'element',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   253
                                    'group',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   254
                                    #'choice',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   255
                                    #'sequence',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   256
                                    #'any',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   257
                                )):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   258
                        self._refS.append(RefBase(aGrandChild))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   259
                break
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   260
        
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   261
    def __str__(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   262
        #print 'TRACE:', self._refS
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   263
        return self.joinString().join(['%s' % r.attrRef for r in self._refS]) \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   264
            + ' ' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   265
            + self.qualifierString() 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   266
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   267
    def qualifierString(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   268
        if self._type == 'all':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   269
            return '(any number, any order)'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   270
        elif self._type == 'choice':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   271
            return '(any number)'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   272
        elif self._type == 'sequence':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   273
            return ''
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   274
        return 'Unknown'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   275
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   276
    def joinString(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   277
        if self._type == 'all':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   278
            return ' or '
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   279
        elif self._type == 'choice':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   280
            return ' or '
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   281
        elif self._type == 'sequence':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   282
            return ' then '
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   283
        return ''
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   284
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   285
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   286
    def groupType(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   287
        return self._type
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   288
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   289
class ComplexTypeDef(DefBase):#XsdNodeBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   290
    """Represents the definition of a complexType definition i.e. <xs:complexType name="...">...</xs:group>.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   291
    See: http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-complexType"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   292
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   293
        super(ComplexTypeDef, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   294
        assert(theN.tag == self._addSchemaPrefix('complexType'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   295
        # http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-complexType
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   296
        # Simplified content: ((group | all | choice | sequence)?
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   297
        self._type = None
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   298
        # Get xs:attribute
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   299
        self._attrS = []
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   300
        for aChild in theN.getchildren():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   301
            # We only handle complexType
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   302
            if not self._tagSchemaMatchesList(
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   303
                    aChild,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   304
                    ('group', 'all', 'choice', 'sequence', 'attribute')):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   305
                # Unrecognised element or annotation
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   306
                continue
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   307
            self._type = self._stripSchemaPrefix(aChild)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   308
            if self._tagSchemaMatches(aChild, 'group'):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   309
                self._refS.append(RefBase(aChild))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   310
            elif self._tagSchemaMatchesList(
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   311
                                aChild,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   312
                                ('choice', 'sequence', 'any',),
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   313
                                ):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   314
                self._refS.append(RefSequence(aChild))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   315
            elif self._tagSchemaMatches(aChild, 'attribute'):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   316
                self._attrS.append(Attribute(aChild))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   317
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   318
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   319
    def groupType(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   320
        return self._type
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   321
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   322
    def namedAttribute(self, theName):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   323
        """Returns an Attribute object or None."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   324
        for anA in self._attrS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   325
            if anA.attrName == theName:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   326
                return anA
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   327
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   328
class ElementDef(DefBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   329
    """Represents the definition of a element definition i.e. <xs:element name="...">...</xs:group>.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   330
    See: http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-group"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   331
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   332
        super(ElementDef, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   333
        assert(theN.tag == self._addSchemaPrefix('element'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   334
        # http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-element
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   335
        # Simplified content: (annotation?, ((simpleType | complexType)?
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   336
        self._type = None
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   337
        self._complexType = None
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   338
        for aChild in theN.getchildren():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   339
            # We only handle complexType
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   340
            if not self._tagSchemaMatchesList(aChild, ('complexType',)):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   341
                # Unrecognised element or annotation
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   342
                continue
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   343
            # Process a <complexType>
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   344
            self._complexType = ComplexTypeDef(aChild)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   345
            break
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   346
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   347
    @property
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   348
    def complexType(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   349
        return self._complexType
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   350
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   351
class GroupRef(RefBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   352
    """Represents a reference of a group i.e. <xs:group ref="..." .../>.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   353
    See: http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-group"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   354
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   355
        super(GroupRef, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   356
        assert(theN.tag == self._addSchemaPrefix('group'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   357
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   358
class ElementRef(RefBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   359
    """Represents a reference to an element i.e. <xs:element ref="..." .../>.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   360
    See: http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-group"""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   361
    def __init__(self, theN):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   362
        super(ElementRef, self).__init__(theN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   363
        assert(theN.tag == self._addSchemaPrefix('element'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   364
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   365
class XsdToPackageDef(XsdBase):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   366
    """Create a PackageDef.xml file from a set of XSD files."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   367
    DUMP_PREFIX = '  '
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   368
    def __init__(self, thePrefix):#, theOutFile=None, theTitle=''):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   369
        super(XsdToPackageDef, self).__init__()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   370
        # Maps of group definitions and references
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   371
        self._groupDefMap = {}
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   372
        self._groupRefMap = {}
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   373
        # Maps of element definitions and references
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   374
        self._elemDefMap = {}
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   375
        self._elemRefMap = {}
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   376
        # Top level complex types
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   377
        self._complexTypeMap = {}
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   378
        # Element prefix
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   379
        self._prefix = thePrefix
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   380
            
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   381
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   382
    # Section: Add an XSD file
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   383
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   384
    def addXsdFile(self, thePath):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   385
        """Read an XSD and add it to the representation."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   386
        t = etree.parse(thePath)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   387
        r = t.getroot()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   388
        self._addGroups(r)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   389
        self._addElements(r)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   390
        self._addComplexTypes(r)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   391
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   392
    def addXsdPath(self, thePath):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   393
        if os.path.isfile(thePath):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   394
            if os.path.splitext(thePath)[1].lower() == '.xsd':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   395
                self.addXsdFile(thePath)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   396
        elif os.path.isdir(thePath):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   397
            for aName in os.listdir(thePath):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   398
                self.addXsdPath(os.path.join(thePath, aName))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   399
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   400
    def _addGroups(self, root):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   401
        """Adds to the group maps."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   402
        for anE in root.getchildren():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   403
            if self._tagSchemaMatches(anE, 'group'):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   404
                if anE.get('name') is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   405
                    self._groupDefMap[anE.get('name')] = GroupDef(anE)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   406
                elif anE.get('ref') is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   407
                    self._groupRefMap[anE.get('ref')] = GroupRef(anE)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   408
                
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   409
    def _addElements(self, root):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   410
        """Adds to the element maps."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   411
        for anE in root.getchildren():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   412
            if self._tagSchemaMatches(anE, 'element'):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   413
                if anE.get('name') is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   414
                    self._elemDefMap[anE.get('name')] = ElementDef(anE)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   415
                elif anE.get('ref') is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   416
                    self._elemRefMap[anE.get('ref')] = ElementRef(anE)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   417
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   418
    def _addComplexTypes(self, root):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   419
        for anE in root.getchildren():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   420
            if self._tagSchemaMatches(anE, 'complexType'):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   421
                self._complexTypeMap[anE.get('name')] = ComplexTypeDef(anE)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   422
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   423
    # End: Add an XSD file
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   424
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   425
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   426
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   427
    # Section: Query the IR
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   428
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   429
    def elemContains(self, theElemName):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   430
        """Returns a list of immediate child elements that this element contains."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   431
        logging.debug('elemContains(%s)' % theElemName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   432
        retVal = []
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   433
        if not self._elemDefMap.has_key(theElemName):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   434
            return retVal
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   435
        myElem = self._elemDefMap[theElemName]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   436
        if myElem.complexType is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   437
            logging.debug('elemContains(): complexType: %s', myElem.complexType)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   438
            #print 'myElem', myElem
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   439
            for aRef in myElem.complexType.genRefs():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   440
                logging.debug('elemContains(): complexType tag: %s, attrRef: %s',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   441
                              aRef.tag,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   442
                              aRef.attrRef,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   443
                        )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   444
                self._addFromComplexTypeSequence(aRef, retVal)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   445
#                myRef = aRef.attrRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   446
#                #print 'myRef', myRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   447
#                #if self._elemDefMap.has_key(myRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   448
#                #    retVal.append(myRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   449
#                if self._groupDefMap.has_key(myRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   450
#                    self._addContainsGroup(myRef, retVal)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   451
#                else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   452
#                    retVal.append(myRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   453
        logging.debug('elemContains(%s) returns %s', theElemName, str(retVal))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   454
        return retVal
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   455
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   456
    def _addFromComplexTypeSequence(self, theRefObj, theList):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   457
        """Recursively add containing elements."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   458
        myRef = theRefObj.attrRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   459
        logging.debug('_addFromComplexTypeSequence(%s):', myRef) 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   460
        if theRefObj.isSequence:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   461
            for aSubRef in theRefObj.refs:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   462
                logging.debug('_addFromComplexTypeSequence(): recursing on: %s',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   463
                              myRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   464
                self._addFromComplexTypeSequence(aSubRef, theList)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   465
        elif myRef is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   466
            if self._groupDefMap.has_key(myRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   467
                self._addContainsGroup(myRef, theList)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   468
            else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   469
                logging.debug('_addFromComplexTypeSequence(): adding: %s',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   470
                              myRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   471
                theList.append(myRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   472
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   473
    def _addContainsGroup(self, theRef, theList):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   474
        logging.debug('_addContainsGroup(%s)' % theRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   475
        assert(self._groupDefMap.has_key(theRef))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   476
        for aRef in self._groupDefMap[theRef].genRefs():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   477
            #print 'TRACE: aRef', aRef.tag
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   478
            logging.debug('_addContainsGroup(): aRef.tag: %s aRef.attrRef: %s' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   479
                          % (aRef.tag, aRef.attrRef))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   480
            if aRef.tag == 'element':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   481
                theList.append(aRef.attrRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   482
            elif aRef.tag == 'group' and self._groupDefMap.has_key(aRef.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   483
                self._addContainsGroup(aRef.attrRef, theList)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   484
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   485
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   486
    # End: Query the IR
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   487
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   488
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   489
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   490
    # Section: Debug/trace
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   491
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   492
    def dump(self, s=sys.stdout):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   493
        s.write(' Group definitions '.center(75, '-')+'\n')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   494
        keyS = self._groupDefMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   495
        keyS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   496
        for k in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   497
            s.write('%40s : %s\n' % (k, self._groupDefMap[k]))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   498
        s.write(' EOL '.center(75, '-')+'\n\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   499
        s.write(' Group references '.center(75, '-')+'\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   500
        keyS = self._groupRefMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   501
        keyS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   502
        for k in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   503
            s.write('%40s : %s\n' % (k, self._groupRefMap[k]))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   504
        s.write(' EOL '.center(75, '-')+'\n\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   505
        s.write(' Element definitions '.center(75, '-')+'\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   506
        keyS = self._elemDefMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   507
        keyS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   508
        for k in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   509
            s.write('%40s : %s\n' % (k, self._elemDefMap[k]))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   510
        s.write(' EOL '.center(75, '-')+'\n\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   511
        s.write(' Element references '.center(75, '-')+'\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   512
        keyS = self._elemRefMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   513
        keyS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   514
        for k in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   515
            s.write('%40s : %s\n' % (k, self._elemRefMap[k]))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   516
        s.write(' EOL '.center(75, '-')+'\n\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   517
        s.write(' Complex types '.center(75, '-')+'\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   518
        keyS = self._complexTypeMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   519
        keyS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   520
        for k in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   521
            s.write('%40s : %s\n' % (k, self._complexTypeMap[k]))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   522
        s.write(' EOL '.center(75, '-')+'\n\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   523
        s.write(' Parent to child relationship '.center(75, '-')+'\n')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   524
        # A map {element_name : [parent element, ...], ...}
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   525
        myPcMap = self._retContainedByMap()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   526
        keyS = myPcMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   527
        keyS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   528
        for k in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   529
            s.write('Child: %s\n' % k)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   530
            s.write('    Contained by: %s\n' % myPcMap[k])
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   531
        s.write(' EOL '.center(75, '-')+'\n\n') 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   532
        # Run through the elements
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   533
        keyS = self._elemDefMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   534
        keyS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   535
        for k in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   536
            myElem = self._elemDefMap[k]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   537
            s.write('Element: %s\n' % k)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   538
            if myElem.complexType is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   539
                for aRef in myElem.complexType.genRefs():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   540
                    #print 'TRACE: aRef', aRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   541
                    if aRef.isSequence:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   542
                        self._dumpSequenceRef(s, aRef, level=1)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   543
                    else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   544
                        self._dumpRef(s, aRef, level=1)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   545
            else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   546
                s.write('  No complexType\n')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   547
            s.write('\n')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   548
            
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   549
    def _dumpRef(self, s, theRef, level=1):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   550
        assert(not theRef.isSequence)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   551
        if self._groupDefMap.has_key(theRef.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   552
            s.write('%s%s %s [%s]\n' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   553
                    % (self.DUMP_PREFIX*level,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   554
                       theRef.attrRef,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   555
                       '(group)',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   556
                       theRef.boundedString,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   557
                       #self._groupDefMap[aRef.attrRef].boundedString,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   558
                    )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   559
                )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   560
            self._dumpGroupRef(s, theRef.attrRef, level)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   561
            #for aGm in self._groupDefMap[aRef.attrRef].genRefs():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   562
            #    print '  <%s> %s %s %s' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   563
            #        % (aGm.tag, aGm.attrName, aGm.attrRef, aGm.boundedString)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   564
        elif self._elemDefMap.has_key(theRef.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   565
            s.write('%s%s %s\n' % (self.DUMP_PREFIX*level, theRef.attrRef, '(element)'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   566
        elif self._complexTypeMap.has_key(theRef.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   567
            s.write('%s%s %s\n' % (self.DUMP_PREFIX*level, theRef.attrRef, '(complex)'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   568
        else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   569
            s.write('%s%s %s\n' % (self.DUMP_PREFIX*level, theRef.attrRef, '(not in my IR)'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   570
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   571
    def _dumpGroupRef(self, s, theR, level=1):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   572
        """Dump out references to groups, recursively using self._groupDefMap."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   573
        assert(self._groupDefMap.has_key(theR))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   574
        if self._groupDefMap[theR].numRefs == 1 \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   575
        and self._groupDefMap[theR].refs[0].tag == 'element':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   576
            s.write('%sELEMENT<%s> %s %s "%s" [%s]\n' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   577
                    % (
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   578
                       self.DUMP_PREFIX*level,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   579
                       self._groupDefMap[theR].refs[0].tag,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   580
                       self._groupDefMap[theR].refs[0].attrName,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   581
                       self._groupDefMap[theR].refs[0].attrRef,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   582
                       self._groupDefMap[theR].refs[0],
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   583
                       self._groupDefMap[theR].refs[0].boundedString,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   584
                       )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   585
                )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   586
        else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   587
            s.write('%sGROUP  <%s>%s\n' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   588
                % (self.DUMP_PREFIX*level, self._groupDefMap[theR].tag, self._groupDefMap[theR]))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   589
            for aGm in self._groupDefMap[theR].genRefs():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   590
                #print '%s<%s> %s %s "%s"' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   591
                #    % (self.DUMP_PREFIX*level, aGm.tag, aGm.attrName, aGm.attrRef, aGm)#aGm.boundedString)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   592
                if aGm.tag == 'group' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   593
                and aGm.attrRef \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   594
                and self._groupDefMap.has_key(aGm.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   595
                    self._dumpGroupRef(s, aGm.attrRef, level+1)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   596
                elif aGm.tag == 'element':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   597
                    s.write('%sCHLDELE<%s> %s %s "%s"\n' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   598
                        % (self.DUMP_PREFIX*level, aGm.tag, aGm.attrName, aGm.attrRef, aGm))#aGm.boundedString)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   599
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   600
    def _dumpSequenceRef(self, s, theR, level=1):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   601
        """Dump out sequences recursively."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   602
        assert(theR.isSequence)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   603
        for i, aRef in enumerate(theR.genRefs()):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   604
            if i > 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   605
                s.write('%s[%s]\n' % (self.DUMP_PREFIX*level, theR.joinString()))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   606
            #print '%sTRACE: _dumpSequenceRef aRef: %s' % (self.DUMP_PREFIX*level, aRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   607
            if aRef.isSequence:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   608
                self._dumpSequenceRef(s, aRef, level=level+1)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   609
            else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   610
                self._dumpRef(s, aRef, level=level+1)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   611
        s.write('%s[%s]\n' % (self.DUMP_PREFIX*level, theR.qualifierString()))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   612
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   613
    # End: Debug/trace
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   614
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   615
        
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   616
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   617
    # Section: Output
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   618
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   619
    def _writeHeader(self, theS, theTitle):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   620
        self._writeLine(theS, '<?xml version="1.0" encoding="UTF-8"?>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   621
        self._writeLine(theS, """<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "../../dtd/reference.dtd">""")
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   622
        self._writeLine(theS, """<reference id="%sapiref" xml:lang="en-us">""" % self._prefix)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   623
        self._writeLine(theS, '<title>%s</title>' % theTitle)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   624
        
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   625
    def _writeLine(self, theS, theL):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   626
        theS.write(theL)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   627
        theS.write('\n')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   628
        
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   629
    def _write(self, theS, theStr):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   630
        theS.write(theStr)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   631
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   632
    def close(self, theS):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   633
        self._writeLine(theS, '</reference>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   634
        theS.close()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   635
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   636
    def _retContainedByMap(self):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   637
        """Returns a map {element_name : [parent element, ...], ...}."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   638
        retMap = {}
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   639
        keyS = self._elemDefMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   640
        # Ensure that every element is represented
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   641
        for myName in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   642
            retMap[myName] = []
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   643
        for myName in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   644
            myContainS = self.elemContains(myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   645
            for aChild in myContainS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   646
                try:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   647
                    retMap[aChild].append(myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   648
                except KeyError:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   649
                    retMap[aChild] = [myName]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   650
        return retMap
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   651
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   652
    def _retDirName(self, theName):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   653
        assert(theName.startswith(self._prefix))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   654
        # Slice the name to get the directory
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   655
        # e.g. 'cxxVariableDeclarationFile' becomes 'cxxVariable'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   656
        # Special case where all ...Ref.dita are in cxxAPIMap/
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   657
        if theName.endswith('Ref') \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   658
        or theName == 'cxxAPIMap':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   659
            return 'cxxAPIMap'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   660
        i = len(self._prefix) + 1
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   661
        while i < len(theName) and theName[i] in string.lowercase:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   662
            i += 1
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   663
        retVal = theName[:i]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   664
        # This is a bit clunky for these special cases
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   665
        if retVal in ('cxxEnumerator', 'cxxEnumerators'):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   666
            retVal = 'cxxEnumeration'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   667
        return retVal
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   668
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   669
    def _writeElementNameToFile(self, theS, theName):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   670
        if self._elemDefMap.has_key(theName) \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   671
        and theName.startswith(self._prefix):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   672
            # Slice the name to get the directory
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   673
            theDir = self._retDirName(theName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   674
            self._writeLine(theS, '<xref href="%s/%s.dita">%s</xref> ' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   675
                            % (theDir, theName, theName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   676
                        )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   677
        else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   678
            # Write out as a keyword
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   679
            self._writeLine(theS, '<keyword>%s</keyword>, ' % theName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   680
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   681
    def _writeContentModelToStream(self, theS, theName):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   682
        assert(self._elemDefMap.has_key(theName))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   683
        hasWritten = False
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   684
        myElem = self._elemDefMap[theName]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   685
        if myElem.complexType is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   686
            for aRef in myElem.complexType.genRefs():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   687
                #print 'TRACE: aRef', aRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   688
                if aRef.isSequence:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   689
                    if self._writeContentModelSequenceRef(theS, aRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   690
                        hasWritten = True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   691
                else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   692
                    if self._writeContentModelRef(theS, aRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   693
                        hasWritten = True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   694
        return hasWritten
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   695
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   696
    def _writeContentModelSequenceRef(self, theS, theR):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   697
        assert(theR.isSequence)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   698
        hasWritten = False
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   699
        if theR.numRefs > 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   700
            self._write(theS, '(')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   701
        for i, aRef in enumerate(theR.genRefs()):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   702
            if i > 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   703
                self._writeLine(theS, ' %s ' % theR.joinString())
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   704
                hasWritten = True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   705
            if aRef.isSequence:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   706
                if self._writeContentModelSequenceRef(theS, aRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   707
                    hasWritten = True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   708
            else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   709
                if self._writeContentModelRef(theS, aRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   710
                    hasWritten = True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   711
        if theR.qualifierString():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   712
            self._writeLine(theS, '<i>%s</i>' % theR.qualifierString())
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   713
        if theR.numRefs > 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   714
            self._write(theS, ')')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   715
        return hasWritten
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   716
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   717
    def _writeContentModelRef(self, theS, theR):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   718
        assert(not theR.isSequence)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   719
        hasWritten = False
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   720
        if self._groupDefMap.has_key(theR.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   721
            #s.write('%s %s\n' % (theR.attrRef, '(group)'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   722
            self._writeContentModelGroupRefToStream(theS, theR)#.attrRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   723
            hasWritten = True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   724
        elif self._elemDefMap.has_key(theR.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   725
            pass#s.write('%s %s\n' % (theR.attrRef, '(element)'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   726
        elif self._complexTypeMap.has_key(theR.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   727
            pass#s.write('%s %s\n' % (theR.attrRef, '(complex)'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   728
        else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   729
            #s.write('%s %s\n' % (theR.attrRef, '(not in my IR)'))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   730
            self._writeLine(theS, '<keyword>%s</keyword>, ' % theR.attrRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   731
            hasWritten = True
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   732
        return hasWritten
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   733
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   734
    def _writeContentModelGroupRefToStream(self, theS, theR):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   735
        assert(self._groupDefMap.has_key(theR.attrRef))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   736
        myGroup = self._groupDefMap[theR.attrRef]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   737
        if myGroup.numRefs == 1 \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   738
        and myGroup.refs[0].tag == 'element':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   739
#            s.write('%sELEMENT<%s> %s %s "%s"\n' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   740
#                    % (
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   741
#                       self.DUMP_PREFIX*level,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   742
#                       self._groupDefMap[theR.attrRef].refs[0].tag,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   743
#                       self._groupDefMap[theR.attrRef].refs[0].attrName,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   744
#                       self._groupDefMap[theR.attrRef].refs[0].attrRef,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   745
#                       self._groupDefMap[theR.attrRef].refs[0],
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   746
#                       )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   747
#                )
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   748
            #self._write(theS, '(')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   749
            aN = myGroup.refs[0].attrRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   750
            self._writeElementNameToFile(theS, aN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   751
            #self._writeLine(theS, '<xref href="%s/%s.dita">%s</xref>, %s' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   752
            #                % (aN, aN, aN, theR.boundedString))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   753
            if theR.boundedString:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   754
                self._writeLine(theS, '(<i>%s</i>)' % theR.boundedString)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   755
            #self._write(theS, ')')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   756
        else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   757
            #s.write('%sGROUP  <%s>%s\n' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   758
            #    % (self.DUMP_PREFIX*level, self._groupDefMap[theR.attrRef].tag, self._groupDefMap[theR.attrRef]))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   759
            if myGroup.numRefs > 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   760
                self._write(theS, '(')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   761
            for i, aGm in enumerate(myGroup.genRefs()):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   762
                #print '%s<%s> %s %s "%s"' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   763
                #    % (self.DUMP_PREFIX*level, aGm.tag, aGm.attrName, aGm.attrRef, aGm)#aGm.boundedString)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   764
                if i > 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   765
                    self._writeLine(theS, myGroup.joinString())
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   766
                if aGm.tag == 'group' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   767
                and aGm.attrRef \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   768
                and self._groupDefMap.has_key(aGm.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   769
                    self._writeContentModelGroupRefToStream(theS, aGm)#.attrRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   770
                elif aGm.tag == 'element' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   771
                and aGm.attrRef:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   772
                    self._writeElementNameToFile(theS, aGm.attrRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   773
                    #if self._elemDefMap.has_key(aGm.attrRef):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   774
                    #    aN = aGm.attrRef
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   775
                    #    self._writeLine(theS, '<xref href="%s/%s.dita">%s</xref>, ' % (aN, aN, aN))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   776
                    #else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   777
                    #    self._writeLine(theS, '<keyword>%s</keyword>, ' % aGm.attrRef)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   778
                #elif aGm.tag == 'element':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   779
                #    s.write('%sCHLDELE<%s> %s %s "%s"\n' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   780
                #        % (self.DUMP_PREFIX*level, aGm.tag, aGm.attrName, aGm.attrRef, aGm))#aGm.boundedString)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   781
            self._writeLine(theS, self._groupDefMap[theR.attrRef].qualifierString())
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   782
            if myGroup.numRefs > 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   783
                self._write(theS, ')')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   784
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   785
    def writeToFile(self, thePath, theTitle):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   786
        myS = open(thePath, 'w')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   787
        self._writeHeader(myS, theTitle)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   788
        #self.dump()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   789
        myChildParentMap = self._retContainedByMap()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   790
        #print 'TRACE: myChildParentMap', myChildParentMap
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   791
        # Run through the elements
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   792
        keyS = self._elemDefMap.keys()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   793
        keyS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   794
        for myName in keyS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   795
            myElem = self._elemDefMap[myName]
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   796
            logging.info('Writing element: <%s>' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   797
            self._writeLine(myS, '<reference id="%s-reference" xml:lang="en-us">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   798
            self._writeLine(myS, '<title>Element: %s</title>' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   799
            self._writeLine(myS, '<refbody>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   800
            # Section: Contained by
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   801
            self._writeLine(myS, '<section id="%s-containedBy-section" outputclass="elementContainedBy">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   802
            self._writeLine(myS, '<title>Contained by</title>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   803
            self._writeLine(myS, '<p id="%s-containedBy-p">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   804
            for aParent in myChildParentMap[myName]:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   805
                self._writeElementNameToFile(myS, aParent)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   806
                #if self._elemDefMap.has_key(aParent):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   807
                #    self._writeLine(myS, '<xref href="%s/%s.dita">%s</xref>, ' \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   808
                #                    % (aParent, aParent, aParent))
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   809
                #else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   810
                #    # Write out as a keyword
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   811
                #    self._writeLine(myS, '<keyword>%s</keyword>, ' % aParent)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   812
            self._writeLine(myS, '</p>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   813
            self._writeLine(myS, '</section>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   814
            # Section: Contains
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   815
            self._writeLine(myS,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   816
                '<section id="%s-contains-section" outputclass="elementContains">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   817
            self._writeLine(myS, '<title>Contains</title>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   818
            self._writeLine(myS, '<p id="%s-contains-p">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   819
            myContainS = self.elemContains(myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   820
            myContainS.sort()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   821
            #print 'myContainS', myContainS
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   822
            for aN in myContainS:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   823
                self._writeElementNameToFile(myS, aN)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   824
            self._writeLine(myS, '</p>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   825
            self._writeLine(myS, '</section>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   826
            # Section: Content Model
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   827
            self._writeLine(myS, '<section id="%s-contentModel-section" outputclass="elementContentModel">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   828
            self._writeLine(myS, '<title>Content Model</title>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   829
            self._writeLine(myS, '<p id="%s-contentModel-p">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   830
            # Content model contents
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   831
            if not self._writeContentModelToStream(myS, myName):
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   832
                self._writeLine(myS, 'No content.')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   833
            self._writeLine(myS, '</p>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   834
            self._writeLine(myS, '</section>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   835
            # Section: Attributes - empty
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   836
            self._writeLine(myS, '<section id="%s-attList-section" outputclass="elementAttList" />' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   837
            # Section: classValue
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   838
            self._writeLine(myS, '<section id="%s-classValue-section" outputclass="elementClassValue">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   839
            self._writeLine(myS, '<title>Inheritance</title>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   840
            self._writeLine(myS, '<p id="%s-classValue-p">' % myName)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   841
            if myElem.complexType is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   842
                myClassAttr = myElem.complexType.namedAttribute('class')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   843
                if myClassAttr is not None \
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   844
                and myClassAttr.default is not None:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   845
                    #print 'TRACE: myClassAttr.default: "%s"' % myClassAttr.default
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   846
                    for aStr in myClassAttr.default[1:].strip().split():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   847
                        if aStr.find('/') != -1:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   848
                            a,b = aStr.split('/')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   849
                            myS.write(' %s/' % a)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   850
                            myS.write('<keyword>%s</keyword>' % b)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   851
            self._writeLine(myS, '</p>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   852
            self._writeLine(myS, '</section>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   853
            self._writeLine(myS, '</refbody>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   854
            self._writeLine(myS, '</reference>')
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   855
        self.close(myS)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   856
    
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   857
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   858
    # End: Output
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   859
    ##########################
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   860
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   861
def main():
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   862
    usage = """usage: %prog [options] file_or_dir
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   863
Takes a XSD file or directory and generates a packagedef.dita file with
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   864
the documentation for the XSD file(s)."""
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   865
    print 'Cmd: %s' % ' '.join(sys.argv)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   866
    optParser = OptionParser(usage, version='%prog ' + __version__)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   867
    optParser.add_option("-d", action="store_true", dest="dump", default=False, 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   868
                      help="Dump IR (for debugging). [default: %default]")
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   869
    optParser.add_option(
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   870
            "-l", "--loglevel",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   871
            type="int",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   872
            dest="loglevel",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   873
            default=20,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   874
            help="Log Level (debug=10, info=20, warning=30, error=40, critical=50) [default: %default]"
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   875
        )      
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   876
    optParser.add_option("-o", "--out",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   877
                         type="string",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   878
                         dest="output",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   879
                         default=None, 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   880
                         help="Output file. [default: %default]")
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   881
#===============================================================================
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   882
#    optParser.add_option("-u", "--unittest",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   883
#                         action="store_true",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   884
#                         dest="unit_test",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   885
#                         default=False, 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   886
#                         help="Execute unit tests. [default: %default]")
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   887
#===============================================================================
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   888
    optParser.add_option("-t", "--title", type="string", dest="title",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   889
                         default='C++ API Reference Content Model Definitions', 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   890
                         help="Title for the packagedef.dita. [default: %default]")
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   891
    optParser.add_option("-p", "--prefix", type="string", dest="prefix",
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   892
                         default='cxx', 
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   893
                         help="Prefix, only the elements starting with this will be documented. Use '' for all. [default: %default]")
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   894
    opts, args = optParser.parse_args()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   895
    clkStart = time.clock()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   896
    # Initialise logging etc.
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   897
    logging.basicConfig(level=opts.loglevel,
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   898
                    format='%(asctime)s %(levelname)-8s %(message)s',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   899
                    #datefmt='%y-%m-%d % %H:%M:%S',
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   900
                    stream=sys.stdout)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   901
#===============================================================================
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   902
#    if opts.unit_test:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   903
#        unitTest()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   904
#===============================================================================
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   905
    if len(args) > 0:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   906
        # Your code here
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   907
        myX = XsdToPackageDef(opts.prefix)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   908
        for aFile in args:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   909
            myX.addXsdPath(aFile)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   910
        myX.writeToFile(opts.output, opts.title)
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   911
        if opts.dump:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   912
            myX.dump()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   913
    else:
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   914
        optParser.print_help()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   915
        optParser.error("No arguments!")
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   916
        return 1
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   917
    clkExec = time.clock() - clkStart
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   918
    print 'CPU time = %8.3f (S)' % clkExec
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   919
    print 'Bye, bye!'
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   920
    return 0
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   921
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   922
if __name__ == '__main__':
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   923
    #multiprocessing.freeze_support()
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   924
    sys.exit(main())
468f4c8d3d5b Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff changeset
   925