<?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; Java Bean Metadata</title>
	<atom:link href="http://ankit.co/tag/java-bean-metadata/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>
	</channel>
</rss>
