Skip navigation


Message Rendering

Each time you select a JMS message in the user interface, Hermes uses a collection of message renderers to try and display the message in meaningful ways, for example in hexadecimal, pretty printed XML or decoded FIX.

The Most Simple Renderer

This most simple example just calls toString on the message and puts the result into a JTextArea. You can download the code from here. For instructions on how HermesJMS bootstraps python code read here.

There are two parts to a renderer. The first is its configuration and the second its implementation. The configuration lets a renderer store properties in the main Hermes XML and we'll cover that in a future example.

Firstly, although we won't be using it in this example, we need to create a configuration class:

class CustomRendererConfig (MessageRenderer.Config):
	def getName(self):
		return self.__name 

	def setName(self, name):
		self.__name = name 	

	def getPropertyDescription(self, propertyName):
		return propertyName

Next for the renderer itself. The most important methods are:

  • canRender is called to see if the message can be renderd.
  • getDisplayName is used for the name of the tab in the GUI.
  • render does the main business of rendering and returns a JComponent. If this method returns null then it is ignored and any exceptions are displayed in a text pane.
class CustomRenderer (MessageRenderer):
	def __init__(self):
		self.__config = CustomRendererConfig() 
		
	def canRender(self, message):
		return 1 

        def isActive(self):
                return 1

	def getConfigPanel(self, dialogProxy):
		return None

	def getDisplayName(self):
		return 'CustomRenderer'

	def setConfig(self, config):
		self.__config = config 

	def getConfig(self):
		return self.__config

	def createConfig(self):
		return CustomRendererConfig() 

	def render(self, message):
		rval = JTextArea() 
		rval.setText(message.toString())
		return rval

The isActive call allows you to disable the renderer via its configuration dialog.

If you already have some Java code to render a JMS message to a JComponent then you can either use the Hermes class loading facility or add it to the main classpath in the startup scripts.

If you think your renderer may be useful to others then drop me a mail or post on the forums.

Finally you need to tell Hermes to use this renderer:

HermesBrowser.getBrowser().getRendererManager().getRenderers().add(0, CustomRenderer())

The collection of renderers is an ArrayList and the order of renderers in the list is the order displayed on screen. In this example we've put the renderer at the head of the list so it will display first:

Adaptavist Theme Builder Powered by Atlassian Confluence