JavaServer Page

February 4, 2007

The Show tag interesting; we already know how

Filed under: JSP Tag Libraries — webmaster @ 11:34 am

The Show tag interesting; we already know how a method is called using reflection and the only new issue here is that you see how to provide parameters to the invoked method using an array of objects. E 1) Looks for the method in the introspected methods cache The second method presents several new ideas, starting with the use of a method cache, continuing with introspecting indexed properties, and ending with our own low-level introspection when the default Introspector fails us. The method cache was added when we found out how time-consuming introspection is. In fact, in pages loaded with reflection, adding the method cache gave the pages a 33% performance boost. It s important to remember that the key to the cache needs to be a combination of the object s class, property name, and method parameters. This is a rather complex key, so a new method key object was created (when caching methods for indexed setters, the key is even more involved). If we fail to find a method in the cache, we will introspect it and, when complete, place it in the cache. F Method not in the cache, start introspecting. G Skip methods that do not match our needs H Validate that this method matches our indexed property I Skip methods that do not match our needs Introspecting the class is different from introspection code in listing 8.2, mainly because we now introspect indexed properties. We iterate over the properties descriptor array and differentiate between indexed (instances of IndexedPropertyDescriptor) from non-indexed properties, and then check on the indexed property method. The check includes testing the parameter list of the indexed property, because a certain method in Java may be overloaded. For example, think of the following class: class SuperHero{ Power getSuperPower(int i); Power getSuperPower(String s); } We may want to inspect getSuperPower(String), yet the Introspector will prob ably give us the descriptor of getSuperPower(int). We will then need to skip this descriptor and hope our luck is better elsewhere. J Method was not found using the default introspector; try our own low-level introspection We are finally finished with the property introspection, yet we may not have found the property method. The above example, wherein a specific method has two index types, is a good example of such a case (no, it is not a bug in the default Introspector, just our desire to attain more than the simple indexes regulated in JavaBeans). To overcome cases in which the default Introspector fails to find the needed method, we employ elementary low-level reflection to look for a method

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Java Web Hosting