[rhmessaging-commits] rhmessaging commits: r2270 - mgmt/trunk/cumin/python/cumin.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Fri Aug 8 10:04:02 EDT 2008
Author: eallen
Date: 2008-08-08 10:04:01 -0400 (Fri, 08 Aug 2008)
New Revision: 2270
Modified:
mgmt/trunk/cumin/python/cumin/binding.py
mgmt/trunk/cumin/python/cumin/queue.py
Log:
Refactor bindings so that each binding type does it's own input processing.
Modified: mgmt/trunk/cumin/python/cumin/binding.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/binding.py 2008-08-08 12:57:24 UTC (rev 2269)
+++ mgmt/trunk/cumin/python/cumin/binding.py 2008-08-08 14:04:01 UTC (rev 2270)
@@ -137,6 +137,10 @@
def render_xquery_value(self, session, exchange):
return self.get_exchange_info_for(session, exchange, "xquery")
+ def process_input(self, this_exchange, arguments):
+ if "xquery" in this_exchange:
+ arguments["xquery"] = this_exchange["xquery"]
+
class HeadersExchangeInput(BindingKeyExchangeInput):
def __init__(self, app, name, form):
super(HeadersExchangeInput, self).__init__(app, name, form)
@@ -199,6 +203,30 @@
def render_headers_extra(self, session, exchange):
return "headers_extra.%s" % str(exchange.id)
+
+ def process_input(self, this_exchange, arguments):
+ # x-match is a radio button, it must have a value
+ arguments["x-match"] = this_exchange["x-match"]
+ # Fill out the other arguments.
+ # The form has input boxes named mkey.* and mkey.*.nv
+ # We need to create an arguments dictionary entry
+ # of the form {mkey.*.value: mkey.*.nv.value}
+ for match_info in this_exchange:
+ if this_exchange[match_info]:
+ if match_info.startswith("mkey") \
+ and not match_info.endswith("nv"):
+ # find the value in the matching .nv field
+ match_value = self._find_match_value(this_exchange, match_info)
+ # it is valid for the value in the .nv field
+ # to be empty
+ arguments[this_exchange[match_info]] = \
+ match_value or None
+
+ def _find_match_value(self, this_exchange, match_info):
+ for m_info in this_exchange:
+ if m_info.startswith(match_info):
+ if m_info.endswith("nv"):
+ return this_exchange[m_info]
class ExchangeState(StateSwitch):
def __init__(self, app, name):
@@ -290,7 +318,7 @@
return writer.to_string()
- def get_binding_info(self, session, queue_name):
+ def get_binding_errors(self, session, queue_name):
form_binding_info = self.process_binding_info(session, queue_name)
binding_info = self.dict_param.get(session)
@@ -322,7 +350,7 @@
name = form_binding_info[exchange]["name"]
errs = berrs.setdefault(name, dict())
errs["key"] = ["A binding key is required"]
- if not "xquery" in form_binding_info[exchange]:
+ if not "xquery" in binding_info[exchange]:
name = binding_info[exchange]["name"]
if not name in berrs:
berrs.setdefault(name, dict())
@@ -341,51 +369,31 @@
return (len(berrs), form_binding_info)
def process_binding_info(self, session, queue_name):
+ """ Processes the raw binding_info from the DictParameter into
+ a "form_binding_info" dictionary that contains four keys:
+ name, key, arguments, and type
+ """
binding_info = self.dict_param.get(session)
form_binding_info = dict()
for this_exchange in binding_info:
# if the exchange checkbox is checked
if "name" in binding_info[this_exchange]:
- form_binding_info[this_exchange] = dict()
- arguments = dict()
type = binding_info[this_exchange]["type"]
- if type == "headers":
- arguments["x-match"] = binding_info[this_exchange]["x-match"]
+ if type == "direct":
+ binding_info[this_exchange]["key"] = queue_name
- # Fill out the other arguments.
- # The form has input boxes named mkey.* and mkey.*.nv
- # We need to create an arguments dictionary entry
- # of the form {mkey.*.value: mkey.*.nv.value}
- for match_info in binding_info[this_exchange]:
- if binding_info[this_exchange][match_info]:
- if match_info.startswith("mkey") \
- and not match_info.endswith("nv"):
- # find the value in the matching .nv field
- match_value = self._find_match_value(binding_info,
- this_exchange, match_info)
- # it is valid for the value in the .nv field
- # to be empty
- arguments[binding_info[this_exchange][match_info]] = \
- match_value or None
- elif type == "xml":
- if "xquery" in binding_info[this_exchange]:
- arguments["xquery"] = binding_info[this_exchange]["xquery"]
- elif type == "direct":
- binding_info[this_exchange]["key"] = queue_name
- #topic and fanout exchanges don't need any processing
-
+ form_binding_info[this_exchange] = dict()
form_binding_info[this_exchange]["name"] = binding_info[this_exchange]["name"]
if "key" in binding_info[this_exchange]:
form_binding_info[this_exchange]["key"] = binding_info[this_exchange]["key"]
+ form_binding_info[this_exchange]["type"] = type
+
+ arguments = dict()
+ if type == "headers":
+ self.headers_input.process_input(binding_info[this_exchange], arguments)
+ elif type == "xml":
+ self.xml_input.process_input(binding_info[this_exchange], arguments)
+ #direct, topic and fanout exchanges don't have aditional arguments
form_binding_info[this_exchange]["arguments"] = arguments
- # type is used in form validation only
- form_binding_info[this_exchange]["type"] = binding_info[this_exchange]["type"]
return form_binding_info
-
- def _find_match_value(self, binding_info, this_exchange, match_info):
- for m_info in binding_info[this_exchange]:
- if m_info.startswith(match_info):
- if m_info.endswith("nv"):
- return binding_info[this_exchange][m_info]
-
Modified: mgmt/trunk/cumin/python/cumin/queue.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/queue.py 2008-08-08 12:57:24 UTC (rev 2269)
+++ mgmt/trunk/cumin/python/cumin/queue.py 2008-08-08 14:04:01 UTC (rev 2270)
@@ -351,7 +351,7 @@
def validate(self, session, queue_name):
super_error = super(QueueForm, self).validate(session)
- (errors, form_binding_info) = self.bindings.get_binding_info(session, queue_name)
+ (errors, form_binding_info) = self.bindings.get_binding_errors(session, queue_name)
return (errors or super_error, form_binding_info)
class QueueAdd(QueueForm):
@@ -532,7 +532,7 @@
def process_submit(self, session):
queue = self.frame.get_object(session)
- (errors, form_binding_info) = self.bindings.get_binding_info(session, queue.name)
+ (errors, form_binding_info) = self.bindings.get_binding_errors(session, queue.name)
if not len(form_binding_info):
# no exhchanges were selected is not an
More information about the rhmessaging-commits
mailing list