advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Download the sample code for this article.
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
Average Rating: 3.5/5 | Rate this item | 22 users have rated this item.
Take Control of Class Loading in Java (cont'd)
Loading Specific Class Versions
Now, you can use the container and restricted classloader to load components containing versioned classes from specified archives.

Listing 2 shows how to instantiate instances of the component container and initialize them with the names of the configuration files for two different versions of a HelloWorld component. Each component version is then loaded and instantiated using the createComponent method of the ComponentContainer class.
advertisement


 
Figure 3. Component Sequence: The figure shows the sequence the component container framework follows to create a component.
Calls to each instantiated component object produce results from the expected versions of each component.

The sequence diagram in Figure 3 illustrates the steps taken by the framework to load and create a component:

Notice that calls to the RestrictedURLClassLoader class terminate before reaching an instance of the default classloader; thereby restricting class-searching to the URLs supplied to the RestrictedURLClassLoader instance.

So, you've seen how to build a class loading component container framework that facilitates a self-contained context in which to define, version, and create Java components. Exploiting Java's class loading capabilities in this manner restricts class-loading to specified locations, leting you load different versions of classes simultaneously—both created and used in the same running JVM.





Previous Page: Exploiting Classloader Namespaces  


Jeff Hanson has more than 18 years of experience in the software industry. He has worked as senior engineer for the Windows OpenDoc port and as lead architect for the Route 66 framework at Novell. He is currently Chief Architect for eReinsure, which specializes in providing frameworks and platforms for J2EE-based reinsurance systems. Jeff has also authored numerous articles and books.
Page 1: IntroductionPage 3: Exploiting Classloader Namespaces
Page 2: Archives and ComponentsPage 4: Loading Specific Class Versions
Please rate this item (5=best)
 1  2  3  4  5
advertisement