Thursday, February 16, 2012

Oracle Writing multi lingual characters with Oracle file IO

If you have multi lingual characters like chinese to be written in a file or excel sheet from tables, using orcale file IO, It requires UTF-8 conversion. Just convert the character to UTF8 and write it. I tried using the utl_file.put raw, but i failed. When i used the below, it was working fine for me.
 l_file_handle:= utl_file.fopen('D:\',test.csv','W');
utl_file.put_line(l_file_handle,convert(l_str_head1,'UTF8'),TRUE);

Oracle - Alternative to between operator

When your query has joins to multiple table, and also you need a date operation to be carried with between operator. Hope you need to compromise on the query performance. An alternative way is to use subquery and in operator instead. Consider the below query with between operator
select A.a,A.a1,A.a2,B.b3,B.b4,C.c5 from TableA A
inner join TableB B on A.a1=B.a1
inner join Table C on c.c1=B.c1
where A.a3 between '10-May-01' AND '10-May-05'.
The above query takes around 65 seconds in my Sql explorer. An alternative to the query above is shown below
select A.a,A.a1,A.a2,B.b3,B.b4,C.c5 from TableA A
inner join TableB B on A.a1=B.a1
inner join Table C on c.c1=B.c1
where A.a3 in (select A.a3 from TABLEA where A.a3 between '10-May-01' AND '10-May-05')
Just a change in the where clause with sub query improves the query performance, and the query took just 1.14 secs.
I faced this situation and thought it will be of help to share it. Execuse me if I am wrong or if it is worthless to take your time. I am just a starter with oracle database. :)

Clustering and Load Balancing of JBoss 4.2

JBoss Clustering
As you all might be knowing how to cluster JBoss, by surfing various sites and blogs. This article doesn’t make difference in briefing you about JBoss clustering and Apache Load balancing.

Let me start of with explaining cluster.
Cluster: A cluster is a set of nodes. In Jboss each node is Jboss server instance. Multiple Jboss instances on same machine and different machine in same network forms a cluster.
There might be different clusters, differentiated by the name across same network.

To start the Jboss in cluster mode you need to use the following command

run –c “all”

We can specify each jboss instance to join a specific cluster by  specifying the name in /server/all/deploy/cluster-service.xml file. The default name will be of default partition.

When you run multiple instances of Jboss in same machine, then you might get the port conflict(like port already in use). Its not recommended to use multiple instance of Jboss in same machine. But if required we can run multiple instance of Jboss in same machine by resolving the port conflict either manually changing all the conflicting ports or by configuring the sample-binding.xml file.

