* @throws org.jboss.soa.esb.ConfigurationException Invalid listener configuration.
*/
public static Element map(Element root, JbrListener listener, XMLBeansModel model) throws ConfigurationException {
Element listenerNode = YADOMUtil.addElement(root, "listener");
JbrBus bus;
JbrProvider provider;
listenerNode.setAttribute("name", listener.getName());
try {
bus = (JbrBus) model.getBus(listener.getBusidref());
} catch (ClassCastException e) {
throw new ConfigurationException("Invalid busid reference [" + listener.getBusidref() + "] on listener [" + listener.getName() + "]. A <jbr-listener> must reference a <jbr-bus>.");
}
try {
provider = (JbrProvider) model.getProvider(bus);
} catch (ClassCastException e) {
throw new ConfigurationException("Invalid bus config [" + listener.getBusidref() + "]. Should be contained within a <jbr-provider> instance. Unexpected exception - this should have caused a validation error!");
}
// Map the standard listener attributes - common across all listener types...
MapperUtil.mapDefaultAttributes(listener, listenerNode, model);
// Map the <property> elements targeted at the listener - from the listener itself.
MapperUtil.mapProperties(provider.getPropertyList(), listenerNode);
MapperUtil.mapProperties(bus.getPropertyList(), listenerNode);
MapperUtil.mapProperties(listener.getPropertyList(), listenerNode);
if(listener.getIsGateway()) {
String host = provider.getHost();
listenerNode.setAttribute("gatewayClass", JBossRemotingGatewayListener.class.getName());
listenerNode.setAttribute(ListenerTagNames.IS_GATEWAY_TAG, Boolean.toString(listener.getIsGateway()));
if(host != null) {
listenerNode.setAttribute(JBossRemotingGatewayListener.JBR_SERVER_HOST, host);
}
listenerNode.setAttribute(JBossRemotingGatewayListener.JBR_SERVER_PROTOCOL, provider.getProtocol().toString());
listenerNode.setAttribute(JBossRemotingGatewayListener.JBR_SERVER_PORT, Integer.toString(bus.getPort()));
} else {
throw new ConfigurationException("Invalid <jbr-listener> config [" + listener.getName() + "]. <jbr-listener> is currently only supported as a gateway listener.");
}