| Trees | Indices | Help |
|
|---|
|
|
1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the (LGPL) GNU Lesser General Public License as
3 # published by the Free Software Foundation; either version 3 of the
4 # License, or (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU Library Lesser General Public License for more details at
10 # ( http://www.gnu.org/licenses/lgpl.html ).
11 #
12 # You should have received a copy of the GNU Lesser General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # written by: Jeff Ortel ( jortel@redhat.com )
16
17 """
18 The I{query} module defines a class for performing schema queries.
19 """
20
21 from logging import getLogger
22 from suds import *
23 from suds.sudsobject import *
24 from suds.xsd import qualify, isqref
25 from suds.xsd.sxbuiltin import Factory
26
27 log = getLogger(__name__)
28
29
31 """
32 Schema query base class.
33 """
34
36 """
37 @param ref: The schema reference being queried.
38 @type ref: qref
39 """
40 Object.__init__(self)
41 self.id = objid(self)
42 self.ref = ref
43 self.history = []
44 self.resolved = False
45 if not isqref(self.ref):
46 raise Exception('%s, must be qref' % tostr(self.ref))
47
49 """
50 Execute this query using the specified schema.
51 @param schema: The schema associated with the query. The schema
52 is used by the query to search for items.
53 @type schema: L{schema.Schema}
54 @return: The item matching the search criteria.
55 @rtype: L{sxbase.SchemaObject}
56 """
57 raise Exception, 'not-implemented by subclass'
58
60 """
61 Filter the specified result based on query criteria.
62 @param result: A potential result.
63 @type result: L{sxbase.SchemaObject}
64 @return: True if result should be excluded.
65 @rtype: boolean
66 """
67 if result is None:
68 return True
69 reject = ( result in self.history )
70 if reject:
71 log.debug('result %s, rejected by\n%s', Repr(result), self)
72 return reject
73
75 """
76 Query result post processing.
77 @param result: A query result.
78 @type result: L{sxbase.SchemaObject}
79 """
80 if result is None:
81 log.debug('%s, not-found', self.ref)
82 return
83 if self.resolved:
84 result = result.resolve()
85 log.debug('%s, found as: %s', self.ref, Repr(result))
86 self.history.append(result)
87 return result
88
89
91 """
92 Schema query class that I{blindly} searches for a reference in
93 the specified schema. It may be used to find Elements and Types but
94 will match on an Element first. This query will also find builtins.
95 """
96
98 if schema.builtin(self.ref):
99 name = self.ref[0]
100 b = Factory.create(schema, name)
101 log.debug('%s, found builtin (%s)', self.id, name)
102 return b
103 result = None
104 for d in (schema.elements, schema.types):
105 result = d.get(self.ref)
106 if self.filter(result):
107 result = None
108 else:
109 break
110 if result is None:
111 eq = ElementQuery(self.ref)
112 eq.history = self.history
113 result = eq.execute(schema)
114 return self.result(result)
115
116
118 """
119 Schema query class that searches for Type references in
120 the specified schema. Matches on root types only.
121 """
122
133
134
136 """
137 Schema query class that searches for Group references in
138 the specified schema.
139 """
140
146
147
149 """
150 Schema query class that searches for Attribute references in
151 the specified schema. Matches on root Attribute by qname first, then searches
152 deep into the document.
153 """
154
156 result = schema.attributes.get(self.ref)
157 if self.filter(result):
158 result = self.__deepsearch(schema)
159 return self.result(result)
160
171
172
174 """
175 Schema query class that searches for attributeGroup references in
176 the specified schema.
177 """
178
184
185
187 """
188 Schema query class that searches for Element references in
189 the specified schema. Matches on root Elements by qname first, then searches
190 deep into the document.
191 """
192
194 result = schema.elements.get(self.ref)
195 if self.filter(result):
196 result = self.__deepsearch(schema)
197 return self.result(result)
198
209
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Jun 20 03:54:30 2014 | http://epydoc.sourceforge.net |