<?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>Ankit Virparia &#187; Introspection</title>
	<atom:link href="http://ankit.co/tag/introspection/feed" rel="self" type="application/rss+xml" />
	<link>http://ankit.co</link>
	<description>A Programmer, Designer and Trainer</description>
	<lastBuildDate>Sun, 11 May 2014 04:15:47 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>How to retrieve Java Bean Metadata</title>
		<link>http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-retrieve-java-bean-metadata</link>
		<comments>http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata#comments</comments>
		<pubDate>Sat, 05 Jan 2013 11:37:55 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Java Bean]]></category>
		<category><![CDATA[Introspection]]></category>
		<category><![CDATA[Java Bean Metadata]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=126</guid>
		<description><![CDATA[<p>Now, The question is How to retrieve the information about a given java bean class(I mean compiled class). That information is also known as Metadata: There are again 2 ways! And its based on how we have describe the Bean. As seen in previous tutorial &#8211; Link We have 2 methods to describe a Bean. [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata">How to retrieve Java Bean Metadata</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<ol>
Now, The question is How to retrieve the information about a given java bean class(I mean compiled class). That information is also known as Metadata:<br />
There are again 2 ways! And its based on how we have describe the Bean. As seen in previous tutorial &#8211; <a href="http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection">Link</a><br />
We have 2 methods to describe a Bean.</p>
<ol>
<li>Naming Conventions</li>
<li>By writing an additional class that extends the BeanInfo interface</li>
</ol>
<p><strong class="trheading">1. Naming Conventions</strong>.</p>
<pre class="brush: java; title: ; notranslate">
import java.beans.*;
public class EmpIntrospector 
{
	public static void main(String args[]) 
	{
		try 
		{
			Class c = Class.forName(&quot;Employee&quot;);
			BeanInfo beanInfo = Introspector.getBeanInfo(c);
			System.out.println(&quot;Properties:&quot;);
			PropertyDescriptor propertyDescriptor[] = beanInfo.getPropertyDescriptors();
			for(int i = 0; i &lt; propertyDescriptor.length; i++) 
			{
				System.out.println(&quot;\t&quot; + propertyDescriptor[i].getName());
			}
			System.out.println(&quot;Events:&quot;);
			EventSetDescriptor eventSetDescriptor[] = beanInfo.getEventSetDescriptors();
			for(int i = 0; i &lt; eventSetDescriptor.length; i++) 
			{
				System.out.println(&quot;\t&quot; + eventSetDescriptor[i].getName());
			}
		}
		catch(Exception e) 
		{
			System.out.println(&quot;Exception caught. &quot; + e);
		}
	}
}
</pre>
<p>In above sample code we are retrieving metadata by getting propertyDescriptor[] / eventDescriptopr[] using beanInfo Interface. </p>
<p><strong class="trheading">2. By writing an additional class that extends the BeanInfo interface</strong>.</p>
<pre class="brush: java; highlight: [11]; title: ; notranslate">
import java.beans.*;
public class EmpIntrospector2
{
	public static void main(String args[]) 
	{
		try 
		{
			Class c = Class.forName(&quot;Employee&quot;);
			BeanInfo beanInfo = Introspector.getBeanInfo(c);
			System.out.println(&quot;Properties:&quot;);
			PropertyDescriptor propertyDescriptor[] = new EmployeeBeanInfo().getPropertyDescriptors();
                        for(int i = 0; i &lt; propertyDescriptor.length; i++) 
			{
				System.out.println(&quot;\t&quot; + propertyDescriptor[i].getName());
			}
			System.out.println(&quot;Events:&quot;);
			EventSetDescriptor eventSetDescriptor[] = new EmployeeBeanInfo().getEventDescriptors(); 
			for(int i = 0; i &lt; eventSetDescriptor.length; i++) 
			{
				System.out.println(&quot;\t&quot; + eventSetDescriptor[i].getName());
			}
		}
		catch(Exception e) 
		{
			System.out.println(&quot;Exception caught. &quot; + e);
		}
	}
}
</pre>
<p>In above sample code we are retrieving metadata by getting propertyDescriptor[] / eventDescriptopr[] using our defined class &#8220;EmployeeBeanInfo&#8221; which was describing Employee bean.</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata">How to retrieve Java Bean Metadata</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Bean Introspection</title>
		<link>http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-bean-introspection</link>
		<comments>http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection#comments</comments>
		<pubDate>Sat, 05 Jan 2013 08:14:59 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Java Bean]]></category>
		<category><![CDATA[Introspection]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=103</guid>
		<description><![CDATA[<p>Introspection It is the self-examination of one&#8217;s conscious thoughts and feelings. [reference: Wikipedia] Java Bean Introspection It is the examination provided by a Java Bean class! But a class cannot speak. A developer has to write the description about the bean so that Other developers can understand the Bean properties/methods/events etc. In short, The process [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection">Java Bean Introspection</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><strong>Introspection</strong><br />
It is the self-examination of one&#8217;s conscious thoughts and feelings. [<strong>reference:</strong> <a href="http://en.wikipedia.org/wiki/Introspection">Wikipedia</a>]</p>
<p><strong>Java Bean Introspection</strong><br />
It is the examination provided by a Java Bean class! But a class cannot speak. A developer has to write the description about the bean so that Other developers can understand the Bean properties/methods/events etc.<br />
In short, The process to describe a Bean is known as Bean Introspection. </p>
<p><strong>Which is done by two ways:</strong></p>
<ol>
<li>Naming Conventions(What we did in previous tutorial &#8211; <a href="http://ankit.co/tutorials/java-tutorials/java-bean/introduction-to-java-bean">Link</a>)</li>
<li>By writing an additional class that extends the BeanInfo interface</li>
</ol>
<p><strong>In Brief:</strong><br />
<strong class="trheading">1. Naming Conventions</strong>.</p>
<ul>
<li><strong>Simple/Single Property: </strong>
<pre class="brush: java; title: ; notranslate">
    private int id;
    public void setId(int id) 
    {
        this.id = id;
    }

    public String getName() 
    {
        return name;
    }
</pre>
</li>
<li><strong>Indexed Property: </strong>
<pre class="brush: java; title: ; notranslate">
private double data[ ];
public double getData(int index) 
{
	return data[index];
}
public void setData(int index, double value) 
{
	data[index] = value;
}
public double[ ] getData( ) 
{
	return data;
}
public void setData(double[ ] values) 
{
	data = new double[values.length];
	System.arraycopy(values, 0, data, 0, values.length);
}
</pre>
</li>
<li><strong>Events: </strong>
<pre class="brush: java; title: ; notranslate">
public void addEventListener(EventListener e) 
{
	// code
}
public void removeEventListener(EventListener e) 
{
	// code
}
</pre>
</li>
</ul>
<p><strong class="trheading">2. By writing an additional class that extends the BeanInfo interface</strong></p>
<p>The BeanInfo interface enables us to explicitly control what information is available in a Bean. The BeanInfo interface defines following:</p>
<pre class="brush: java; title: ; notranslate">
PropertyDescriptor[ ] getPropertyDescriptors( )
EventSetDescriptor[ ] getEventSetDescriptors( )
MethodDescriptor[ ] getMethodDescriptors( )
</pre>
<p><strong>Now we are going to describe all the properties of Employee.class by using java.beans.SimpleBeanInfo(Derived from BeanInfo Interface):</strong></p>
<ul>
<li><strong>Property Descriptor: </strong>
<pre class="brush: java; title: ; notranslate">
import java.beans.SimpleBeanInfo;
public class EmployeeBeanInfo extends SimpleBeanInfo 
{
	public PropertyDescriptor[] getPropertyDescriptors() 
	{
		try 
		{
			PropertyDescriptor pdId = new PropertyDescriptor(&quot;id&quot;, Employee.class);
			PropertyDescriptor pdName = new PropertyDescriptor(&quot;name&quot;, Employee.class);
			PropertyDescriptor pdContact = new PropertyDescriptor(&quot;contact&quot;, Employee.class);
			PropertyDescriptor pd[] = {pdId, pdName, pdContact};
			return pd;
		}
		catch(Exception e) 
		{
			System.out.println(&quot;Exception caught. &quot; + e);
		}
	return null;
	}
}
</pre>
</li>
</ul>
<p>Same way we can describe Events and Methods of the Bean class.</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection">Java Bean Introspection</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