You can get all the ports of Jboss which run independently, in the sample-binding.xml file. Here each set of ports will be defined under server name (port-default,port-01), you can use this server name in /server/all/conf/jboss-service.xml of each jboss server instance , by either changing the port number or using default port numbers in the sample-binding.xml file. Before that to enable this feature you need to uncomment the following piece of code in /server/all/conf/jboss-service.xml

   <mbean code="org.jboss.services.binding.ServiceBindingManager"
    >
     <attribute>ports-01</attribute>
     <attribute>${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>
     <attribute>
       org.jboss.services.binding.XMLServicesStoreFactory
     </attribute>
   </mbean>

You can even change the name and location of sample-binding.xml file.

Now let us start two Jboss server instances in same machine, to form a cluster automatically. For example,
http://localhost:8080/
http://localhost:8180/
Apache Load Balancing
After clustering Jboss we need to balance the load, and we need direct request to a jboss server with less load. (Also we need to have a common URL , instead exposing the clustered Joss servers url) . Here comes in picture, Apache web server.

In architecture, the apache web server will be placed in front of the Jboss server. Like the one shown in figure,



Now to configure the apache server,  for the cluster which we have created with 2 nodes in same machine. First download and install apache2.2.x. It will get installed in
/apache software foundation/apache2.2.x/.

First open the httpd.conf file under conf directory in your apache installation path and uncomment the following, which acts as connector between your webserver and Jboss application server.

LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_balancer_module modules/mod_proxy_balancer.soLoadModule proxy_http_module modules/mod_proxy_http.so
Next add the following lines in your httpd.conf file. Which says the webserver about the nodes that form the cluster and its url. And what is the URL to the webserver that will pass the request to application deployed in Jboss server instance.

<Proxy balancer://mycluster>       Order deny,allow       Allow from all       BalancerMember http://localhost:8080/test route=node1       BalancerMember http://localhost:8180/test route=node2</Proxy>      ProxyPass /jmx-console balancer://mycluster stickysession=JSESSIONID lbmethod=bytraffic nofailover=Off  ProxyPassReverse /test  http://localhost:8080/testProxyPassReverse /test  http://localhost:8180/test  You need to use the sticky session attribute to make the request available to both the Jboss server , to server request even during failover of other server. To be simple maintaining or duplication of session created in one server on the other server.

Whenever you need change your httpd.conf file, remember to restart your apache webserver service also.

Now to use Sticky session in Jboss make change to your Jboss instance server.xml file, like the following

<Engine defaultHost="localhost" jvmRoute="node1">..
..
..
</Engine>

Atlast we need to tell the Jboss web to add the jvm route to the incoming sessions, by making the usejk attribute to true, in jboss-service.xml under /deploy/jboss-webdeployer.war/META-INF

<attribute>true</attribute>
Now start both of your jboss server instances in same machine. And restart the Apache webserver.

Hope you find this article useful.
 

Ajax - Using Ajax Tags

You might have heard of Auto complete in many applications and web sites, where you need to select a option instead from combo box. A simple example is of Airline site where you will select your Destination airport and origin airport.



From developer’s perspective, the implementation of Auto complete option was being made easy day by day. And now by the use of Ajaxtags, the auto complete option was made much easier than the easiest.



Ajaxtags is open source, which can be downloaded from http://ajaxtags.sourceforge.net/.



With the use of Ajaxtags, we can perform the following Ajax operations just by using a simple tag.

•AutoComplete
•Callout
•Tree
•Update
•Tab Panel/Tab
•Toggle
•Select Dropdown.


In this article will explain you Autocomplete tag.



To implement autocomplete option for a text field using Ajax tags, you just need to write a small piece of code in the server side either using servlet or using struts action class, and call the server side action using the Autocomplete tag.



Following are some of the attributes that are must for Ajax autocomplete tag, for complete reference of tag attributes please refer http://ajaxtags.sourceforge.net/usage.html.




Attribute
Required
Detail

baseUrl
yes
Url of server side action class or servlet that gives the list of values.

Source
Yes
Text field where the user enters the search string

Target
Yes
Text field where the autocomplete selection will be populated

Parameters
Yes
List of comma separated parameters that will be passed to the server side.









First we need to design a form which has a text field and we will implement auto complete option for it.



Following is the JSP page that contains a form having a text field and Ajax Autocomplete tag. Make sure to add the autocomplete tag outside the form tag.

<%@ taglib uri="http://ajaxtags.sourceforge.net/tags/ajaxtags" prefix="ajax" %>












































ajax:autocomplete example




















You can see a list of script file imported at the top of the JSP page. You can get those script file when you download ajaxtags. Make sure that the script files are imported in the following order else, you will get script error. Next we will write a servlet code that serves as the value for the autcomplete options.



import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;



import net.sourceforge.ajaxtags.servlets.BaseAjaxServlet;

import net.sourceforge.ajaxtags.xml.AjaxXmlBuilder;



public class Ajaxservlet extends BaseAjaxServlet{





public String getXmlContent(HttpServletRequest request,

HttpServletResponse response) throws Exception {

System.out.println("Inside Base ajax Servlet");

System.out.println("Request: "+request.getParameter("country"));

AjaxXmlBuilder temp=new AjaxXmlBuilder();

temp.addItem("Angola", "angola");

temp.addItem("Angola1", "UK");

temp.addItem("Angola2", "USA");

String country=temp.toString();

return country;

}



}



Here in this servlet we are adding the value in name value pair, to ajaxxmlbuilder. When the servlet is called , the response of this servlet will be in XML format.



Make this as a war file and deploy it in a web container. You can see the autcomplete working for the text field defined.

EJB3 and JAAS Security

In this article, we will see how to implement JAAS security for a EJB3 Bean with JBOSS application sever, and how a stand alone client access the EJB in a secured manner. Here we will have a stateless session bean , configured in a secured domain named Trng. In the application server we need to configure a login module and the domain settings corresponding to the name. In the client side we will just configure login module, which will just pass the credentials to the server security domain. Below is the piece of code for bean class and remote interface.
@Stateless
@SecurityDomain("Trng")
@Remote(TestEjb.class)

public class TestEjbBean implements TestEjb{//,TimedObject{

@Resource
private SessionContext ctx;
@RolesAllowed(value="admin")
public String getMessage(String message) {
System.out.println("Message from client:: "+message+":");
System.out.println("CALLER IDENTITY"+ctx.getCallerPrincipal());
return "Hello "+message;
}
}
@Remote
public interface TestEjb extends java.rmi.Remote{
public String getMessage(String message);
}
In the above piece of code we have a method getMessage() which is secured and it can accessed only by the client having role admin. And you can notice how the security domain is configured for the bean. Using the @SecurityDomain("TRNG") it tells the bean that it belongs to the particular security domain. The security domain can be configured to use any loging module that the App server provides or the custom one which the user can write. In this example I am using a simple uersroleslogin module. Its configured within JBOSS_HOME/server/default/conf/login-config.xml. Following shows the configuration of the domain named Trng.
<application-policy name="Trng">
      <authentication>
        <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
          flag="required">
          <module-option name="usersProperties">props/users.properties</module-option>
          <module-option name="rolesProperties">props/roles.properties</module-option>
          <module-option name="unauthenticatedIdentity">anonymous</module-option>
        </login-module>
      </authentication>
    </application-policy>
Next we will create a standalone client , which will access the secured bean in a secured manner. For that we need to have a loginmodule in the client side, as dicussed earlier this login module should pass the credentials to the server side login module. Following is the configuration of loginmodule in the client side with file name auth.conf
clientlogin{org.jboss.security.ClientLoginModule required;
 };
Name of the login module is clientlogin. This has the login module ClientLoginModule passing the credentials to the server.
Following is the piece of code for the client that access the secured bean in seured manner.
public static void main(String[] args) throws NamingException, LoginException {
String authFile="D:/ui_rds1/temp/src/auth.conf";System.setProperty("java.security.auth.login.config", authFile);
LoginCallBackHandler lc=new LoginCallBackHandler("admin","admin");LoginContext loginContext=
new LoginContext("clientlogin",lc);
loginContext.login();
System.out.println("Logged In");
Properties p=new Properties();p.setProperty(
"java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" );
p.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );p.setProperty(
"java.naming.provider.url", "hostname:jnpport" );
InitialContext ic=new InitialContext(p);System.
out.println("Inititial context created");
TestEjb testEjb=(TestEjb) ic.lookup("TestEjbBean/remote");System.
out.println("Got the reference of Remote Interface");
System.out.println("Resulte from EJB::->"+testEjb.getMessage("Meiyappan"));
loginContext.logout();
testEjb.getMessage("sdfdsf");
}
In the above client set the system property to have the value of the location of conf file, which contains the loginmodule. Then we need to have a callback handler in which we will pass the username and password to the LoginContext. Following is a simplecall back handler class.
public class LoginCallBackHandler implements CallbackHandler{
private String username;
/**
* Password which will be set in the PasswordCallback, when PasswordCallback is handled
*/ private String password;
/**
* Constructor
* @param username The username
* @param password The password
*/
public LoginCallBackHandler(String username, String password) {
this.username = username;
this.password = password;
}
/**
* @param callbacks Instances of Callbacks
* @throws IOException IOException
* @throws UnsupportedCallbackException If Callback is other than NameCallback or PasswordCallback
*/ public void handle(Callback callbacks[]) throws IOException, UnsupportedCallbackException {
for(int i = 0; i < callbacks.length; i++) {
if(callbacks[i] instanceof NameCallback) {
NameCallback nc = (NameCallback)callbacks[i];
nc.setName(username);
System.out.println("USER NAME:: "+username);}
else if(callbacks[i] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback)callbacks[i];
pc.setPassword(password.toCharArray());
System.out.println("PASSWORD:: "+password);}
else { throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
}
}
}
}
Then we will create a logincontext with a name of the loginmodule which we gave in the .conf file and with the callbakhandler class instance, with the credentials set in the handler class. Now login using the login context. Next proceed with the normal lookup and access the method.For the specified username and password , we have the role admin defined in the roles.properties and users.properties file have this username and password. So the client will get the result from the bean. The logout from the logincontext and try to access the bean method again , you will be thrown with a EJBAcessException.
I hope this article is useful.

