PyutXmlV4.py :  » UML » Python-UML-Tool » pyut-1.4.0 » src » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » UML » Python UML Tool 
Python UML Tool » pyut 1.4.0 » src » PyutXmlV4.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

__version__ = "$Revision: 1.7 $"
__author__ = "EI5, eivd, Group Burgbacher - Waelti"
__date__ = "2002-1-9"

from PyutClass import *
from PyutParam import *
from PyutMethod import *
from PyutField import *
from PyutStereotype import *
from PyutType import *
from PyutConsts import *

# reading file
from StringIO import StringIO
from UmlFrame import *
from OglClass import OglClass
from OglLink import *
from OglAssociation import *
#import lang
import PyutXmlV3

def secure_int(x):
    if x is None:
        return 0
    elif x=="_DeprecatedNonBool: False":
        return 0
    elif x=="_DeprecatedNonBool: True":
        return 1
    else:
        return int(x)

class PyutXml(PyutXmlV3.PyutXml):
    """
    Class for saving and loading a PyUT UML diagram in XML.
    This class offers two main methods that are save() and load().
    Using the dom XML model, you can, with the saving method, get the
    diagram corresponding XML view. For loading, you have to parse
    the file and indicate the UML frame on which you want to draw
    (See `UmlFrame`).

    Sample use::

        # Write
        pyutXml = PyutXml()
        text = pyutXml.save(oglObjects)
        file.write(text)

        # Read
        dom = parse(StringIO(file.read()))
        pyutXml = PyutXml()
        myXml.open(dom, umlFrame)

    :version: $Revision: 1.7 $
    :author: Philippe Waelti
    :contact: pwaelti@eivd.ch
    """

    #>------------------------------------------------------------------------
    def __init__(self):
        """
        Constructor
        @author C.Dutoit
        """
        self._this_version = 4


#>------------------------------------------------------------------------
    #    Here begin saving file
#>------------------------------------------------------------------------



    def _PyutClass2xml(self, pyutClass, xmlDoc):
        """
        Exporting an PyutClass to an miniDom Element.

        @param PyutMethod pyutClass : Class to save
        @param xmlDoc : xml document
        @return Element : XML Node
        @author Deve Roux <droux@eivd.ch>
        @modified C.Dutoit/20021121 added display properties
        """
        root = xmlDoc.createElement('Class')

        # ID
        root.setAttribute('id', str(pyutClass.getId()))

        # class name
        root.setAttribute('name', pyutClass.getName())

        # classs stereotype
        stereotype = pyutClass.getStereotype()
        if stereotype is not None:
            root.setAttribute('stereotype', stereotype.getStereotype())

        # description (pwaelti@eivd.ch)
        root.setAttribute('description', pyutClass.getDescription())

        # filename (lb@alawa.ch)
        root.setAttribute('filename', pyutClass.getFilename())

        # display properties (cd)
        root.setAttribute('showMethods', str(pyutClass.getShowMethods()))
        root.setAttribute('showFields',  str(pyutClass.getShowFields()))
        root.setAttribute('showStereotype', str(pyutClass.getShowStereotype()))



        # methods
        for method in pyutClass.getMethods():
            root.appendChild(self._PyutMethod2xml(method, xmlDoc))

        # fields
        for field in pyutClass.getFields():
            root.appendChild(self._PyutField2xml(field, xmlDoc))

        return root




#>------------------------------------------------------------------------
    #   Here begins reading file
#>------------------------------------------------------------------------



    #>--------------------------------------------------------------------

    def _getOglClasses(self, xmlOglClasses, dicoOglObjects, dicoLink, \
            dicoFather, umlFrame):
        """
        Parse the XML elements given and build data layer for PyUT classes.
        If file is version 1.0, the dictionary given will contain, for key,
        the name of the OGL object. Otherwise, it will be the ID
        (multi-same-name support from version 1.1). Everything is fixed
        later.

        @param Element[] xmlOglClasses : XML 'GraphicClass' elements
        @param {id / srcName, OglObject} dicoOglObjects : OGL objects loaded
        @param {id / srcName, OglLink} dicoLink : OGL links loaded
        @param {id / srcName, id / srcName} fathers: Inheritance
        @param UmlFrame umlFrame : Where to draw
        @author Philippe Waelti <pwaelti@eivd.ch>
        @modified C.Dutoit/20021121 added display properties
        """
        for xmlOglClass in xmlOglClasses:

            pyutClass = PyutClass()
            # Building OGL class
            height = float(xmlOglClass.getAttribute('height'))
            width = float(xmlOglClass.getAttribute('width'))
            oglClass = OglClass(pyutClass, width, height)

            # Data layer class
            xmlClass = xmlOglClass.getElementsByTagName('Class')[0]

            pyutClass.setId(int(xmlClass.getAttribute('id')))

            # adding name for this class
            pyutClass.setName(xmlClass.getAttribute('name').encode("charmap"))

            # adding description
            pyutClass.setDescription(xmlClass.getAttribute('description'))

            # adding stereotype
            if xmlClass.hasAttribute('stereotype'):
                pyutClass.setStereotype(
                    getPyutStereotype(xmlClass.getAttribute('stereotype')))

            # adding display properties (cd)
            value = secure_int(xmlClass.getAttribute('showStereotype'))
            pyutClass.setShowStereotype(value)
            value = secure_int(xmlClass.getAttribute('showMethods'))
            pyutClass.setShowMethods(value)
            value = secure_int(xmlClass.getAttribute('showFields'))
            pyutClass.setShowFields(value)

            # adding associated filename (lb@alawa.ch)
            pyutClass.setFilename(xmlClass.getAttribute('filename'))

            # adding methods for this class
            pyutClass.setMethods(self._getMethods(xmlClass))

            # adding fields for this class
            pyutClass.setFields(self._getFields(xmlClass))

            dicoOglObjects[pyutClass.getId()] = oglClass

            # Adding OGL class to UML Frame
            x = float(xmlOglClass.getAttribute('x'))
            y = float(xmlOglClass.getAttribute('y'))
            umlFrame.addShape(oglClass, x, y)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.