<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: JSTL, instanceof, and hasProperty</title>
	<atom:link href="http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/feed/" rel="self" type="application/rss+xml" />
	<link>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
	<description>random musings of just another computer nerd</description>
	<lastBuildDate>Tue, 22 May 2012 16:32:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: sbk</title>
		<link>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/comment-page-1/#comment-41003</link>
		<dc:creator>sbk</dc:creator>
		<pubDate>Thu, 10 May 2012 09:19:51 +0000</pubDate>
		<guid isPermaLink="false">http://vivin.net/?p=1233#comment-41003</guid>
		<description>Thanks for this post which was most useful for me today. FYI org.apache.commons.beanutils.PropertyUtils could futher simplify your code (if you are happy with the dependency of course):

    public static boolean hasProperty(Object o, String propertyName) {
        if (o == null &#124;&#124; propertyName == null) {
            return false;
        }
		try
		{
		  return PropertyUtils.getPropertyDescriptor(o, propertyName) != null;
		}
		catch (Exception e)
		{
		  return false;
		}
	}</description>
		<content:encoded><![CDATA[<p>Thanks for this post which was most useful for me today. FYI org.apache.commons.beanutils.PropertyUtils could futher simplify your code (if you are happy with the dependency of course):</p>
<p>    public static boolean hasProperty(Object o, String propertyName) {<br />
        if (o == null || propertyName == null) {<br />
            return false;<br />
        }<br />
		try<br />
		{<br />
		  return PropertyUtils.getPropertyDescriptor(o, propertyName) != null;<br />
		}<br />
		catch (Exception e)<br />
		{<br />
		  return false;<br />
		}<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vivin</title>
		<link>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/comment-page-1/#comment-19074</link>
		<dc:creator>vivin</dc:creator>
		<pubDate>Thu, 11 Aug 2011 21:41:42 +0000</pubDate>
		<guid isPermaLink="false">http://vivin.net/?p=1233#comment-19074</guid>
		<description>Thanks for the improvements! I&#039;m adding them to the original post. :)</description>
		<content:encoded><![CDATA[<p>Thanks for the improvements! I&#8217;m adding them to the original post. <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thetoolman</title>
		<link>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/comment-page-1/#comment-19073</link>
		<dc:creator>thetoolman</dc:creator>
		<pubDate>Thu, 11 Aug 2011 21:35:28 +0000</pubDate>
		<guid isPermaLink="false">http://vivin.net/?p=1233#comment-19073</guid>
		<description>insanceOf now uses the callers classloader, and hasProperty now uses BeanInfo for inspection instead of doing it by hand :)</description>
		<content:encoded><![CDATA[<p>insanceOf now uses the callers classloader, and hasProperty now uses BeanInfo for inspection instead of doing it by hand <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thetoolman</title>
		<link>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/comment-page-1/#comment-19072</link>
		<dc:creator>thetoolman</dc:creator>
		<pubDate>Thu, 11 Aug 2011 21:32:47 +0000</pubDate>
		<guid isPermaLink="false">http://vivin.net/?p=1233#comment-19072</guid>
		<description>Thanks for posting; here is some improvements for your code:



    public static boolean instanceOf(Object o, String className) {
        if (o == null &#124;&#124; className == null) {
            return false;
        }
        try {
            return Class.forName(className, false, Thread.currentThread().getContextClassLoader()).isInstance(o);
        } catch (ClassNotFoundException e) {
            return false;
        }
    }

    public static boolean hasProperty(Object o, String propertyName) {
        if (o == null &#124;&#124; propertyName == null) {
            return false;
        }
        BeanInfo beanInfo;
        try {
            beanInfo = java.beans.Introspector.getBeanInfo(o.getClass());

        } catch (IntrospectionException e) {
            return false;
        }

        for (final PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
            if (propertyName.equals(pd.getName())) {
                return true;
            }
        }

        return false;
    }</description>
		<content:encoded><![CDATA[<p>Thanks for posting; here is some improvements for your code:</p>
<p>    public static boolean instanceOf(Object o, String className) {<br />
        if (o == null || className == null) {<br />
            return false;<br />
        }<br />
        try {<br />
            return Class.forName(className, false, Thread.currentThread().getContextClassLoader()).isInstance(o);<br />
        } catch (ClassNotFoundException e) {<br />
            return false;<br />
        }<br />
    }</p>
<p>    public static boolean hasProperty(Object o, String propertyName) {<br />
        if (o == null || propertyName == null) {<br />
            return false;<br />
        }<br />
        BeanInfo beanInfo;<br />
        try {<br />
            beanInfo = java.beans.Introspector.getBeanInfo(o.getClass());</p>
<p>        } catch (IntrospectionException e) {<br />
            return false;<br />
        }</p>
<p>        for (final PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {<br />
            if (propertyName.equals(pd.getName())) {<br />
                return true;<br />
            }<br />
        }</p>
<p>        return false;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vivin</title>
		<link>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/comment-page-1/#comment-1229</link>
		<dc:creator>vivin</dc:creator>
		<pubDate>Thu, 17 Dec 2009 02:23:03 +0000</pubDate>
		<guid isPermaLink="false">http://vivin.net/?p=1233#comment-1229</guid>
		<description>No problem! Glad you found it useful.</description>
		<content:encoded><![CDATA[<p>No problem! Glad you found it useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kalyan</title>
		<link>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/comment-page-1/#comment-1217</link>
		<dc:creator>Kalyan</dc:creator>
		<pubDate>Tue, 15 Dec 2009 17:33:11 +0000</pubDate>
		<guid isPermaLink="false">http://vivin.net/?p=1233#comment-1217</guid>
		<description>Thanks for posting this example Vivin.</description>
		<content:encoded><![CDATA[<p>Thanks for posting this example Vivin.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

