1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import time
20
21 import util.uri
22
23 from util.auto_properties import auto_properties
24
25 import _impl
26 import bundle
27 import content
28 import modeled
29 import viewable
30
31 from advene.model.constants import adveneNS
32
33 from exception import AdveneException
34 from fragment import fragmentFactory, unknownFragment
35
36 from advene.model.util.defaultdict import DefaultDict
37
38 -class Annotation(modeled.Importable, content.WithContent,
39 viewable.Viewable.withClass('annotation','_get_type_uri'),
40 _impl.Authored, _impl.Dated, _impl.Uried, _impl.Tagged):
41
42 __metaclass__ = auto_properties
43
45 getNamespaceUri = staticmethod(getNamespaceUri)
46
48 getLocalName = staticmethod(getLocalName)
49
50 - def __init__(self,
51 parent,
52 element = None,
53 type = None,
54 fragment = None,
55 ident = None,
56 date = None,
57 author = None,
58 authorUrl = None,
59 context = None,
60 content_data = None,
61 content_stream = None,
62 ):
63 """
64 The constructor has two modes of calling
65 - giving it a DOM element (constructing from XML)
66 - giving it type,fragment,[ident],[date],[author],[authorUrl],
67 [context],[content_data|content_stream] (constructing from scratch)
68 """
69
70 _impl.Uried.__init__(self, parent=parent)
71 self.__fragment = None
72
73 self._relations = []
74
75 self._cached_type = type
76
77 if element is not None:
78
79 if type is not None:
80 raise TypeError("incompatible parameter 'type'")
81 if fragment is not None:
82 raise TypeError("incompatible parameter 'fragment'")
83 if ident is not None:
84 raise TypeError("incompatible parameter 'ident'")
85 if date is not None:
86 raise TypeError("incompatible parameter 'date'")
87 if author is not None:
88 raise TypeError("incompatible parameter 'author'")
89 if authorUrl is not None:
90 raise TypeError("incompatible parameter 'authorUrl'")
91 if context is not None:
92 raise TypeError("incompatible parameter 'context'")
93 if content_data is not None:
94 raise TypeError("incompatible parameter 'content_data'")
95 if content_stream is not None:
96 raise TypeError("incompatible parameter 'content_stream'")
97
98
99 modeled.Importable.__init__(self, element, parent)
100 _impl.Uried.__init__(self, parent=self.getOwnerPackage())
101
102 else:
103
104 if type is None:
105 raise TypeError("parameter 'type' required")
106 if fragment is None:
107 raise TypeError("parameter 'fragment' required")
108
109
110 doc = parent._getDocument()
111 element = doc.createElementNS(Annotation.getNamespaceUri(),
112 Annotation.getLocalName())
113 modeled.Importable.__init__(self, element, parent)
114
115 e = doc.createElementNS(None,"dummyFragment")
116 self._getModel().appendChild(e)
117
118 self.setType(type)
119
120 self.setFragment(fragment)
121
122 if ident is None:
123
124
125
126 ident = u"a" + unicode(id(self)) + unicode(time.clock()).replace('.','')
127 self.setId(ident)
128
129 if date is not None: self.setDate(date)
130 if