/*
   Copyright 2013 Nationale-Nederlanden

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package nl.nn.adapterframework.senders;

import nl.nn.adapterframework.core.SenderException;
import nl.nn.adapterframework.core.SenderWithParametersBase;
import nl.nn.adapterframework.core.TimeOutException;
import nl.nn.adapterframework.parameters.ParameterResolutionContext;
import nl.nn.adapterframework.pipes.AbstractPipe;
import nl.nn.adapterframework.pipes.PipeAware;
import nl.nn.adapterframework.util.DomBuilderException;
import nl.nn.adapterframework.util.XmlUtils;

import javax.xml.xpath.XPathExpressionException;

import nl.nn.adapterframework.configuration.Configuration;
import nl.nn.adapterframework.configuration.IbisContext;

/**
 * Performs a reload on database config .
 *
 * <p><b>Configuration:</b>
 * <table border="1">
 * <tr><th>attributes</th><th>description</th><th>default</th></tr>
 * <tr><td>{@link #setName(String) name}</td><td>name of the Sender</td><td>&nbsp;</td></tr>
 * </table>
 * </p>
 * <p><b>Exits:</b>
 * <table border="1">
 * <tr><th>state</th><th>condition</th></tr>
 * <tr><td>"success"</td><td>default</td></tr>
 * <tr><td><i>{@link #setForwardName(String) forwardName}</i></td><td>if specified</td></tr>
 * </table>
 * </p>
 * @author  Lars Sinke
 */
public class ReloadSender extends SenderWithParametersBase implements PipeAware {

	private AbstractPipe pipe;

	public String sendMessage(String correlationID, String message,
			ParameterResolutionContext prc) throws SenderException,
			TimeOutException {

		String configName = null;
		String activeVersion = null;

		try {
			configName = XmlUtils.evaluateXPathNodeSetFirstElement(message,
					"row/field[@name='name']");
		} catch (DomBuilderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XPathExpressionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			activeVersion = XmlUtils.evaluateXPathNodeSetFirstElement(message,
					"row/field[@name='version']");
		} catch (DomBuilderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XPathExpressionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Configuration configuration = getPipe().getAdapter().getConfiguration()
				.getIbisManager().getConfiguration(configName);

		String latestVersion = configuration.getVersion();

		if (!latestVersion.equals(activeVersion)) {
			IbisContext ibisContext = getPipe().getAdapter().getConfiguration()
					.getIbisManager().getIbisContext();
			ibisContext.reload(configName);
			return "Reload " + configName + " succeeded";
		} else {
			return "Reload " + configName + " skipped";
		}
	}

	public void setPipe(AbstractPipe pipe) {
		this.pipe = pipe;
	}

	public AbstractPipe getPipe() {
		return pipe;
	}
};
@@ -629,24 +629,140 @@
 k.senders;%0A%0A
+import nl.nn.adapterframework.configuration.Configuration;%0Aimport nl.nn.adapterframework.configuration.IbisContext;%0A
 import nl.nn
@@ -1120,239 +1120,16 @@
 til.
-DomBuilderException;%0Aimport nl.nn.adapterframework.util.XmlUtils;%0A%0Aimport javax.xml.xpath.XPathExpressionException;%0A%0Aimport nl.nn.adapterframework.configuration.Configuration;%0Aimport nl.nn.adapterframework.configuration.IbisContext
+XmlUtils
 ;%0A%0A/
@@ -2115,34 +2115,24 @@
 %0A%09%09%7D catch (
-DomBuilder
 Exception e)
@@ -2141,84 +2141,74 @@
 %0A%09%09%09
-// TODO Auto-g
+throw new S
 en
+d
 er
-ated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D catch (XPathE
+Exception(getLogPrefix()+%22error evaluating Xpath e
 xpre
@@ -2216,88 +2216,30 @@
 sion
-Exception e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace(
+ configName%22, e
 );%0A%09%09%7D
+ 
 %0A%0A%09%09
@@ -2365,18 +2365,8 @@
 ch (
-DomBuilder
 Exce
@@ -2383,84 +2383,74 @@
 %0A%09%09%09
-// TODO Auto-g
+throw new S
 en
+d
 er
-ated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D catch (XPathE
+Exception(getLogPrefix()+%22error evaluating Xpath e
 xpre
@@ -2458,82 +2458,26 @@
 sion
-Exception e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace(
+ activeVersion%22, e
 );%0A%09

Fix catch for evaluate xpath expressions