This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Dynamically pass the value to Annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dynamically pass the value to Annotation" Watch "Dynamically pass the value to Annotation" New topic
Author

Dynamically pass the value to Annotation

Talitha Bell
Greenhorn

Joined: Oct 01, 2007
Posts: 29
Hi All

I want to pass, dynamic value to the annotation........


I am using @XmlElement annotation there are two attribute in this annotation which I required ,type and name

@XmlElement(type=anyClassName.class, name = "anyValue")

Problem is this I don't know the class name because ,It comes at run time ,Is there any way to pass the information to annotation at runtime like this ,If there is any solution It would be very helpful to me.

class TheClass{

@XmlElement(type=anyClassName.class, name = "anyValue")
someMethod(){
......
}
}
[ October 18, 2008: Message edited by: Talitha ]

Thanks <br />Talitha
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Annotations can only be set at compile time; that also why their values can only be compile time constants. The only thing you can do with them at runtime is reading them.

In this case I would say that an interface with getter and setter methods for both class and name would be more appropriate.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: Dynamically pass the value to Annotation
 
Similar Threads
convert java classes to .xsd xml schema in eclise
How to make Axis2 bottom-up webservice make minOccurs="1" nillable="false"
Not able to pass Form parameters from jsp to servlet
XMLDocument.selectNodes
Not able to submit the hidden pramaters from one jsp to the next jsp