Loading Specific Class Versions
Now, you can use the container and restricted classloader to load components containing versioned classes from specified archives.
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.
|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 simultaneouslyboth created and used in the same running JVM.