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