1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""RelationshipBase
15
16 RelationshipBase is the base class for RelationshipManager
17 and ToManyRelationship.
18
19 $Id: RelationshipBase.py,v 1.26 2003/10/03 16:16:01 edahl Exp $"""
20
21 __version__ = "$Revision: 1.26 $"[11:-2]
22
23 import logging
24 log = logging.getLogger("zen.Relations")
25
26 from Globals import InitializeClass
27 from Acquisition import aq_base
28 from zope import interface
29
30 from Products.ZenRelations.Exceptions import *
31 from Products.ZenRelations.utils import importClass
32
33 from PrimaryPathObjectManager import PrimaryPathManager
34
35 from zope.event import notify
36 from OFS.event import ObjectWillBeAddedEvent
37 from OFS.event import ObjectWillBeRemovedEvent
38 from zope.container.contained import dispatchToSublocations
39 from zope.container.contained import ObjectAddedEvent
40 from zope.container.contained import ObjectRemovedEvent
41 from zope.container.contained import ContainerModifiedEvent
42
44 """
45 Marker interface.
46 """
47
49 """
50 Abstract base class for all relationship classes.
51 """
52 interface.implements(IRelationship)
53
54 _operation = -1
55
57 """Return the contents of this relation."""
58 raise NotImplementedError
59
60
63
64
66 """Does this relationship relate to obj."""
67 raise NotImplementedError
68
69
70 - def _add(self, obj):
71 """Add object to local side of relationship."""
72 raise NotImplementedError
73
74
75 - def _remove(self,obj=None, suppress_events=False):
76 """
77 Remove object from local side of relationship.
78 If obj=None remove all object in the relationship
79 """
80 raise NotImplementedError
81
82
84 """Remove obj form the remote side of this relationship."""
85 raise NotImplementedError
86
87
105
106
108 """remove an object from a relationship"""
109 self._remoteRemove(obj)
110 self._remove(obj, suppress_events=suppress_events)
111
112
114 """Return the type of the remote end of our relationship."""
115 schema = self.__primary_parent__.lookupSchema(self.id)
116 return schema.remoteType
117
118
120 """Return the type of the remote end of our relationship."""
121 schema = self.__primary_parent__.lookupSchema(self.id)
122 return schema.remoteType.__name__
123
124
126 """Return the class at the remote end of our relationship."""
127 classdef = getattr(aq_base(self), "_v_remoteClass", None)
128 if not classdef:
129 schema = self.__primary_parent__.lookupSchema(self.id)
130 classdef = importClass(schema.remoteClass)
131 self._v_remoteClass = classdef
132 return classdef
133
134
136 """Return the name at the remote end of our relationship."""
137 schema = self.__primary_parent__.lookupSchema(self.id)
138 return schema.remoteName
139
140
142 """Return our parent object by our primary path"""
143 return self.__primary_parent__.primaryAq()
144
145
147 """
148 Return the local class of this relationship. For all relationshps
149 this is the class of our __primary_parent___.
150 """
151 return self.__primary_parent__.__class__
152
153
155 """Don't let relationships move off their managers"""
156 return 0
157
158
160 """Don't let relationships move off their managers"""
161 return 0
162
163
165 """Check to make sure that relationship bidirectionality is ok.
166 """
167 return
168
169
170 InitializeClass(RelationshipBase)
171