Timers and Interceptors in EJB3

Interceptors are used to intercept business method invocations og EJB3 bean class. The interceptors can be defined either class level or method level.
Also the interceptors can be in a seperate class using @Interceptor annotation or a method annotated with @AroundInvoke with signature Object methodname (InvocationContext ic)in the same class.
More than one interceptor classes can also be defined for a bean, using @Interceptor annotation. Interceptors have same life cycle as of that of associated bean and can have dependency injection in the same context.
Invocation Context
InvocationContext allows you to propagate through a chain of interceptors, along with its get/set methods, which even provides reference to the bean. Following are the methods that can be accessed by the handle provided.
Object getBean(): Provides the reference to the bean for which the Interceptor is defined.
Method getMethod():Provides information of about which method in the bean is called
Object[] getParameters():Provides infomation of the parameters passed to the bean.
void setParameters(): Set the parameter values
Map getContextData(): Provides context data that can be shared by the chain.
Object proceed(): Proceeds to the next interceptor in the chain or to the business method of the bean.
A simple example of using the Interceptor is illustrated below
package com.test;


1.import javax.ejb.Remote;
2.import javax.ejb.SessionContext;
3.import javax.ejb.Stateless;
4.import javax.ejb.TimedObject;
5.import javax.ejb.Timeout;
6.import javax.ejb.Timer;
7.import javax.ejb.TimerHandle;
8.import javax.ejb.TimerService;
9.@Stateless
mailto:10.@RemoteBinding(jndiBinding=%22Welcome")
11.@Remote(UpdateEJB.class)
12.@Interceptors(TestInterceptor.class)
13.public class UpdateEJBBean implements UpdateEJB {
14.private String message;
15.@Resource
16.private SessionContext ctx;
17.@Interceptors(TestInterceptor1.class)
18.public String sayHello(String name) {
19.System.out.println("Inside EJB method");
20.return "Hello " + name + message;
21.}
22.@AroundInvoke
23.public Object log(InvocationContext invocationContext) throws Exception {
24.System.err.println(invocationContext.getMethod().getName() + " called from interceptor 3");
25.return invocationContext.proceed();
26.}
27.}
28.The @RemoteBinding(jndiBinding="Welcome") is used to bind the EJB Bean to the JNDI name which we specify, instead using default JNDI name, provided by appserver vendors
29.The interceptor class will be like the one shown below.
30.public class TestInterceptor{
31.@AroundInvoke
32.public Object log(InvocationContext invocationContext) throws Exception {
33.System.err.println(invocationContext.getMethod().getName() + " called from interceptor 1");
34.return invocationContext.proceed();
35.}
36.}

1.public class TestInterceptor1{
2.@AroundInvoke
3.public Object log(InvocationContext invocationContext) throws Exception {
4.System.err.println(invocationContext.getMethod().getName() + " called from interceptor 1");
5.return invocationContext.proceed();
6.}
7.}
The order of Interceptor Invocation will be like
1.EJB Bean Class level Interceptor
2.EJB Bean Method level interceptor annotated by @Interceptor above the method
3.The method annotated with @AroundInvoke annotation.
Timer Service
Using EJB3 we can create a timely triggers and method invocations using the TimerService, provided by EJB3. You can either implement TimedObject interface, or you can
annotate method that you need to trigger after each timer expiration using @Timeout annotation.

1.package com.test;
2.import javax.ejb.Remote;
3.import javax.ejb.SessionContext;
4.import javax.ejb.Stateless;
5.import javax.ejb.TimedObject;
6.import javax.ejb.Timeout;
7.import javax.ejb.Timer;
8.import javax.ejb.TimerHandle;
9.import javax.ejb.TimerService;
10.import javax.ejb.TransactionAttribute;
11.import javax.ejb.TransactionManagement;
12.import javax.interceptor.AroundInvoke;
13.import javax.interceptor.InvocationContext;
14.@Stateless
mailto:15.@RemoteBinding(jndiBinding=%22Welcome")
16.@Remote(UpdateEJB.class)
17.public class UpdateEJBBean implements UpdateEJB,TimedObject {
18.private String message;
19.@Resource
20.private SessionContext ctx;
21.public String sayHello(String name) {
22.ctx.getTimerService().createTimer(6000, "HAI");
23.ctx.getTimerService().createTimer(6000,6000, "HAI");
24.return "Hello " + name + message;
25.}
26.public void ejbTimeout(Timer handle) {
27.System.out.println("handle.getTimeRemaining()"+handle.getTimeRemaining());
28.System.out.println("handle.getNextTimeout()"+handle.getNextTimeout());
29.}
30.}
To create the timer ctx.getTimerService().createTimer method is used, the timer timeout can be only once or frequently in a timed manner.
createTimer(6000,6000, "HAI") this says that the timer will expire in a period of 6000ms with initial delay of 6000ms.
The argument, Timer provides the handle to the timer, which has getTimeRemaining and getNextTimeout methods.
Instead of implementing interface you can also use annotation @Timeout above the method that needs to be triggered after each timer expiration.

</div>

Interceptors in Struts

The power of annotation is now available in struts2. All your validations can be made easy just by annotating the field, which you want to validate. Example, you can make a null check, email validation and some more built in validation annotators.

You can get the power of annotation in your application just , by annotating the getter method of the respective field in the JSP page.
Example
If I have a field name username in my struts2 JSP page, and I want to make a validation on it(If value is not entered, a message should be thrown) then, just annotate the action class using @validation and you can do the validation for textfield like

@RequiredStringValidator(message="Enter username ")
public String getUsername() {
return username;
}
And in the JSP page you can get the message in the same way, as how you get when you add a fielderror.

You can also invoke a method, before invoking your action class method, after execution of your action class method and before returning result from action method, by using @before, @after, and @before result annotations. For this to work you have to configure interceptor stack in your struts.xml .

  1. <interceptors>
  2. <interceptor name="annotationWorkFlow" class="com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptor"/>
  3. <interceptor-stack name="demostack">
  4. <interceptor-ref name="defaultStack" />
  5. <interceptor-ref name="annotationWorkFlow"/>
  6. /span>interceptor-stack>
  7. interceptors>
  8. <default-interceptor-ref name="demostack" />
If you add the above line within action tag then the interceptor tag will be applicable for that particular action alone. If you add the line out of the action tag then all the actions will pass through the set of interceptors.

You can also define your own interceptor classes.
For that your interceptor class should implement the interceptor interface. The example class is as shown below. Your request will pass through this interceptors in the order specified in the struts.xml file .
  1. public class TestInterceptor implements Interceptor{
  2. public String intercept(ActionInvocation next) throws Exception {
  3. long t1 = System.currentTimeMillis();
  4. String s= next.invoke();
  5. long t2 = System.currentTimeMillis();
  6. System.out.println("From Interceptor Action "+next.getAction().getClass().getName()+" took "+(t2-t1)+" millisecs");
  7. return s;
  8. }
  9. public void destroy() {
  10. }
  11. public void init() {
  12. // TODO Auto-generated method stub
  13. }
  14. }
Here the interceptor class just calculates the time taken to fullfill the request. The ActionInvoactions , invoke method will invoke the corresponding method in the action class.

To access the request and response within the Interceptor class, you need to getInvocationContext() and you need to get the HttpServletRequest and HttpServletResponse like this
HttpServletRequest request=(HttpServletRequest)next.getInvocationContext().get(StrutsStatics.HTTP_REQUEST);

HttpServletResponse response=(HttpServletResponse)next.getInvocationContext().get(StrutsStatics.HTTP_RESPONSE);

Thus annotations and Interceptors gives flexibility and ease of development of our application.

Accessing Session Variables in struts2

Accessing session variables in Struts2
Here in this post, I am going to show how to access variables in different scope , in struts2. In struts 2 we can set objects in the following scopes, say request, session, page and application.
To share the object between Java and Jsp expressions, we need to set the java object in any of the above said scopes and can access it using the struts tag in Jsp page.


For Example....
If I have a variable named foodCollection which contains a collection of different food items, I can set this in different scopes and can access it.
1. Session
In Java Action class
ActionContext.getContext().getSession().setAttribute("foodCollection",foodCollection);
In Struts2 Jsp page
#session.foodCollection
2.Request
request.setAttribute("foodCollection",foodCollection);
In Struts2Jsp
#request.foodCollection
3.Page
pageContext.setAttribute("foodCollection",foodCollection);
In Struts2Jsp
#attr.foodCollection

Here is a simple example of using struts2.
First add the following entry in your web.xml, so that all your requests pass through the filterdispatcher filter instead Action servlet in struts1.2.
<filter
filter-namestruts2filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcherfilter-class>
filter>

<filter-mapping>
<filter-name>struts2filter-name>
<url-pattern>*.dourl-pattern>
filter-mapping>

The default URL pattern is .action which can be changed by using the struts.properties file.

Next write your struts.xml file and place it in the package where you want.
Struts.xml contains the mapping between the request and the corresponding action class.
<package name="struts2" extends="struts-default">
<action name="showLogin">
<result>/jsp/master/login.jsp</result>
action>

action name="doLogin" class="action.Login">
<result name="input">/jsp/master/login.jspresult>
<result name="error">/jsp/master/login.jspresult>
<result>/jsp/master/loginsuccess.jspresult>
action>

package>

Write a java class which extends ActionSupport class of struts2, you can either have a default execute method or any method name according to the requirements.

In the action class you cant access the request and session directly, you need to either use ActionContext class like this,

ActionContext.getContext().getSession().put("TestLoop1",testingVos);

or need to implement the ServletRequestAware and ,ServletResponseAware and override its setter method, also you define your getter method which returns the request and response and you can access like the one shown below

getServletRequest().getSession().setAttribute("testSessionVar", "From Action class set in session");
getServletRequest().setAttribute("TestVariable", "From Action class set in request");

Suppose if you want to access a collection in the action class in JSP page you dont have to set the collection in session or request, you can access it in the JSP page by just having the name of the collection and a getter method for that collection in the StrutsAction class like this
I have a collection named testingVos which is a collection of testing vo
In Action class, the code snippet will be like the one....
public ArrayList getTestingVos(){
return testingVos;
}


In JSP page the code snippet will be

<s:iterator value="testingVos">
<s:property value="code"/><s:property value="type"/>
s:iterator>

Defining and reading a cutom annotation


In this article we will create a custom annotation , and use that annotation in a class, and also we will write a program which reads the annotation value.
You then, can understand how the dependency injection happens , using annotations.
Following is the code which shows of creating annotations.

@Retention(RetentionPolicy.RUNTIME)

public @interface Argument {
String value() default "";
boolean required() default false;
String description() default "";
}

The @Retention annotations is of great use which help us to define, whether the annotation can be used in class level, field level, method level or the combinations.
Next we will have a class that use this annotation

public class AnnotationTester {
@Argument(value = "input", description = "This is the input file", required = true)
public String inputFilename;
@Argument(value = "output", description = "This is the output file", required = true)
public String outputFilename;
@Argument(description = "This flag can optionally be set")
public boolean someflag;
public AnnotationTester(){

}

@Argument(value="testValue",required=true,description = "This is method")
public void callMe(){
System.out.println("Input: " + inputFilename);
System.out.println("Output: " + outputFilename);
System.out.println("Someflag: " + someflag);
}
@Argument(description = "This is method")
public void method1(){
System.out.println("Hi All");
}
}

So we have used the custom annotation which we have created in the above shown code.
Next we will write a class which will read all the annotations that are defined in the above class.
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Hashtable;
public class AnnotationReader
{
private static Object name=new AnnotationTester();
public AnnotationReader(Object name) throws Exception{
System.out.println(""+name);
this.name=name;
getAnnotateValue();
}
public AnnotationReader(){}
public void getAnnotateValue() throws Exception
{
Class<AnnotationTester> classObject = AnnotationTester.class;
//readAnnotation(classObject);
Method method1 = classObject.getMethod("method1", new Class[]{});
//readAnnotation(method1);

Field[] method2=classObject.getDeclaredFields();
for(int i=0;i<method2.length;i++){
System.out.println("Thi si smethod"+method2[i]);
System.out.println("Thi si smethod"+method2[3].get(name));
method2[3].set(name, "Meiyappan");
System.out.println("Hi-> "+((AnnotationTester)name).hhh);

}

Field[] fs=classObject.getDeclaredFields();
for(int j=0;j<fs.length;j++){
readAnnotation(fs[j]);
}
Method[] method=classObject.getDeclaredMethods();
for(int i=0;i<method.length;i++){
readAnnotation(method[i]);
}
}

static void readAnnotation(AnnotatedElement element)
{
try
{
System.out.println("\nFinding annotations on " + element.getClass().getCanonicalName());
Annotation[] classAnnotations = element.getAnnotations();
for(Annotation annotation : classAnnotations)
{
if (annotation instanceof Argument)
{
Argument argument = (Argument)annotation;
System.out.println("DESC:" + argument.description());
System.out.println("VALUE:" + argument.value());
System.out.println("REQUIRED:" + argument.required());
}
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
new AnnotationReader().getAnnotateValue();
}
}