Join.py :  » Database » Modeling-Framework » Modeling-0.9 » Modeling » 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 » Database » Modeling Framework 
Modeling Framework » Modeling 0.9 » Modeling » Join.py
# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sbastien Bigaret <sbigaret@users.sourceforge.net>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------


""" ... describe me please I feel alone...

  CVS information

    $Id: Join.py 932 2004-07-20 06:21:57Z sbigaret $
"""

__version__='$Revision: 932 $'[11:-2]

from Modeling.utils import isaValidName

import types

from Modeling.XMLutils import *

class Join(XMLCapability):
  "Describe a join"
  def __init__(self, aSrcAttribute, aDestAttribute):
    "Initializes a join."
    self._destAttribute = aDestAttribute
    self._srcAttribute  = aSrcAttribute

  def validateObject(self, aJoin):
    "Checks whether the supplied object is valid"
    raise "Unimplemented"

  def destinationAttribute(self):
    "Returns the destination attribute referenced by the join"
    return self._destAttribute

  def destinationAttributeIdentifier(self):
    """
    Returns the destination attribute's string identifier referenced by the
    join.
    See also: Attribute.__str__
    """
    return str(self._destAttribute)

  def destinationAttributeName(self):
    """
    Returns the destination attribute's name
    See also: destinationAttribute, destinationAttributeIdentifier
    """
    return self._destAttribute.name()

  def isReciprocicalToJoin(self, aJoin):
    """
    Tells whether the supplied join is reciprocical to the receiver.
    Two joins are reciprocical iff aJoin's source (resp. destination) is equal
    to the receiver's destination (resp. source).
    Returns integer '1' for true, '0' for false
    """
    if aJoin.destinationAttribute()==self.sourceAttribute() and \
       aJoin.sourceAttribute()==self.destinationAttribute():
      return 1
    return 0

  def sourceAttribute(self):
    "Returns the source attribute referenced by the join"
    return self._srcAttribute

  def sourceAttributeIdentifier(self):
    """
    Returns the source attribute's string identifier referenced by the join.
    See also: Attribute.__str__
    """
    return str(self._srcAttribute)

  def sourceAttributeName(self):
    """
    Returns the source attribute's name
    See also: sourceAttribute, sourceAttributeIdentifier
    """
    return self._srcAttribute.name()

  def __eq__(self, aJoin):
    "Tests two joins for equality"
    if self._srcAttribute != aJoin._srcAttribute or \
       self._destAttribute != aJoin._destAttribute:
      return 0
    return 1

  # XML
  def initWithXMLDOMNode(self, aNode, encoding='iso-8859-1'):
    """
    Cannot be called: initialization from XML is made by relationships.
    Raises NotImplementedError.
    """
    # Just a reminder
    raise NotImplementedError, 'Calling it on a join is a nonsense'
  
  def getXMLDOM(self, doc=None, parentNode=None, encoding='iso-8859-1'):
    """
    Returns the (DOM) DocumentObject for the receiver.

    Parameters 'doc' and 'parentDoc' should be both omitted or supplied.
    If they are omitted, a new DocumentObject is created.
    If they are supplied, elements are added to the parentNode.

    Returns: the (possibly new) DocumentObject.
    """
    if (doc is None) ^ (parentNode is None):
      raise ValueError, "Parameters 'doc' and 'parentNode' should be together supplied or omitted"
    if doc is None:
      doc=createDOMDocumentObject('join')
      parentNode=doc.documentElement
      node=parentNode
    else:
      node=doc.createElement('join')
      parentNode.appendChild(node)

    exportAttrDict=self.xmlAttributesDict()
    for attr in exportAttrDict.keys():
      value=self.xmlGetAttribute(attr)()
      value=strToUnicode(str(value), encoding)
      node.setAttribute(attr, value)

    return doc

  def xmlAttributesDict(self):
    "."
    return {
      'sourceAttribute'       : ('string',
                                 lambda self=None,p=None: None,
                                 self.sourceAttributeName),
      'destinationAttribute' : ('string',
                                 lambda self=None,p=None: None,
                                 self.destinationAttributeName),
      }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.