<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>hasan&#039;s blog (বল্গ) &#187; tips</title>
	<atom:link href="http://we4tech.wordpress.com/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://we4tech.wordpress.com</link>
	<description>work for fun!!!</description>
	<lastBuildDate>Wed, 25 Jan 2012 11:56:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='we4tech.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/77f5f3e5f84d83c83da12540728f5cb3?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>hasan&#039;s blog (বল্গ) &#187; tips</title>
		<link>http://we4tech.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://we4tech.wordpress.com/osd.xml" title="hasan&#039;s blog (বল্গ)" />
	<atom:link rel='hub' href='http://we4tech.wordpress.com/?pushpress=hub'/>
		<item>
		<title>create new url protocol to load spring configuration resource from the relative path</title>
		<link>http://we4tech.wordpress.com/2008/04/18/create-new-url-protocol-to-load-spring-configuration-resource-from-the-relative-path/</link>
		<comments>http://we4tech.wordpress.com/2008/04/18/create-new-url-protocol-to-load-spring-configuration-resource-from-the-relative-path/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 18:17:42 +0000</pubDate>
		<dc:creator>nhm tanveer hossain khan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java ee]]></category>
		<category><![CDATA[spring framework]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://hasan.we4tech.com/create-new-url-protocol-to-load-spring-configuration-resource-from-the-relative-path/</guid>
		<description><![CDATA[i had a problem with spring framework, as you know while we are defining dependency over the xml documents, it becomes less changeable unless you know about my recent post about ext-util namespace handler and if you know any other alternatives. before digging inside the problem better i clarify my context - i have been &#8230; <a href="http://we4tech.wordpress.com/2008/04/18/create-new-url-protocol-to-load-spring-configuration-resource-from-the-relative-path/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=405&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>i had a problem with spring framework, as you know while we are defining dependency over the xml documents, it becomes less changeable unless you know about my recent post about <a href="http://hasan.we4tech.com/ext-utilresource-new-spring-namespace-for-loading-property-from-different-scope-ie-system-test-dev/">ext-util namespace handler</a> and if you know any other alternatives.</p>
<p>before digging inside the problem better i clarify my context -</p>
<p>i have been working with one of my projects, where i have a several configurations which suppose to be different in different deployment environment, for example &#8211; to make my service avail, user has to define his database, his content index directory, server port, ip address and few more.</p>
<p>all these configurations were kept within the spring bean declaration scope. though few of them were moved to the properties file through <a href="http://hasan.we4tech.com/ext-utilresource-new-spring-namespace-for-loading-property-from-different-scope-ie-system-test-dev/">ext-util namespace handler</a>.</p>
<p>previously to make those configuration changeable i kept those files under WEB-INF/classes so it overrides the default bundled resource.</p>
<p>but still it wasn&#8217;t user friendly, since my user has to change one xml document to add more index services also he has to edit different configurations from java properties file.</p>
<p>again when i started bundling jetty with my whole application i found it is tricker to keep those xml outside of application, since i don&#8217;t wanna make my user confused with lot of xml files. and i have to keep few xml out of  my classpath context, so spring has to load my configuration from my &#8220;config/index-configuration/&#8221; directory.</p>
<p>though by default spring can do it over &#8220;file:///absolute/path/to/file.xml&#8221; since spring is using java URL class to locate this resource.  but in my case i can&#8217;t put any aboslute path.<br />
so i found a simple way out there to support relative path reference.</p>
<p>previously i had the following xml document -</p>
<p><!-- import index services --></p>
<p><!-- available item index services --></p>
<p>now i have replaced them with the following change -</p>
<p><!-- import index services --><br />
<strong><br />
</strong></p>
<p><!-- available item index services --></p>
<p>if you observe closely you will find &#8220;extfile:///&#8221; protocol reference, which is not standard url protocol. so to make it work i used the following bunch of code and configuration -</p>
<p>1. i have created a class &#8220;Handler&#8221; under the &#8220;com.ideabase.repository.core.protocols.extfile&#8221; package.<br />
this package and class name is conventional, though you can change them lets sun <a href="http://java.sun.com/developer/onlineTraining/protocolhandlers/">explain about it.</a></p>
<p>2. i wrote the following code -</p>
<p>public class Handler extends URLStreamHandler {<br />
protected URLConnection openConnection(final URL pURL) throws IOException {<br />
final String path = pURL.getPath();<br />
final URL resourceUrl;<br />
if (path.startsWith(&#8220;/./&#8221;)) {<br />
resourceUrl = new File(path.substring(1, path.length())).toURL();<br />
} else {<br />
throw new RuntimeException(&#8220;Unsupported url schema. currently you can &#8221; +<br />
&#8220;use only extfile:///./path/to/somewhere/in&#8221;);<br />
}<br />
return resourceUrl.openConnection();<br />
}<br />
}<br />
3. i registered my protocol package through the system property -</p>
<p>System.setProperty(&#8220;java.protocol.handler.pkgs&#8221;, &#8220;com.ideabase.repository.core.protocols&#8221;);</p>
<p>now have a look on the main applicationContext.xml</p>
<p><strong><br />
</strong><br />
if you observe closely again you could find the difference, on the normal case i have used relative path reference. so it must be from classloader or if it is loaded through file system based resource locator it will be located from the file system.</p>
<p>but now i can use cross context (relative file system and class loader path reference) resource file path reference. you can see i have imported &#8220;indexer-beans.xml&#8221; from the application relative path &#8220;config/index-configuration/&#8230;&#8221; where &#8220;data-access-layer-beans.xml&#8221; is loaded from the class loader.<br />
now have a quick look on my configuration directory, to get an idea how i have improved configuration ability.<br />
<img class="alignleft size-medium wp-image-431" title="picture-1" src="http://we4tech.files.wordpress.com/2008/04/picture-1.png?w=300&#038;h=66" alt="picture-1" width="300" height="66" /></p>
<p>hope this will help you to solve similar problem.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/we4tech.wordpress.com/405/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/we4tech.wordpress.com/405/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/we4tech.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/we4tech.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/we4tech.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/we4tech.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/we4tech.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/we4tech.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/we4tech.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/we4tech.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/we4tech.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/we4tech.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/we4tech.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/we4tech.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/we4tech.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/we4tech.wordpress.com/405/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=405&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://we4tech.wordpress.com/2008/04/18/create-new-url-protocol-to-load-spring-configuration-resource-from-the-relative-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4bb774de244da2d6e7f39a189b905077?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hasan</media:title>
		</media:content>

		<media:content url="http://we4tech.files.wordpress.com/2008/04/picture-1.png?w=300" medium="image">
			<media:title type="html">picture-1</media:title>
		</media:content>
	</item>
		<item>
		<title>uncaught exception: Permission denied to get property Object.constructor</title>
		<link>http://we4tech.wordpress.com/2007/12/30/uncaught-exception-permission-denied-to-get-property-objectconstructor/</link>
		<comments>http://we4tech.wordpress.com/2007/12/30/uncaught-exception-permission-denied-to-get-property-objectconstructor/#comments</comments>
		<pubDate>Sun, 30 Dec 2007 07:58:14 +0000</pubDate>
		<dc:creator>nhm tanveer hossain khan</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://hasan.we4tech.com/uncaught-exception-permission-denied-to-get-property-objectconstructor/</guid>
		<description><![CDATA[seems you are getting &#8220;uncaught exception: Permission denied to get property Object.constructor&#8221; while you are  executing some javascript which was instantiating some objects and during that time it stucked with some exception. for example function get(pUpdate, pUrl, pParams) { new Ajax.Updater(pUpdate, pUrl, {parameters: pParams}); } if you want to regenerate this exception you can invoke &#8230; <a href="http://we4tech.wordpress.com/2007/12/30/uncaught-exception-permission-denied-to-get-property-objectconstructor/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=390&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>seems you are getting &#8220;uncaught exception: Permission denied to get property Object.constructor&#8221; while you are  executing some javascript which was instantiating some objects and during that time it stucked with some exception.</p>
<p>for example</p>
<p>function get(pUpdate, pUrl, pParams) {<br />
new Ajax.Updater(pUpdate, pUrl, {parameters: pParams});<br />
}</p>
<p>if you want to regenerate this exception you can invoke this function with the following arguments -</p>
<p>get(&#8220;abc&#8221;, &#8220;http://abc&#8221;)</p>
<p>so why this crap ?</p>
<p>the main reason is in your code where you mentioned about &#8220;parameters&#8221; and which is not supposed to be null. you better write the following code -</p>
<p>function get(pUpdate, pUrl, pParams) {<br />
var options = new Array();<br />
if (pParams != null) {<br />
options["parameters"] = pParams;<br />
}</p>
<p>new Ajax.Updater(pUpdate, pUrl, options);<br />
}<br />
that will take away your javascript exception.</p>
<p>best wishes,<!--ad04f3532ed57400b9d6076e25c5c38a--></p>
</p>
<p><!--f73179b3f04d1c7c82ca5411ae48fd2f-->
</p>
<p><!--49e0d34ca2cd0a35fe5fa98e268ea7a0--></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/we4tech.wordpress.com/390/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/we4tech.wordpress.com/390/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/we4tech.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/we4tech.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/we4tech.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/we4tech.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/we4tech.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/we4tech.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/we4tech.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/we4tech.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/we4tech.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/we4tech.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/we4tech.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/we4tech.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/we4tech.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/we4tech.wordpress.com/390/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=390&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://we4tech.wordpress.com/2007/12/30/uncaught-exception-permission-denied-to-get-property-objectconstructor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4bb774de244da2d6e7f39a189b905077?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hasan</media:title>
		</media:content>
	</item>
		<item>
		<title>simple fragment cache implementation on ruby on rails</title>
		<link>http://we4tech.wordpress.com/2007/11/17/simple-fragment-cache-implementation-on-ruby-on-rails/</link>
		<comments>http://we4tech.wordpress.com/2007/11/17/simple-fragment-cache-implementation-on-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 21:00:55 +0000</pubDate>
		<dc:creator>nhm tanveer hossain khan</dc:creator>
				<category><![CDATA[cache]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://hasan.we4tech.com/simple-fragment-cache-implementation-on-ruby-on-rails</guid>
		<description><![CDATA[i was getting serious performance problem with one of my projects. so i came up with a simple fragment cache implementation on ruby on rails. after implementing this stuff, i replaced &#8220;render(:partial =&#62; &#8230;)&#8221; with the following method - render_from_cache_or_render(:cache_key =&#62;”cache key”, :cache_expire_after =&#62; ConstantHelper::TAG_CLOUD_EXPIRED_IN, # minutes :partial =&#62; “….”) let&#8217;s have a look on &#8230; <a href="http://we4tech.wordpress.com/2007/11/17/simple-fragment-cache-implementation-on-ruby-on-rails/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=385&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>i was getting serious performance problem with one of my projects. so i came up with a simple fragment cache implementation on ruby on rails.</p>
<p>after implementing this stuff, i replaced &#8220;render(:partial =&gt; &#8230;)&#8221; with the following method -</p>
<blockquote>
<pre>render_from_cache_or_render(:cache_key =&gt;”cache key”, :cache_expire_after =&gt; ConstantHelper::TAG_CLOUD_EXPIRED_IN, # minutes :partial =&gt; “….”)</pre>
</blockquote>
<p>let&#8217;s have a look on my implementation -</p>
<blockquote><p>def render_from_cache_or_render(p_args)</p>
<p>return render(p_args) if true == p_args[:cache_off]</p>
<p># check from cache<br />
cache_key = p_args[:cache_key]<br />
cached_content = CacheService.get_cache(cache_key)</p>
<p>if not cached_content.nil? and not cached_content.empty?<br />
return cached_content<br />
else<br />
content = render(p_args)<br />
# cache expire time if defined<br />
cache_expire_time_in_minutes = p_args[:cache_expire_after] || 60<br />
CacheService.add_cache(cache_key, cache_expire_time_in_minutes, content)<br />
return content<br />
end<br />
end</p></blockquote>
<p>actually, my implemented &#8220;CacheService&#8221; class is simply storing all cache in a hash map.<br />
when some cache was requested for peek, cache expiry was checked before returning the cached value.</p>
<p>for CacheService implementation look at the bottom of my post.</p>
<p>anyway, after implementing and utilizing this stuff, i gained 70+ requests capability per second. fyi, before applying cache it was around 10 per second.</p>
<blockquote><p>module Cache<br />
class Item<br />
attr_accessor :key, :expire_time, :content, :created_on</p>
<p>def initialize(p_key, p_expire_time, p_content)<br />
@key = p_key<br />
@expire_time = p_expire_time * 60 # in minutes<br />
@content = p_content<br />
@created_on = Time.now<br />
end<br />
end<br />
end</p>
<p>class CacheService<br />
@@CACHES = {}<br />
@@CACHE_EXPIRE_TIMES = {}</p>
<p>def self.add_cache(p_key, p_expire_time, p_content)<br />
cache_item = Cache::Item.new(p_key, p_expire_time, p_content)<br />
@@CACHES[p_key.to_sym] = cache_item<br />
end</p>
<p>def self.get_cache(p_key)<br />
# load content from cache<br />
cached_content = @@CACHES[p_key.to_sym]<br />
return nil if cached_content.nil?</p>
<p># verify cache validity<br />
return cached_content.content if not expired?(cached_content)<br />
return nil<br />
end</p>
<p>private<br />
def self.expired?(p_cache)<br />
# find time difference<br />
time_difference = Time.now &#8211; p_cache.created_on<br />
return true if time_difference &gt; p_cache.expire_time<br />
end<br />
end</p></blockquote>
<p>best wishes,<!--3d03e28513b3f05efbe65bc64219c415--></p>
<p><!--f6265e57e7aec9039f352fd813fc9a58--></p>
<p><!--5d693aaea750a2e28b4ea43ff6938b40--></p>
<p><!--4d046ce81eef3b7632a83741ad51e2d5--></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/we4tech.wordpress.com/385/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/we4tech.wordpress.com/385/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/we4tech.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/we4tech.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/we4tech.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/we4tech.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/we4tech.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/we4tech.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/we4tech.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/we4tech.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/we4tech.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/we4tech.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/we4tech.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/we4tech.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/we4tech.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/we4tech.wordpress.com/385/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=385&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://we4tech.wordpress.com/2007/11/17/simple-fragment-cache-implementation-on-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4bb774de244da2d6e7f39a189b905077?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hasan</media:title>
		</media:content>
	</item>
		<item>
		<title>damn simple!!!, define instance variables in ruby way</title>
		<link>http://we4tech.wordpress.com/2007/08/31/damn-simple-define-instance-variables-in-ruby-way/</link>
		<comments>http://we4tech.wordpress.com/2007/08/31/damn-simple-define-instance-variables-in-ruby-way/#comments</comments>
		<pubDate>Thu, 30 Aug 2007 18:39:38 +0000</pubDate>
		<dc:creator>nhm tanveer hossain khan</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://hasan.we4tech.com/damn-simple-define-instance-variables-in-ruby-way</guid>
		<description><![CDATA[i was creating a new class where a hash object will be passed with value and key. my class suppose to iterate for each key and value. and those key will be treated as the instance variable. so the pretty simple job i did is the following lines of code block - def initialize(p_params = &#8230; <a href="http://we4tech.wordpress.com/2007/08/31/damn-simple-define-instance-variables-in-ruby-way/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=356&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>i was creating a new class where a hash object will be passed with value and key. my class suppose to iterate for each key and value. and those key will be treated as the instance variable.</p>
<p>so the pretty simple job i did is the following lines of code block -</p>
<p><strong> def</strong> <em>initialize</em>(p_params = {})<br />
<strong>super</strong>()<br />
<strong>unless </strong>p_params.empty?<br />
p_params.each do |key, value|<br />
<strong>eval </strong><em>%(<br />
self.#{key} = value<br />
)</em><br />
<strong>end</strong><br />
<strong>end</strong><br />
<strong>end </strong></p>
<p>surprisingly my instance variable declaration became soooooo simple and easy.</p>
<p><strong>update:</strong><br />
i didn&#8217;t know that <em>self.send(&#8220;#{key}=&#8221;, value)</em> does the same job, obviously send is prefer way to do this job.
</p>
<p><!--f866f6d0cdda02fe45f48b046968fdf4--></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/we4tech.wordpress.com/356/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/we4tech.wordpress.com/356/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/we4tech.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/we4tech.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/we4tech.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/we4tech.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/we4tech.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/we4tech.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/we4tech.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/we4tech.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/we4tech.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/we4tech.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/we4tech.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/we4tech.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/we4tech.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/we4tech.wordpress.com/356/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=356&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://we4tech.wordpress.com/2007/08/31/damn-simple-define-instance-variables-in-ruby-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4bb774de244da2d6e7f39a189b905077?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hasan</media:title>
		</media:content>
	</item>
		<item>
		<title>Visitor Design pattern to traverse hierarchical object structure.</title>
		<link>http://we4tech.wordpress.com/2007/06/01/visitor-design-pattern-to-traverse-hierarchical-object-structure/</link>
		<comments>http://we4tech.wordpress.com/2007/06/01/visitor-design-pattern-to-traverse-hierarchical-object-structure/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 17:05:30 +0000</pubDate>
		<dc:creator>nhm tanveer hossain khan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java SE]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://hasan.we4tech.com/visitor-design-pattern-to-traverse-hierarchical-object-structure</guid>
		<description><![CDATA[Those who know about visitor design pattern, i am not triggering my write up for them. but those who didn&#8217;t know about this or heard but always ignored i am writing for them. Visitor design patter is used to traverse through the object structure. it is used to separate the iterating logic from the object. &#8230; <a href="http://we4tech.wordpress.com/2007/06/01/visitor-design-pattern-to-traverse-hierarchical-object-structure/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=333&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">Those who know about visitor design pattern, i am not triggering my write up for them. but those who didn&#8217;t know about this or heard but always ignored i am writing for them.</p>
<p class="MsoNormal">Visitor design patter is used to traverse through the object structure. it is used to separate the iterating logic from the object.</p>
<p class="MsoNormal">Let&#8217;s imagine, you have the following object structure :</p>
<p class="MsoNormal">class Tree {</p>
<p class="MsoNormal">private List mBranches;</p>
<p class="MsoNormal">public List getBranches() {</p>
<p class="MsoNormal">return mBranches;</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">
<p class="MsoNormal">how we usually iterate through this list of objects, lets think like following code -</p>
<p class="MsoNormal">// &#8230;.</p>
<p class="MsoNormal">final List branches = tree.getBranches();</p>
<p class="MsoNormal">for (final Branch branch : branches) {</p>
<p class="MsoNormal">// &#8230;</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">// &#8230;</p>
<p class="MsoNormal">
<p class="MsoNormal">visitor design pattern emphases API designer to hide underlying  object structure and iterating logic. now let&#8217;s see how we can implement the above example using visitor design pattern:</p>
<p class="MsoNormal">
<p class="MsoNormal">interface Visitor {</p>
<p class="MsoNormal">void visit(final Branch pBranch);</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">interface Visitable {</p>
<p class="MsoNormal">void accept(final Visitor pVisitor);</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">class Tree implements Visitable {</p>
<p class="MsoNormal">// &#8230; previous code</p>
<p class="MsoNormal">public void visit(final Visitor pVisitor) {</p>
<p class="MsoNormal">for (final Branch branch : mBranches) {</p>
<p class="MsoNormal">pVisitor.visit(branch);</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">
<p class="MsoNormal">now my concern is to make it &#8220;n&#8221; depth. so it will become a real tree with &#8220;n&#8221; depth, where can traverse branches and leafs. who is it possible over visitor dp.</p>
<p class="MsoNormal">
<p class="MsoNormal">here is simple extension over visitor patter, which will enable visitor to visit &#8220;n&#8221; depth hierarchical object structure.</p>
<p class="MsoNormal">
<p class="MsoNormal">let&#8217;s define our interfaces:</p>
<p class="MsoNormal">interface Visitor {</p>
<p class="MsoNormal">void visit(final int pDepth, final TreeItem pItem);</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">interface Visitable {</p>
<p class="MsoNormal">void accept(final Visitor pVisitor);</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">
<p class="MsoNormal">our tree class:</p>
<p class="MsoNormal">class Tree implements Visitable {</p>
<p class="MsoNormal">private TreeItem mRootItem;</p>
<p class="MsoNormal">// &#8230; setter getter</p>
<p class="MsoNormal">
<p class="MsoNormal">class TreeItem {</p>
<p class="MsoNormal">private String name;</p>
<p class="MsoNormal">// .. Setter getter</p>
<p class="MsoNormal">private List<br />
mTreeItems;
</p>
<p class="MsoNormal">// .. Setter getter</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">
<p class="MsoNormal">public void accept(final Visitor pVisitor) {</p>
<p class="MsoNormal">visitRecursivlyTreeItem(0, pVisitor, mRootItem);</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">
<p class="MsoNormal">private visitRecursivlyTreeItem(int pLevel, final Visitor pVisitor, final TreeItem pItem) {</p>
<p class="MsoNormal">pVisitor.visit(pLevel, pItem);</p>
<p class="MsoNormal">for (final TreeItem item : pVisitor.getTreeItems()) {</p>
<p class="MsoNormal">visitRecursivlyTreeItem(pLevel + 1, pVisitor, pItem);</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">
<p class="MsoNormal">
<p class="MsoNormal">That’s all <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/we4tech.wordpress.com/333/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/we4tech.wordpress.com/333/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/we4tech.wordpress.com/333/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/we4tech.wordpress.com/333/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/we4tech.wordpress.com/333/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/we4tech.wordpress.com/333/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/we4tech.wordpress.com/333/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/we4tech.wordpress.com/333/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/we4tech.wordpress.com/333/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/we4tech.wordpress.com/333/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/we4tech.wordpress.com/333/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/we4tech.wordpress.com/333/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/we4tech.wordpress.com/333/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/we4tech.wordpress.com/333/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/we4tech.wordpress.com/333/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/we4tech.wordpress.com/333/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=we4tech.wordpress.com&amp;blog=537526&amp;post=333&amp;subd=we4tech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://we4tech.wordpress.com/2007/06/01/visitor-design-pattern-to-traverse-hierarchical-object-structure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4bb774de244da2d6e7f39a189b905077?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hasan</media:title>
		</media:content>
	</item>
	</channel>
</rss>
