# -*- 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),
}
|