Java reflection discussing the integration of reflection, JavaBeans,
CHAPTER 8 Using JavaBeans with tags By now you have seen how reflection is used to learn about a class at runtime. The tags we build in this chapter, like the standard JavaBean tags, will take as tag attributes the reference to an instance of a JavaBean and, for our printing tag, also the name of the property to print. Since the JSP author may specify any JavaBean instance at all, our tags will need to be able to take that instance at runtime and use reflection to find and call the proper methods. It should be clear that the only way to accomplish this is through the reflection API. Let us look at the syntax of that API in greater detail. NOTE Using the reflection API in order to introspect methods and later invoke them follows strict security rules that disallow overriding the Java security model. For example, one may not introspect private and package protected classes. 8.1.2 The reflection API The reflection APIs are contained in the Java package java.lang.reflect. Some of the more important classes in this package are shown in table 8.1. Table 8.1 Classes that are important for reflection Class Description Class Represents a Java class. Although not part of the java.lang.reflect package, this class is very important for reflection. Method Represents a method of class (also allows that method to be called). Array Supports creation and accessing of Java arrays (without having to know the exact type of the array in advance). Constructor Represents a specific class constructor (and allows that constructor to be called). The Class class The means to obtain all the constructors, methods, and fields for a particular class (or interface) in Java is through an instance of java.lang.Class. We obtain an instance of Class that corresponds to a particular Java class in a couple of ways: Calling Class.forName( com.manning.SomeClass ) where com.manning. SomeClass is the fully qualified name of the class we want to study. Referring to the class field of a particular Java class. Code for this looks like: Class c= com.manning.SomeClass.class
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services