<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Guy Mahieu's Blog</title>
	<atom:link href="http://blog.guymahieu.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.guymahieu.com</link>
	<description>Agile OO Software Development and More</description>
	<pubDate>Sun, 19 Oct 2008 14:22:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>IvyIDEA: Ivy support for IntelliJ IDEA</title>
		<link>http://blog.guymahieu.com/2008/10/18/ivy-support-for-intellij-idea/</link>
		<comments>http://blog.guymahieu.com/2008/10/18/ivy-support-for-intellij-idea/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 14:55:15 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[ivyidea]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[idea]]></category>

		<category><![CDATA[intellij]]></category>

		<category><![CDATA[ivy]]></category>

		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/?p=70</guid>
		<description><![CDATA[At my current job everyone is using eclipse and ivy is the standard dependency manager. I&#8217;ve used eclipse as well for the last months, but it could never make me forget IntelliJ IDEA. Too bad IntelliJ still lacks ivy support though&#8230;
There are a few plugins around that add (some) ivy support to IntelliJ IDEA but [...]]]></description>
			<content:encoded><![CDATA[<p>At my current job everyone is using <a href="http://www.eclipse.org/">eclipse</a> and <a href="http://ant.apache.org/ivy/">ivy</a> is the standard dependency manager. I&#8217;ve used eclipse as well for the last months, but it could never make me forget<a href="http://www.jetbrains.com/idea/"> IntelliJ IDEA</a>. Too bad IntelliJ still lacks ivy support though&#8230;</p>
<p>There are a few plugins around that add (some) ivy support to IntelliJ IDEA but I wasn&#8217;t able to get them to work properly; they seem to be written for a specific situation or are a pain to configure.</p>
<p>All of this got me to the point where I started working on my own plugin: <a href="http://www.ivyidea.org">IvyIDEA</a>. At first I started out with a quick and dirty way of adding dependencies from a certain folder into a module library in IntelliJ. After a few days and nights of development, I now have it integrated with the ivy resolve functionality. It detects source and document types and adds them as such. As a bonus (and because I was curious how it worked) I also added an IvyIDEA facet in intellij, meaning that ivy.xml files are autodetected and configured to be recognized by the plugin.</p>
<p>It is still very rough around the edges (the exception handling is non-existing and there currently is no output console to see what&#8217;s going on during the resolve process) but I use it daily in my job and I hope to have a good enough version ready soon to add to the IntelliJ plugin repository.</p>
<p>If you can&#8217;t wait until then, you can always download the source code and compile it on your own from <a href="http://www.ivyidea.org">www.ivyidea.org</a>. If you have feature requests, bug reports or comments, please let me know!</p>
<p><strong>Update 2008-10-19</strong>: I just saw that JetBrains is organizing an <a href="http://plugins.intellij.net/contest/">IntelliJ plugin contest</a>, and I decided to submit IvyIDEA as an entry. They suggested to publish a version as early as possible so I decided to already publish a first alpha version to the plugin repository. This means that you can now install the first rough-around-the-edges alpha version using the plugin manager in IntelliJ if you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2008/10/18/ivy-support-for-intellij-idea/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting the depth of an MQSeries queue from Java</title>
		<link>http://blog.guymahieu.com/2008/06/11/getting-the-depth-of-an-mqseries-queue-from-java/</link>
		<comments>http://blog.guymahieu.com/2008/06/11/getting-the-depth-of-an-mqseries-queue-from-java/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 09:39:37 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[mqseries]]></category>

		<category><![CDATA[tips&#038;tricks]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/2008/06/11/getting-the-depth-of-an-mqseries-queue-from-java/</guid>
		<description><![CDATA[The JMS spec does not provide a way to easily obtain the number of messages on a certain queue. You could create a browser and browse through the entire queue and keep count, but this is very slow.
The java client for MQSeries (or WebsphereMQ as it is called nowadays) does provide this functionality, so if [...]]]></description>
			<content:encoded><![CDATA[<p>The JMS spec does not provide a way to easily obtain the number of messages on a certain queue. You could create a browser and browse through the entire queue and keep count, but this is very slow.</p>
<p>The java client for MQSeries (or WebsphereMQ as it is called nowadays) does provide this functionality, so if you don&#8217;t mind using IBM specific classes, you could do it like this:</p>
<p><div id="mycode"><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">int</span> getDepth<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> queueName<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MQException <span style="color: #66cc66;">&#123;</span>
  <span style="color: #808080; font-style: italic;">// Build quemanager (this should be done in another method)</span>
  <span style="color: #808080; font-style: italic;">// and not every time in a real life application</span>
  MQEnvironment.<span style="color: #006600;">channel</span> = <span style="color: #ff0000;">&quot;CHANNELNAME&quot;</span>;
  MQEnvironment.<span style="color: #006600;">port</span> = <span style="color: #cc66cc;">1414</span>;
  MQEnvironment.<span style="color: #006600;">hostname</span> = <span style="color: #ff0000;">&quot;qmgrhost.yourdomain.com&quot;</span>;
  MQEnvironment.<span style="color: #006600;">properties</span>.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>MQC.<span style="color: #006600;">TRANSPORT_PROPERTY</span>, 
    MQC.<span style="color: #006600;">TRANSPORT_MQSERIES</span><span style="color: #66cc66;">&#41;</span>;
  MQQueueManager qmgr = <span style="color: #000000; font-weight: bold;">new</span> MQQueueManager<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;YourQueueManagerName&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #808080; font-style: italic;">// access the queue to query its depth</span>
  com.<span style="color: #006600;">ibm</span>.<span style="color: #006600;">mq</span>.<span style="color: #006600;">MQQueue</span> queue = qmgr.<span style="color: #006600;">accessQueue</span><span style="color: #66cc66;">&#40;</span>queueName, 
    MQC.<span style="color: #006600;">MQOO_INQUIRE</span> | MQC.<span style="color: #006600;">MQOO_INPUT_AS_Q_DEF</span>, 
    <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">return</span> queue.<span style="color: #006600;">getCurrentDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></p>
<p>The com.ibm.mq.MQQueue class exposes some other interesting methods to get more information about a queue, like the maximum depth and the maximum message length.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2008/06/11/getting-the-depth-of-an-mqseries-queue-from-java/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting the svn HEAD revision number from a windows batch file</title>
		<link>http://blog.guymahieu.com/2008/06/09/getting-the-svn-head-revision-number-from-a-windows-batch-file/</link>
		<comments>http://blog.guymahieu.com/2008/06/09/getting-the-svn-head-revision-number-from-a-windows-batch-file/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 05:10:49 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[batch]]></category>

		<category><![CDATA[svn]]></category>

		<category><![CDATA[windows]]></category>

		<category><![CDATA[command]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/2008/06/09/getting-the-svn-head-revision-number-from-a-windows-batch-file/</guid>
		<description><![CDATA[The svn command has an info parameter with which you can obtain some info about the current directory, like this:
C:\Projects\myproject\branches\DEV_V0001.00>svn info --revision HEAD
Path: DEV_V0001.00
URL: http://svn.mycompany:10080/svn/myproject/branches/DEV_V0001.00
Repository Root: http://svn.mycompany:10080/svn/myproject
Repository UUID: 495b61df-840d-0410-9b36-f3cf8ec0f97e
Revision: 8251
Node Kind: directory
Last Changed Author: mahieuguy
Last Changed Rev: 8211
Last Changed Date: 2008-06-05 13:05:22 +0200 (do, 05 jun 2008)

I could not find a command that would just [...]]]></description>
			<content:encoded><![CDATA[<p>The svn command has an info parameter with which you can obtain some info about the current directory, like this:</p>
<pre>C:\Projects\myproject\branches\DEV_V0001.00>svn info --revision HEAD
Path: DEV_V0001.00
URL: http://svn.mycompany:10080/svn/myproject/branches/DEV_V0001.00
Repository Root: http://svn.mycompany:10080/svn/myproject
Repository UUID: 495b61df-840d-0410-9b36-f3cf8ec0f97e
Revision: 8251
Node Kind: directory
Last Changed Author: mahieuguy
Last Changed Rev: 8211
Last Changed Date: 2008-06-05 13:05:22 +0200 (do, 05 jun 2008)
</pre>
<p>I could not find a command that would just return the revision number, which we needed in our build script. On linux systems it would be trivial to extract just the rev number from the output of the &#8216;info&#8217; command, so I hoped it would also be possible in dos/windows without installing extra tools. It turned out to be possible, but much less elegant than I suspected:</p>
<pre>
@echo off
FOR /F "tokens=2 skip=4" %%G IN ('svn info --revision HEAD') DO ^
IF NOT DEFINED REVISION SET REVISION=%%G
echo %REVISION%
</pre>
<p><em>Note that the ^ character is just there to split the command into two lines, this works for XP batch scripts, but I&#8217;m not sure about other versions of cmd.exe</em></p>
<p>The HEAD revision number is put in the %REVISION% parameter. Make sure you don&#8217;t already have a REVISION parameter defined before executing the command in the batch file though, because it will only be set if it is not already defined. This was needed to be able to get the FOR command to ignore all lines after the &#8216;Revision: 8251&#8242; line from the &#8217;svn info&#8217; result.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2008/06/09/getting-the-svn-head-revision-number-from-a-windows-batch-file/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Custom MSBuild task for grep-like searches</title>
		<link>http://blog.guymahieu.com/2007/08/17/custom-msbuild-task-for-grep-like-searches/</link>
		<comments>http://blog.guymahieu.com/2007/08/17/custom-msbuild-task-for-grep-like-searches/#comments</comments>
		<pubDate>Fri, 17 Aug 2007 12:15:32 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[.net]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[msbuild]]></category>

		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/2007/08/17/custom-msbuild-task-for-grep-like-searches/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2007/08/17/custom-msbuild-task-for-grep-like-searches/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Intercepting calls to a Connection in a spring-managed DataSource</title>
		<link>http://blog.guymahieu.com/2007/05/03/intercepting-calls-to-a-connection-in-a-spring-managed-datasource/</link>
		<comments>http://blog.guymahieu.com/2007/05/03/intercepting-calls-to-a-connection-in-a-spring-managed-datasource/#comments</comments>
		<pubDate>Thu, 03 May 2007 09:44:39 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[aop]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/2007/05/03/intercepting-calls-to-a-connection-in-a-spring-managed-datasource/</guid>
		<description><![CDATA[The spring framework provides an easy way for intercepting calls to methods of managed beans. In the project I am currently working at, we wanted to log access to all methods of the Connections returned by a specific datasource. This datasource is defined as a spring bean, but the connections it provides obviously aren&#8217;t. 
In [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.springframework.org/">spring framework</a> provides an easy way for intercepting calls to methods of managed beans. In the project I am currently working at, we wanted to log access to all methods of the Connections returned by a specific datasource. This datasource is defined as a spring bean, but the connections it provides obviously aren&#8217;t. </p>
<p>In order to get this done, I decided intercept all calls to the getConnection() method of that specific DataSource an in stead of returning the Connection, I return a <a href="http://java.sun.com/j2se/1.4.2/docs/guide/reflection/proxy.html">dynamic proxy</a> to that connection which will log some method information prior to invoking that method.</p>
<p>Here is the source code and xml config I used to do this&#8230;<br />
<span id="more-58"></span></p>
<p>First we need to implement an interceptor for calls to the DataSource.getConnection() method. This class implements the org.aopalliance.intercept.MethodInterceptor interface:<br />
<div id="mycode"><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConnectionCallInterceptor <span style="color: #000000; font-weight: bold;">implements</span> MethodInterceptor <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> invoke<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> MethodInvocation methodInvocation<span style="color: #66cc66;">&#41;</span> 
            <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?q=allinurl%3AThrowable+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Throwable</span></a> <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> methodName = methodInvocation.<span style="color: #006600;">getMethod</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;getConnection&quot;</span>.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>methodName<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #808080; font-style: italic;">// return proxied connection</span>
            <a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a> connection = <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a><span style="color: #66cc66;">&#41;</span> methodInvocation.<span style="color: #006600;">proceed</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #000000; font-weight: bold;">return</span> ConnectionMethodLoggerProxy.<span style="color: #006600;">newInstance</span><span style="color: #66cc66;">&#40;</span>connection<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #808080; font-style: italic;">// simply return methodcall result </span>
            <span style="color: #000000; font-weight: bold;">return</span> methodInvocation.<span style="color: #006600;">proceed</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></p>
<p>To do the actual logging, all method calls to the java.sql.Connection need to be intercepted, here is the class that creates a <a href="http://java.sun.com/j2se/1.4.2/docs/guide/reflection/proxy.html">dynamic proxy</a> and does some logging in the InvocationHandler implementation:<br />
<div id="mycode"><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConnectionMethodLoggerProxy <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?q=allinurl%3AInvocationHandler+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">InvocationHandler</span></a> <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a> connection;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a> newInstance<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a> connection<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a><span style="color: #66cc66;">&#41;</span> <a href="http://www.google.com/search?q=allinurl%3AProxy+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Proxy</span></a>.<span style="color: #006600;">newProxyInstance</span><span style="color: #66cc66;">&#40;</span>
            connection.<span style="color: #006600;">getClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getClassLoader</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
            <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#123;</span> <a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a>.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #66cc66;">&#125;</span>,
            <span style="color: #000000; font-weight: bold;">new</span> ConnectionMethodLoggerProxy<span style="color: #66cc66;">&#40;</span>connection<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> ConnectionMethodLoggerProxy<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a> connection<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">connection</span> = connection;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> invoke<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> proxy, <a href="http://www.google.com/search?q=allinurl%3AMethod+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Method</span></a> method, <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> 
            <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?q=allinurl%3AThrowable+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Throwable</span></a> <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> methodName = method.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> targetName = connection.<span style="color: #006600;">getClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> types = method.<span style="color: #006600;">getParameterTypes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> returnTypeName = method.<span style="color: #006600;">getReturnType</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;=============================&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot; Connection method call detected:&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;  - Target     : &quot;</span> + targetName<span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;  - Method     : &quot;</span> + methodName<span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;  - Arguments  : &quot;</span> + ArrayUtils.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;  - Arg Types  : &quot;</span> + ArrayUtils.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span>types<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;  - Return type: &quot;</span> + returnTypeName<span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;=============================&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> method.<span style="color: #006600;">invoke</span><span style="color: #66cc66;">&#40;</span>connection, args<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></p>
<p>Now we have all the code we need, all that is left to do is configure spring to actually use our ConnectionCallInterceptor whenever a method call is made to our datasource (which in this case is a bean named &#8216;myDataSource&#8217;):<br />
<div id="mycode"><pre class="xml"><span style="color: #009900;"><span style="color: blue;">&lt;bean</span> <span style="color: maroon;">class</span>=
    <span style="color: #ff0000;">&quot;org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator&quot;</span><span style="color: blue;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;property</span> <span style="color: maroon;">name</span>=<span style="color: #ff0000;">&quot;beanNames&quot;</span><span style="color: blue;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: blue;">&lt;list<span style="color: blue;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: blue;">&lt;value<span style="color: blue;">&gt;</span></span></span>myDataSource<span style="color: #009900;"><span style="color: blue;">&lt;/value<span style="color: blue;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: blue;">&lt;/list<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;/property<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;property</span> <span style="color: maroon;">name</span>=<span style="color: #ff0000;">&quot;interceptorNames&quot;</span><span style="color: blue;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: blue;">&lt;list<span style="color: blue;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: blue;">&lt;value<span style="color: blue;">&gt;</span></span></span>dataAccessInterceptor<span style="color: #009900;"><span style="color: blue;">&lt;/value<span style="color: blue;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: blue;">&lt;/list<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;/property<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;property</span> <span style="color: maroon;">name</span>=<span style="color: #ff0000;">&quot;proxyTargetClass&quot;</span> <span style="color: maroon;">value</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: blue;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: blue;">&lt;/bean<span style="color: blue;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: blue;">&lt;bean</span> <span style="color: maroon;">id</span>=<span style="color: #ff0000;">&quot;dataAccessInterceptor&quot;</span> <span style="color: maroon;">class</span>=<span style="color: #ff0000;">&quot;ConnectionCallInterceptor&quot;</span><span style="color: blue;">/&gt;</span></span></pre></div></p>
<p>Although this is probably not something you&#8217;d want to do in a production environment, it helped us a great deal in our specific case. I don&#8217;t have a lot of experience with the spring framework, so there may be better ways to do this (and if you know one, please share it :)), but this looked the most straightforward to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2007/05/03/intercepting-calls-to-a-connection-in-a-spring-managed-datasource/feed/</wfw:commentRss>
		</item>
		<item>
		<title>VlaaiVis website gone public</title>
		<link>http://blog.guymahieu.com/2007/03/29/vlaaivis-website-gone-public/</link>
		<comments>http://blog.guymahieu.com/2007/03/29/vlaaivis-website-gone-public/#comments</comments>
		<pubDate>Thu, 29 Mar 2007 19:13:08 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/2007/03/29/vlaaivis-website-gone-public/</guid>
		<description><![CDATA[ About a year and a half ago, we started working on a project to implement a new kind of visualisation method for my current employer, Johnson &#038; Johnson.The goal was to visualize very wide sets of data in a very condensed way to simplify the analysis process. Trevor Howe came up with the concept [...]]]></description>
			<content:encoded><![CDATA[<p> <img align="right" src='http://blog.guymahieu.com/wp-content/uploads/2007/03/vlaaivis1.png' alt='VlaaiVis' />About a year and a half ago, we started working on a project to implement a new kind of visualisation method for my current employer, <a href="http://www.jnj.com/">Johnson &#038; Johnson</a>.The goal was to visualize very wide sets of data in a very condensed way to simplify the analysis process. Trevor Howe came up with the concept of a pie barchart diagram he named <a href="http://www.vlaaivis.com/">VlaaiVis</a> (see image on the right). The basic idea is that you can define a &#8216;preferred profile&#8217;, the boundaries within which the data values are satisfactory to you, and the data will be visualized relative to this profile. Every row in the dataset is a pie, and the closer a bar is to the outer rim, the better the value for that column fits your profile.</p>
<p>The other members of the development team for this project were <a href="http://www.linkedin.com/pub/2/b65/aba">Max Hillaert</a>, <a href="http://www.linkedin.com/in/alainhufkens">Alain Hufkens</a>, Raf Franco and <a href="http://www.pointerx.net/">Gabriel Lozano-Moràn</a>. Pieter Vugts and <a href="http://www.delarou.net/weblog/">Christophe De Baene</a> created the initial proof-of-concept application. </p>
<p>The department recently decided to make the application publicly available, and the website has gone public now.</p>
<p>From the <a href="http://www.vlaaivis.com/">VlaaiVis website</a>:</p>
<blockquote><p>VlaaiVis is a visualisation tool originally developed for multifactorial structure activity relationship (SAR) data. Each circle represents a single compound and each slice of the &#8216;pie&#8217; represents a normalised response to a particular assay or property. An unlimited number of compounds may be visualised simultaneously. The tool seeks to provide a simple and rapid visualisation of single or multiple compounds during any phase of the drug discovery process. In a broader sense, it fits any kind of data for which a target preferred profile could be determined.</p></blockquote>
<p>If you&#8217;re interested, you can <a href="http://www.vlaaivis.com/download.htm">download a free version</a>, more information on how VlaaiVis works can be found in the <a href="http://www.vlaaivis.com/help/">online help pages</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2007/03/29/vlaaivis-website-gone-public/feed/</wfw:commentRss>
		</item>
		<item>
		<title>TomTom GO 910 infected with a virus out of the box?!</title>
		<link>http://blog.guymahieu.com/2007/03/19/tomtom-go-910-infected-with-a-virus-out-of-the-box/</link>
		<comments>http://blog.guymahieu.com/2007/03/19/tomtom-go-910-infected-with-a-virus-out-of-the-box/#comments</comments>
		<pubDate>Mon, 19 Mar 2007 09:23:25 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<category><![CDATA[virus]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/2007/03/19/tomtom-go-910-infected-with-a-virus-out-of-the-box/</guid>
		<description><![CDATA[This weekend I bought a TomTom navigation system, I chose the GO 910 because it is easy to update, works well and has a lot of nice extra features (bluetooth handsfree, mp3 playback, &#8230;) When I came home and hooked it up to my pc using the USB docking station, avast gave with a warning [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I bought a TomTom navigation system, I chose the GO 910 because it is easy to update, works well and has a lot of nice extra features (bluetooth handsfree, mp3 playback, &#8230;) When I came home and hooked it up to my pc using the USB docking station, <a href="http://www.avast.com/">avast</a> gave with a warning that it detected a virus. </p>
<p>Naively, I assumed that a brand new device could never be infected with a virus, and ignored the warning thinking that avast was over sensitive about some TomTom component. This was not the smartest thing, because soon I realised that there was indeed a virus on the TomTom harddrive, and I couldn&#8217;t open any of my drives from explorer anymore.</p>
<p>I did some surfing and noticed that a lot of people had this problem, there even was an <a href="http://www.tomtom.com/news/category.php?ID=2&#038;NID=349&#038;Language=1">official statement from TomTom</a>, saying they know the problem exists, that it wasn&#8217;t all that bad, and that all antivirus software would spot the threat. They also mentioned that: &#8220;the virus does not impact the navigation performance of the TomTom GO 910&#8243;; good to know when no drives on my PC will open through Windows Explorer&#8230;</p>
<p>A good thing I probably know my way around computers better than the average TomTom customer, it still took me quite some time to realize exactly what happened and fix my system. </p>
<p>I must have missed something, but how can a company get away with keeping a known virus-infected device in stores?  Why can&#8217;t the infected devices be tracked and cleaned by TomTom before a user has to find out the hard way?</p>
<p>Related links:</p>
<ul>
<li><a href="http://www.daniweb.com/blogs/entry1276.html">daniweb</a></li>
<li><a href="http://news.com.com/TomTom+shipped+viruses+on+its+navigation+devices/2100-1002_3-6154198.html">news.com</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2007/03/19/tomtom-go-910-infected-with-a-virus-out-of-the-box/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Computing MD5 hashes in C#</title>
		<link>http://blog.guymahieu.com/2007/03/09/computing-md5-hashes-in-c/</link>
		<comments>http://blog.guymahieu.com/2007/03/09/computing-md5-hashes-in-c/#comments</comments>
		<pubDate>Fri, 09 Mar 2007 07:44:22 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/2007/03/09/computing-md5-hashes-in-c/</guid>
		<description><![CDATA[I&#8217;ve had to create md5 hashes in php before, which can be done by simply using the md5() function. Because I always try to avoid reinventing the wheel, I googled for an example on how to compute these kinds of hashes from c#. It directed me to the Microsoft knowledgebase, article KB307020, but that didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had to create md5 hashes in php before, which can be done by simply using the <a href="http://us2.php.net/manual/en/function.md5.php">md5()</a> function. Because I always try to avoid reinventing the wheel, I googled for an example on how to compute these kinds of hashes from c#. It directed me to the Microsoft knowledgebase, article <a href="http://support.microsoft.com/kb/307020">KB307020</a>, but that didn&#8217;t work as expected. </p>
<p>That particular article shows how you can compute the MD5 hash of a string and then display the resulting byte array as a new string containing the hexadeximal representation of each byte. Since I needed to compare the hash to a string that was generated by a script on a linux machine, I was especially interested in the ByteArrayToString method from the knowledge base article. I have pasted it below, see if you can <strong>spot the error</strong>:</p>
<p><div id="mycode"><pre class="csharp"><span style="color:blue;">static</span> <span style="color:blue;">string</span> ByteArrayToString<span style="color:black;">&#40;</span><span style="color:blue;">byte</span><span style="color:black;">&#91;</span><span style="color:black;">&#93;</span> arrInput<span style="color:black;">&#41;</span>
<span style="color:black;">&#123;</span>
  <span style="color:blue;">int</span> i;
  StringBuilder sOutput = <span style="color:blue;">new</span> StringBuilder<span style="color:black;">&#40;</span>arrInput.<span style="color:black;">Length</span><span style="color:black;">&#41;</span>;
  <span style="color:blue;">for</span> <span style="color:black;">&#40;</span>i=<span style="color:black;">0</span>;i &lt; arrInput.<span style="color:black;">Length</span> <span style="color:black;">-1</span>; i++<span style="color:black;">&#41;</span> 
    <span style="color:black;">&#123;</span>
      sOutput.<span style="color:black;">Append</span><span style="color:black;">&#40;</span>arrInput<span style="color:black;">&#91;</span>i<span style="color:black;">&#93;</span>.<span style="color:black;">ToString</span><span style="color:black;">&#40;</span><span style="color:maroon;">&quot;X2&quot;</span><span style="color:black;">&#41;</span><span style="color:black;">&#41;</span>;
    <span style="color:black;">&#125;</span>
  <span style="color:blue;">return</span> sOutput.<span style="color:black;">ToString</span><span style="color:black;">&#40;</span><span style="color:black;">&#41;</span>;
<span style="color:black;">&#125;</span></pre></div></p>
<p><span id="more-53"></span><br />
Yes, indeed&#8230; the last byte does not get appended to the resulting string, since the end-loop condition is set to i <strong>&lt;</strong> arrInput.Length <strong>-1</strong>. This leaves you with an incorrect string representation of your hash. On top of this, there are two other minor things wrong with this: </p>
<ol>
<li>the StringBuilder should be initialized with twice the length of the array, since each byte will take up two chars in the string</li>
<li>the resulted string is in uppercase while usually hexadecimal representations of MD5 hashes are shown in lower case</li>
</ol>
<p>The following code does exactly what I wanted: compute an MD5 hash from a string and return the lowercase hexadecimal string representation for it, just like the php md5() function does.</p>
<p><div id="mycode"><pre class="csharp"><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> MD5<span style="color:black;">&#40;</span><span style="color:blue;">string</span> str<span style="color:black;">&#41;</span>
<span style="color:black;">&#123;</span>
   <span style="color:blue;">byte</span><span style="color:black;">&#91;</span><span style="color:black;">&#93;</span> strBytes = ASCIIEncoding.<span style="color:black;">ASCII</span>.<span style="color:black;">GetBytes</span><span style="color:black;">&#40;</span>str<span style="color:black;">&#41;</span>;
   <span style="color:blue;">byte</span><span style="color:black;">&#91;</span><span style="color:black;">&#93;</span> resultBytes = MD5CryptoServiceProvider
       .<span style="color:black;">Create</span><span style="color:black;">&#40;</span><span style="color:black;">&#41;</span>.<span style="color:black;">ComputeHash</span><span style="color:black;">&#40;</span>strBytes<span style="color:black;">&#41;</span>;
   <span style="color:blue;">return</span> ByteArrayToString<span style="color:black;">&#40;</span>resultBytes<span style="color:black;">&#41;</span>;
<span style="color:black;">&#125;</span>
&nbsp;
<span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> ByteArrayToString<span style="color:black;">&#40;</span><span style="color:blue;">byte</span><span style="color:black;">&#91;</span><span style="color:black;">&#93;</span> arrInput<span style="color:black;">&#41;</span>
<span style="color:black;">&#123;</span>
   StringBuilder sOutput = <span style="color:blue;">new</span> StringBuilder<span style="color:black;">&#40;</span>arrInput.<span style="color:black;">Length</span> * <span style="color:black;">2</span><span style="color:black;">&#41;</span>;
   <span style="color:blue;">for</span> <span style="color:black;">&#40;</span><span style="color:blue;">int</span> i = <span style="color:black;">0</span>; i &lt; arrInput.<span style="color:black;">Length</span>; i++<span style="color:black;">&#41;</span>
   <span style="color:black;">&#123;</span>
      sOutput.<span style="color:black;">Append</span><span style="color:black;">&#40;</span>arrInput<span style="color:black;">&#91;</span>i<span style="color:black;">&#93;</span>.<span style="color:black;">ToString</span><span style="color:black;">&#40;</span><span style="color:maroon;">&quot;x2&quot;</span><span style="color:black;">&#41;</span><span style="color:black;">&#41;</span>;
   <span style="color:black;">&#125;</span>
   <span style="color:blue;">return</span> sOutput.<span style="color:black;">ToString</span><span style="color:black;">&#40;</span><span style="color:black;">&#41;</span>;
<span style="color:black;">&#125;</span></pre></div></p>
<p><strong>Update:</strong> I hadn&#8217;t noticed this before, but the ByteArrayToString method is in the <a href="http://support.microsoft.com/kb/307020">KB307020</a> article twice, the first mention does not contain the Length -1 bug, the second time, in the full code, it is there.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2007/03/09/computing-md5-hashes-in-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Custom paste behaviour for Windows Forms controls</title>
		<link>http://blog.guymahieu.com/2007/03/03/custom-paste-behaviour-for-winforms-controls/</link>
		<comments>http://blog.guymahieu.com/2007/03/03/custom-paste-behaviour-for-winforms-controls/#comments</comments>
		<pubDate>Sat, 03 Mar 2007 19:35:59 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[.net]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[tips&#038;tricks]]></category>

		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/2007/03/03/custom-paste-behaviour-for-winforms-controls/</guid>
		<description><![CDATA[Some Windows Forms controls come with copy/paste functionality out of the box. This is great when you just want the standard copy/paste behaviour, but what if you want to do some transformation of the data on the clipboard prior to displaying it in the Windows Forms control? 
In my case I needed to convert a [...]]]></description>
			<content:encoded><![CDATA[<p>Some Windows Forms controls come with copy/paste functionality out of the box. This is great when you just want the standard copy/paste behaviour, but what if you want to do some transformation of the data on the clipboard prior to displaying it in the Windows Forms control? </p>
<p>In my case I needed to convert a selection copied from Excel to a comma-delimited list of values when they were pasted in a TextBox. Since there is no OnPaste() method on the TextBox to override, I had to dig deeper to get the job done. </p>
<p>Usually something like this can be done by creating a subclass of the component and overriding the WndProc method to capture the right message. So I created a class called MyTextBox which extends TextBox and I trapped the windows Paste message, like this:</p>
<p><div id="mycode"><pre class="csharp"><span style="color:blue;">private</span> <span style="color:blue;">const</span> <span style="color:blue;">int</span> WM_PASTE = 0x302;
&nbsp;
<span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> WndProc<span style="color:black;">&#40;</span><span style="color:blue;">ref</span> Message m<span style="color:black;">&#41;</span>
<span style="color:black;">&#123;</span>
    <span style="color:blue;">if</span> <span style="color:black;">&#40;</span>m.<span style="color:black;">Msg</span> == WM_PASTE<span style="color:black;">&#41;</span>
    <span style="color:black;">&#123;</span>
        <span style="color:green;">// trigger our custom paste logic</span>
        OnPaste<span style="color:black;">&#40;</span><span style="color:black;">&#41;</span>;
    <span style="color:black;">&#125;</span>
    <span style="color:blue;">else</span>
    <span style="color:black;">&#123;</span>
        <span style="color:blue;">base</span>.<span style="color:black;">WndProc</span><span style="color:black;">&#40;</span><span style="color:blue;">ref</span> m<span style="color:black;">&#41;</span>;
    <span style="color:black;">&#125;</span>
<span style="color:black;">&#125;</span>
&nbsp;
<span style="color:blue;">protected</span> <span style="color:blue;">virtual</span> <span style="color:blue;">void</span> OnPaste<span style="color:black;">&#40;</span><span style="color:black;">&#41;</span> 
<span style="color:black;">&#123;</span>
    <span style="color:green;">// put custom logic here    </span>
<span style="color:black;">&#125;</span></pre></div></p>
<p>There you go, now my own protected virtual OnPaste() method is called when the control receives a PASTE message, and the message is not passed to the base class to prevent the default paste behavior from being executed. </p>
<p>All that is left to do now is get the text data from the clipboard, do my own transformations and change the Text property of the TextBox accordingly. </p>
<p><span id="more-52"></span>Here is the full code for the MyTextBox class:</p>
<p><div id="mycode"><pre class="csharp"><span style="color:blue;">public</span> <span style="color:blue;">class</span> MyTextBox : TextBox
<span style="color:black;">&#123;</span>
    <span style="color:blue;">private</span> <span style="color:blue;">const</span> <span style="color:blue;">int</span> WM_PASTE = 0x302;
&nbsp;
    <span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> WndProc<span style="color:black;">&#40;</span><span style="color:blue;">ref</span> Message m<span style="color:black;">&#41;</span>
    <span style="color:black;">&#123;</span>
        <span style="color:blue;">if</span> <span style="color:black;">&#40;</span>m.<span style="color:black;">Msg</span> == WM_PASTE<span style="color:black;">&#41;</span>
        <span style="color:black;">&#123;</span>
            OnPaste<span style="color:black;">&#40;</span><span style="color:black;">&#41;</span>;
        <span style="color:black;">&#125;</span>
        <span style="color:blue;">else</span>
        <span style="color:black;">&#123;</span>
            <span style="color:blue;">base</span>.<span style="color:black;">WndProc</span><span style="color:black;">&#40;</span><span style="color:blue;">ref</span> m<span style="color:black;">&#41;</span>;
        <span style="color:black;">&#125;</span>
    <span style="color:black;">&#125;</span>
&nbsp;
    <span style="color:blue;">protected</span> <span style="color:blue;">virtual</span> <span style="color:blue;">void</span> OnPaste<span style="color:black;">&#40;</span><span style="color:black;">&#41;</span>
    <span style="color:black;">&#123;</span>
        <span style="color:blue;">string</span> data = Clipboard.<span style="color:black;">GetData</span><span style="color:black;">&#40;</span>DataFormats.<span style="color:black;">Text</span><span style="color:black;">&#41;</span> <span style="color:blue;">as</span> <span style="color:blue;">string</span>;
        <span style="color:blue;">if</span> <span style="color:black;">&#40;</span>data != <span style="color:blue;">null</span><span style="color:black;">&#41;</span>
        <span style="color:black;">&#123;</span>
            <span style="color:blue;">string</span> convertedText = DelimitByCommas<span style="color:black;">&#40;</span>data<span style="color:black;">&#41;</span>;
            InsertText<span style="color:black;">&#40;</span>convertedText<span style="color:black;">&#41;</span>;
        <span style="color:black;">&#125;</span>
    <span style="color:black;">&#125;</span>
&nbsp;
    <span style="color:blue;">protected</span> <span style="color:blue;">virtual</span> <span style="color:blue;">string</span> DelimitByCommas<span style="color:black;">&#40;</span><span style="color:blue;">string</span> text<span style="color:black;">&#41;</span>
    <span style="color:black;">&#123;</span>
        text = text.<span style="color:black;">Replace</span><span style="color:black;">&#40;</span><span style="color:maroon;">&quot;<span style="color:maroon;">\r</span><span style="color:maroon;">\n</span>&quot;</span>, <span style="color:maroon;">&quot;,&quot;</span><span style="color:black;">&#41;</span>;
        text = text.<span style="color:black;">Replace</span><span style="color:black;">&#40;</span><span style="color:maroon;">&quot;<span style="color:maroon;">\t</span>&quot;</span>, <span style="color:maroon;">&quot;,&quot;</span><span style="color:black;">&#41;</span>;
        <span style="color:blue;">return</span> text.<span style="color:black;">Trim</span><span style="color:black;">&#40;</span><span style="color:maroon;">','</span>, <span style="color:maroon;">' '</span><span style="color:black;">&#41;</span>;            
    <span style="color:black;">&#125;</span>
&nbsp;
    <span style="color:blue;">protected</span> <span style="color:blue;">virtual</span> <span style="color:blue;">void</span> InsertText<span style="color:black;">&#40;</span><span style="color:blue;">string</span> textToInsert<span style="color:black;">&#41;</span>
    <span style="color:black;">&#123;</span>
        <span style="color:blue;">int</span> selectionEnd = SelectionStart + SelectionLength;
        <span style="color:blue;">int</span> newCaretPos = SelectionStart + textToInsert.<span style="color:black;">Length</span>;
&nbsp;
        <span style="color:blue;">string</span> prefix = Text.<span style="color:black;">Substring</span><span style="color:black;">&#40;</span><span style="color:black;">0</span>, SelectionStart<span style="color:black;">&#41;</span>;
        <span style="color:blue;">string</span> suffix = Text.<span style="color:black;">Substring</span><span style="color:black;">&#40;</span>selectionEnd, 
                                Text.<span style="color:black;">Length</span> - selectionEnd<span style="color:black;">&#41;</span>;            
        Text = prefix + textToInsert + suffix;
&nbsp;
        <span style="color:green;">// position the caret at the end of the pasted text</span>
        SelectionStart = newCaretPos;
    <span style="color:black;">&#125;</span>
<span style="color:black;">&#125;</span></pre></div></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2007/03/03/custom-paste-behaviour-for-winforms-controls/feed/</wfw:commentRss>
		</item>
		<item>
		<title>TODO reports in CruiseControl.NET</title>
		<link>http://blog.guymahieu.com/2007/01/22/todo-reports-in-cruisecontrolnet/</link>
		<comments>http://blog.guymahieu.com/2007/01/22/todo-reports-in-cruisecontrolnet/#comments</comments>
		<pubDate>Mon, 22 Jan 2007 20:13:35 +0000</pubDate>
		<dc:creator>Guy Mahieu</dc:creator>
		
		<category><![CDATA[.net]]></category>

		<category><![CDATA[continuous integration]]></category>

		<category><![CDATA[cruisecontrol]]></category>

		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://blog.guymahieu.com/?p=28</guid>
		<description><![CDATA[I guess people put todo&#8217;s in their code for different reasons, it can be lazyness (I&#8217;ll write this hard/boring piece of code later), unclear requirements or maybe a debate is needed before a certain choice can be made. 
Be that as it may, some todo&#8217;s need to be solved more urgently than others: &#8220;TODO: implement [...]]]></description>
			<content:encoded><![CDATA[<p>I guess people put todo&#8217;s in their code for different reasons, it can be lazyness (I&#8217;ll write this hard/boring piece of code later), unclear requirements or maybe a debate is needed before a certain choice can be made. </p>
<p>Be that as it may, some todo&#8217;s need to be solved more urgently than others: &#8220;TODO: implement database logic&#8221; could be more urgent than &#8220;TODO: remove obsolete method&#8221;, but removing an obsolete method will probably be easier to do, so it might make sense to do it right away.</p>
<p>Visual Studio 2003 gave you a nice list of all the todo&#8217;s in your solution, but for some reason Visual Studio 2005 only does this for currently opened files. In the project I am current working on, we wanted a clear report of all todo&#8217;s in our code to make sure that they are solved as soon as possible. Since we already have a <a href="http://confluence.public.thoughtworks.org/display/CCNET/">CruiseControl.NET</a> server running, we decided to have our continuous integration build generate the TODO report for us. The samples in this post are valid for CruiseControl 1.1.</p>
<p><span id="more-28"></span></p>
<h3>1. Gathering the todo&#8217;s</h3>
<p>To generate the report, we&#8217;ll need to look through our codebase for lines that have a todo comment in them. This can be done using the <a href="http://blog.guymahieu.com/?p=26">RegexFinder NAnt task</a> described in a previous post. We&#8217;ll add the exact same target from the RegexFinder example (which looks for matches to the expression &#8220;//\s*TO\s*DO.*&#8221;) and add it to the NAnt build file used by our continuous integration build.</p>
<p>The target that we should call in the build file looks like this:<br />
<div id="mycode"><pre class="xml"><span style="color: #009900;"><span style="color: blue;">&lt;target</span> <span style="color: maroon;">name</span>=<span style="color: #ff0000;">&quot;find_todos&quot;</span><span style="color: blue;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: blue;">&lt;regexfinder</span> <span style="color: maroon;">pattern</span>=<span style="color: #ff0000;">&quot;//\s*TO\s*DO.*&quot;</span> 
               <span style="color: maroon;">outputfile</span>=<span style="color: #ff0000;">&quot;c:\todos.xml&quot;</span> 
               <span style="color: maroon;">ignorecase</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: blue;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;fileset</span> <span style="color: maroon;">basedir</span>=<span style="color: #ff0000;">&quot;C:\Project\MySources&quot;</span><span style="color: blue;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: blue;">&lt;include</span> <span style="color: maroon;">name</span>=<span style="color: #ff0000;">&quot;**/*.cs&quot;</span><span style="color: blue;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;/fileset<span style="color: blue;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: blue;">&lt;/regexfinder<span style="color: blue;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: blue;">&lt;/target<span style="color: blue;">&gt;</span></span></span></pre></div></p>
<p>The output of this task will be a file that looks like this:<br />
<div id="mycode"><pre class="xml"><span style="color: #009900;"><span style="color: blue;">&lt;regexFinder</span> <span style="color: maroon;">basedir</span>=<span style="color: #ff0000;">&quot;C:\Project\MySources&quot;</span><span style="color: blue;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: blue;">&lt;match<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;fileName<span style="color: blue;">&gt;</span></span></span>Business\DefaultFacade.cs<span style="color: #009900;"><span style="color: blue;">&lt;/fileName<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;lineNumber<span style="color: blue;">&gt;</span></span></span>57<span style="color: #009900;"><span style="color: blue;">&lt;/lineNumber<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;lineData<span style="color: blue;">&gt;</span></span></span>// TODO: add transaction logic<span style="color: #009900;"><span style="color: blue;">&lt;/lineData<span style="color: blue;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: blue;">&lt;/match<span style="color: blue;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: blue;">&lt;match<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;fileName<span style="color: blue;">&gt;</span></span></span>Presentation\BaseDetailsView.cs<span style="color: #009900;"><span style="color: blue;">&lt;/fileName<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;lineNumber<span style="color: blue;">&gt;</span></span></span>103<span style="color: #009900;"><span style="color: blue;">&lt;/lineNumber<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;lineData<span style="color: blue;">&gt;</span></span></span>// TO do: validate user input<span style="color: #009900;"><span style="color: blue;">&lt;/lineData<span style="color: blue;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: blue;">&lt;/match<span style="color: blue;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: blue;">&lt;/regexFinder<span style="color: blue;">&gt;</span></span></span></pre></div></p>
<h3>2. Integrating with CruiseControl.NET build output</h3>
<p>Ok, we have a list with all our todo&#8217;s, but to make CruiseControl aware of this file it needs to be merged into the main build output xml. This can be done easily by editing the ccnet.config file, make sure you have a merge entry for the xml file containing the todo&#8217;s  as follows:</p>
<p><div id="mycode"><pre class="xml"><span style="color: #009900;"><span style="color: blue;">&lt;cruisecontrol<span style="color: blue;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: blue;">&lt;project</span> <span style="color: maroon;">name</span>=<span style="color: #ff0000;">&quot;MyProject&quot;</span><span style="color: blue;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;publishers<span style="color: blue;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: blue;">&lt;merge<span style="color: blue;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: blue;">&lt;files<span style="color: blue;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></span>
          <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Merge the todo output with the ccnet output file --&gt;</span></span>
          <span style="color: #009900;"><span style="color: blue;">&lt;file<span style="color: blue;">&gt;</span></span></span>C:\Project\Builds\Artifacts\todos.xml<span style="color: #009900;"><span style="color: blue;">&lt;/file<span style="color: blue;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: blue;">&lt;/files<span style="color: blue;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: blue;">&lt;/merge<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;/publishers<span style="color: blue;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: blue;">&lt;/project<span style="color: blue;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: blue;">&lt;/cruisecontrol<span style="color: blue;">&gt;</span></span></span></pre></div></p>
<h3>3. Display TODO&#8217;s on the CruiseControl.NET web dashboard</h3>
<p>Now we just need to get it displayed on the ccnet dashboard webpage. To do this, we&#8217;ll need to transform the xml output of the RegexFinder to html. Also, we&#8217;d like a summary with the number of todo&#8217;s in the main page and a complete of all todo&#8217;s in a detailed report. To perform these transformations, I created two xslt files: <a id="p29" href="http://blog.guymahieu.com/wp-content/uploads/2006/11/TodosSummary.xsl">TodosSummary.xsl</a> and <a id="p30" href="http://blog.guymahieu.com/wp-content/uploads/2006/11/TodosReport.xsl">TodosReport.xsl</a>. </p>
<p>Now we&#8217;ll have to configure the ccnet webdashboard to include these into the build report webpage. This can be done by putting the two xsl files in the xsl folder of the webdashboard and editing the dashboard.config file as follows:</p>
<p><div id="mycode"><pre class="xml"><span style="color: #009900;"><span style="color: blue;">&lt;dashboard<span style="color: blue;">&gt;</span></span></span><span style="color: #009900;"><span style="color: blue;">&lt;plugins<span style="color: blue;">&gt;</span></span></span><span style="color: #009900;"><span style="color: blue;">&lt;buildPlugins<span style="color: blue;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Add the following elements to include TODO reports --&gt;</span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;buildReportBuildPlugin<span style="color: blue;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: blue;">&lt;xslFileNames<span style="color: blue;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: blue;">&lt;xslFile<span style="color: blue;">&gt;</span></span></span>xsl\TodosSummary.xsl<span style="color: #009900;"><span style="color: blue;">&lt;/xslFile<span style="color: blue;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: blue;">&lt;/xslFileNames<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;/buildReportBuildPlugin<span style="color: blue;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: blue;">&lt;xslReportBuildPlugin</span> 
        <span style="color: maroon;">description</span>=<span style="color: #ff0000;">&quot;TODO's Report&quot;</span> 
        <span style="color: maroon;">actionName</span>=<span style="color: #ff0000;">&quot;TodosBuildReport&quot;</span> 
        <span style="color: maroon;">xslFileName</span>=<span style="color: #ff0000;">&quot;xsl\TodosReport.xsl&quot;</span><span style="color: blue;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- End of changes for TODO report --&gt;</span></span>
<span style="color: #009900;"><span style="color: blue;">&lt;/buildPlugins<span style="color: blue;">&gt;</span></span></span><span style="color: #009900;"><span style="color: blue;">&lt;plugins<span style="color: blue;">&gt;</span></span></span><span style="color: #009900;"><span style="color: blue;">&lt;/dashboard<span style="color: blue;">&gt;</span></span></span></pre></div></p>
<p>All done! Just build your project, point your browser to the CruiseControl webdashboard and you should see your TODO&#8217;s!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.guymahieu.com/2007/01/22/todo-reports-in-cruisecontrolnet/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

