<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>By Programmer For Programmer &#187; Uncategorized</title>
	<atom:link href="http://byprogrammerforprogrammer.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://byprogrammerforprogrammer.com</link>
	<description>Here I lay down the useful tips, tricks and utilities for programmers like myself.</description>
	<lastBuildDate>Thu, 15 Sep 2011 19:59:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Handy DWR ErrorHandler Callstack Function</title>
		<link>http://byprogrammerforprogrammer.com/2011/09/handy-dwr-errorhandler-callstack-function/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=handy-dwr-errorhandler-callstack-function</link>
		<comments>http://byprogrammerforprogrammer.com/2011/09/handy-dwr-errorhandler-callstack-function/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 19:49:41 +0000</pubDate>
		<dc:creator>Sean Adkinson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://byprogrammerforprogrammer.com/?p=121</guid>
		<description><![CDATA[Preamble I shared this with the DWR mailing list, and the guys thought it was useful, so I&#8217;m posting here to share with the world. Feel free to use this code under the Open Software License v. 3.0 (OSL-3.0). Background I wanted to have a &#8220;show technical details&#8221; link on our error popup that said [...]]]></description>
			<content:encoded><![CDATA[<h2>Preamble</h2>
<p>I shared this with the <a href="http://directwebremoting.org">DWR</a> <a href="http://dwr.2114559.n2.nabble.com/DWR-Users-f2114559.html">mailing list</a>, and the guys thought it was useful, so I&#8217;m posting here to share with the world.</p>
<p>Feel free to use this code under the <a href="http://www.opensource.org/licenses/OSL-3.0">Open Software License v. 3.0 (OSL-3.0)</a>.</p>
<h2>Background</h2>
<p>I wanted to have a &#8220;show technical details&#8221; link on our error popup that said what happened when an error occurred.</p>
<p>Environment:</p>
<ul>
<li>DWR 2.0.5</li>
<li>ExtJS 3.3.1</li>
</ul>
<div>Three classes:</div>
<div>
<ul>
<li><strong>BatchMapObtainer</strong> - This class retrieves the &#8220;batch map&#8221; from the current error handler callstack</li>
<li><strong>BatchMapWrapper</strong> - Wraps the &#8220;batch map&#8221; in order to wrap DWR-specific details</li>
<li><strong>ErrorHelper</strong> - Uses the above in order to construct a message for the user</li>
</ul>
</div>
<h2>The Code</h2>
<h5>FILE: BatchMapObtainer.js</h5>
<pre>Ext.ns('jx.core.dwr');

/**
 * @class jx.core.dwr.BatchMapObtainer
 * @static
 */
jx.core.dwr.BatchMapObtainer = function() {

	var isArgDwrBatch = function(arg) {
		return Ext.isDefined(arg.httpMethod) &amp;&amp; Ext.isDefined(arg.map);
	};

	var getDwrBatchFromArguments = function(args) {
		for (var i=0; i&lt;args.length; i++) {
			if (isArgDwrBatch(args[i])) {
				return args[i];
			}
		}
		return null;
	};

	var getBatchMapFromCallStack = function() {
		var currentFn = arguments.callee;
		var dwrBatch;
		var visitedFunctions = [];
		while (currentFn &amp;&amp; !dwrBatch) {
			dwrBatch = getDwrBatchFromArguments((currentFn.caller &amp;&amp; currentFn.caller.arguments) || []);
			if (visitedFunctions.indexOf(currentFn) !== -1) {
				currentFn = null;
			}
			else {
				visitedFunctions.push(currentFn);
				currentFn = currentFn.caller;
			}
		}
		return dwrBatch &amp;&amp; dwrBatch.map;
	};

	return {

		/**
                 * @method buildFromCallStack
                 * @static
		 * Tries to obtain a DWR batch map from the current call stack.
		 */
		obtainFromCallStack: function() {
			return getBatchMapFromCallStack();
		}

	};

}();</pre>
<h5></h5>
<h5>FILE: BatchMapWrapper.js</h5>
<pre>Ext.ns('jx.core.dwr');

/**
 * @class jx.core.dwr.BatchMapWrapper
 * @extends Object
 * Use to parse parameters from the DWR batch map.
 */
jx.core.dwr.BatchMapWrapper = Ext.extend(Object, {

	batchMap: null,

	constructor: function(batchMap) {
		this.batchMap = batchMap;
	},

	getBatchId: function() {
		return this.batchMap.batchId;
	},

	getBatchMap: function() {
		return this.batchMap;
	},

	/**
	 * @return Array of call details.  Each detail has "method" and "params" attributes
	 */
	getDwrCallDetails: function() {
		var callDetails = [];
		for (var i=0; this.hasCallDetailsFor(i); i++) {
			var params = [];
			for (var j=0; this.isParamDefined(i, j); j++) {
				params.push(this.getParamAt(i, j));
			}
			callDetails.push({
				method: this.getDwrCallNameFor(i),
				params: params
			});
		}
		return callDetails;
	},

	// private
	hasCallDetailsFor: function(callIndex) {
		return Ext.isDefined(this.batchMap['c' + callIndex + '-id']);
	},

	// private
	isParamDefined: function(callIndex, paramIndex) {
		return Ext.isDefined(this.getParamAt(callIndex, paramIndex));
	},

	// private
	getParamAt: function(callIndex, paramIndex) {
		return this.batchMap['c' + callIndex + '-param' + paramIndex];
	},

	// private
	getDwrCallNameFor: function(callIndex) {
		return this.getScripNameFor(callIndex) + '.' + this.getMethodNameFor(callIndex);
	},

	// private
	getScripNameFor: function(callIndex) {
		return this.batchMap['c' + callIndex + '-scriptName'];
	},

	// private
	getMethodNameFor: function(callIndex) {
		return this.batchMap['c' + callIndex + '-methodName'];
	}

});

/**
 * @method buildFromCallStack
 * @static
 * Tries to obtain a BatchMapWrapper wrapped around the "batch map" for the current call stack
 */
jx.core.dwr.BatchMapWrapper.buildFromCallStack = function() {
	var batchMap = jx.core.dwr.BatchMapObtainer.obtainFromCallStack();
	return batchMap ? new jx.core.dwr.BatchMapWrapper(batchMap) : null;
};</pre>
<h5></h5>
<h5>FILE: ErrorHelper.js</h5>
<pre>Ext.ns('jx.core.dwr');

/**
 * @class jx.core.dwr.ErrorHelper
 * @static
 * Helper to gain information about DWR calls.
 */
jx.core.dwr.ErrorHelper = function() {

	var getBaseDwrCallMessage = function(batchMapWrapper) {
		var message = '';
		var dwrCallDetails = batchMapWrapper.getDwrCallDetails();
		if (Ext.isArray(dwrCallDetails)) {
			for (var i=0; i&lt;dwrCallDetails.length; i++) {
				var details = dwrCallDetails[i];
				message += "DWR Call: " + details.method + "\nParams: " + Ext.util.JSON.encode(details.params);
			}
		}
		return message;
	};

	var getFullBatchMapMessage = function(batchMapWrapper) {
		var message = "Batch Map:";
		var batchMap = batchMapWrapper.getBatchMap();
		for (var key in batchMap) {
			if (!Ext.isFunction(batchMap[key])) {
				message += "\n   " + key + ": " + batchMap[key];
			}
		}
		return message;
	};

	return {

		getDwrCallDetailsFromCallStack: function() {
			var batchMapWrapper = jx.core.dwr.BatchMapWrapper.buildFromCallStack();
			return batchMapWrapper &amp;&amp; batchMapWrapper.getDwrCallDetails();
		},

		buildDwrCallDetailsMessageFromCallStack: function() {
			var message = '';
			var batchMapWrapper = jx.core.dwr.BatchMapWrapper.buildFromCallStack();
			if (batchMapWrapper) {
				message += getBaseDwrCallMessage(batchMapWrapper);
				message += "\n\n";
				message += getFullBatchMapMessage(batchMapWrapper);
				message += "\n\n";
			}
			return message;
		}

	};

}();</pre>
<h5></h5>
<h5>Example Usage:</h5>
<p>In DWR errorHandler, simply:</p>
<pre>var msg = jx.core.dwr.ErrorHelper.buildDwrCallDetailsMessageFromCallStack();
var id = Ext.id();
var html = '&lt;a href="" onclick="document.getElementById(\'' + id + '\').style.display=\'block\'; return false;"&gt;' +
	'Show Technical Details&lt;/a&gt;&lt;br /&gt;' +
	'&lt;div id="' + id + '" style="display: none;"&gt;&lt;textarea style="width: 100%; height: 150px;"&gt;' + msg +
	'&lt;/textarea&gt;&lt;/div&gt;';
Ext.Msg.alert("Error", html);</pre>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://byprogrammerforprogrammer.com/2011/09/handy-dwr-errorhandler-callstack-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JProfiler Helping Out With HTML4Java</title>
		<link>http://byprogrammerforprogrammer.com/2010/04/jprofiler-helping-out-with-html4java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jprofiler-helping-out-with-html4java</link>
		<comments>http://byprogrammerforprogrammer.com/2010/04/jprofiler-helping-out-with-html4java/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 16:57:00 +0000</pubDate>
		<dc:creator>Sean Adkinson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://byprogrammerforprogrammer.com/?p=86</guid>
		<description><![CDATA[Just wanted to give props real quick to the awesome profiler JProfiler (http://www.ej-technologies.com/products/jprofiler/overview.html) for providing me with an open-source license to profile my open-source project HTML4Java (https://sourceforge.net/projects/html4java/). The open-source community is so friendly .]]></description>
			<content:encoded><![CDATA[<p>Just wanted to give props real quick to the awesome profiler JProfiler (<a href="http://www.ej-technologies.com/products/jprofiler/overview.html">http://www.ej-technologies.com/products/jprofiler/overview.html</a>) for providing me with an open-source license to profile my open-source project HTML4Java (<a href="https://sourceforge.net/projects/html4java/">https://sourceforge.net/projects/html4java/</a>).  The open-source community is so friendly <img src='http://byprogrammerforprogrammer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://byprogrammerforprogrammer.com/2010/04/jprofiler-helping-out-with-html4java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Nested Loops: break or continue</title>
		<link>http://byprogrammerforprogrammer.com/2010/03/java-nested-loops-break-or-continue/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-nested-loops-break-or-continue</link>
		<comments>http://byprogrammerforprogrammer.com/2010/03/java-nested-loops-break-or-continue/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 23:58:37 +0000</pubDate>
		<dc:creator>Sean Adkinson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://byprogrammerforprogrammer.com/?p=82</guid>
		<description><![CDATA[Ever wanted to continue from a doubly-nested for loop? How about break from a switch statement more than one level deep? Simple! First you have to label your loop, and then put that label name after the break or continue keyword. &#8220;continue&#8221; example: fooloop: for(foo: foos) { ... barloop: for(bar : bars) { ... for [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to <code>continue</code> from a doubly-nested <code>for</code> loop?  How about <code>break</code> from a <code>switch</code> statement more than one level deep?</p>
<p>Simple!  First you have to label your loop, and then put that label name after the <code>break</code> or <code>continue</code> keyword.</p>
<p>&#8220;continue&#8221; example:</p>
<pre>
fooloop: for(foo: foos) {
    ...
    barloop: for(bar : bars) {
        ...
        for (blotto : blottos) {
            ...
            if (next_innermost_loop)
                continue; //normal
            if (next_middle_loop)
                continue barloop; //goes to the next iteration of "barloop"
            if (next_outer_loop)
                continue fooloop; //goes to the next iteration of the outermost loop, "fooloop"
        }
    }
}
</pre>
<p>&#8220;break&#8221; example:</p>
<pre>
fooswitch: switch(foo) {
    case 1:
        ...
        break;
    case 2:
        ...
       switch(bar) {
            ...
            if (break_this_switch)
                break; //normal
            if (break_outer_switch)
                break fooswitch; // breaks out of the out switch, "fooswitch"
        }
}
</pre>
<p>While most might consider this bad practice, when writing some scratch code to do some one-off task that only you will ever use, sometimes it&#8217;s nice to use a shortcut <img src='http://byprogrammerforprogrammer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://byprogrammerforprogrammer.com/2010/03/java-nested-loops-break-or-continue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse/Tomcat publishing lockup: &#8220;Could not delete file&#8230; may be locked by another process&#8221;</title>
		<link>http://byprogrammerforprogrammer.com/2009/12/eclipsetomcat-publishing-lockup-could-not-delete-file-may-be-locked-by-another-process/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=eclipsetomcat-publishing-lockup-could-not-delete-file-may-be-locked-by-another-process</link>
		<comments>http://byprogrammerforprogrammer.com/2009/12/eclipsetomcat-publishing-lockup-could-not-delete-file-may-be-locked-by-another-process/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 21:47:28 +0000</pubDate>
		<dc:creator>Sean Adkinson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://byprogrammerforprogrammer.com/?p=74</guid>
		<description><![CDATA[I was getting the annoying error in Eclipse with Tomcat where it didn&#8217;t think it could publish an application since some files were locked, when they were locked by the javaw.exe process that eclipse.exe started. The fix for me was to not have &#8220;Use Tomcat installation&#8221; selected in my server configuration. When I switched back [...]]]></description>
			<content:encoded><![CDATA[<p>I was getting the annoying error in Eclipse with Tomcat where it didn&#8217;t think it could publish an application since some files were locked, when they were locked by the javaw.exe process that eclipse.exe started.  The fix for me was to not have &#8220;Use Tomcat installation&#8221; selected in my server configuration.  When I switched back to the default of &#8220;Use workspace metadata&#8221;, the error stopped happening.</p>
]]></content:encoded>
			<wfw:commentRss>http://byprogrammerforprogrammer.com/2009/12/eclipsetomcat-publishing-lockup-could-not-delete-file-may-be-locked-by-another-process/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

