com.sun.syndication.util
Class PlugableClasses

java.lang.Object
  extended bycom.sun.syndication.util.PlugableClasses

public class PlugableClasses
extends java.lang.Object

Loads and instantiates classes indicated in property files.

The PlugableClasses is useful for handling collection of classes that are not known or fixed at development time.

It reads the class names from a default properties file and from an additional properties file indicated through a System property. The additional properties file does not override the default properties file, the classes are aggregated.

Author:
Alejandro Abdelnur

Constructor Summary
PlugableClasses(java.lang.String defaultFile, java.lang.String systemPropertyFile, java.lang.String propertyKey)
          Creates a PlugableClasses instance that will load the classes indicated in properties files.
PlugableClasses(java.lang.String defaultFile, java.lang.String systemPropertyFile, java.lang.String propertyKey, boolean hardFailure, java.lang.ClassLoader classLoader)
          Creates a PlugableClasses instance that will load the classes indicated in properties files.
 
Method Summary
 java.lang.Object[] createInstances()
          Loads, instanciates and returns the classes defined in the properties files.
 java.lang.Class[] getClasses()
          Loads and returns the classes defined in the properties files.
 boolean isHardFailure()
          Returns the hard failure mode for the PlugableClasses instance.
 void setHardFailure(boolean hardFailure)
          Sets the hard failure mode for the PlugableClasses instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlugableClasses

public PlugableClasses(java.lang.String defaultFile,
                       java.lang.String systemPropertyFile,
                       java.lang.String propertyKey)
Creates a PlugableClasses instance that will load the classes indicated in properties files.

It uses the same ClassLoader of the PlugableClasses and it is set for hard failure (a RuntimeException will be thrown if one or more of the classes cannot be loaded or instanciated).

Parameters:
defaultFile - properties file that defines the classes to load
systemPropertyFile - system property that if present it should be indicate an additional properties file to look for classes to load. The additional properties file does not override the default properties file, the classes are aggregated.
propertyKey - property name that contains the list of classes to load. The class names must be separated with white spaces.

PlugableClasses

public PlugableClasses(java.lang.String defaultFile,
                       java.lang.String systemPropertyFile,
                       java.lang.String propertyKey,
                       boolean hardFailure,
                       java.lang.ClassLoader classLoader)
Creates a PlugableClasses instance that will load the classes indicated in properties files.

Parameters:
defaultFile - properties file that defines the classes to load
systemPropertyFile - system property that if present it should be indicate an additional properties file to look for classes to load. The additional properties file does not override the default properties file, the classes are aggregated.
propertyKey - property name that contains the list of classes to load. The class names must be separated with white spaces.
hardFailure - indicates if a RuntimeException will be thrown if one or more of the classes cannot be loaded or instanciated. Otherwise it will ignore the failure and continue with the other classes.
classLoader - ClassLoader to use for loading the properties files and classes.
Method Detail

setHardFailure

public void setHardFailure(boolean hardFailure)
Sets the hard failure mode for the PlugableClasses instance.

If a hard failure mode is OFF, a ClassNotFoundException will be thrown if one of the classes cannot be loaded or instanciated. Otherwise it will ignore the failure and continue with the other classes.

Parameters:
hardFailure - true to set hard failure to ON, false to set it to OFF.

isHardFailure

public boolean isHardFailure()
Returns the hard failure mode for the PlugableClasses instance.

If a hard failure mode is OFF, a RuntimeException will be thrown if one of the classes cannot be loaded or instanciated. Otherwise it will ignore the failure and continue with the other classes.

Returns:
true to set hard failure to ON, false to set it to OFF.

getClasses

public java.lang.Class[] getClasses()
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
Loads and returns the classes defined in the properties files.

Returns:
array containing the classes defined in the properties files.
Throws:
java.io.IOException - thrown if the properties files cannot be found or read, and hard failure is ON.
java.lang.ClassNotFoundException - thrown if one of the classes defined in the properties file cannot be loaded and hard failure is ON.

createInstances

public java.lang.Object[] createInstances()
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException,
                                          java.lang.InstantiationException
Loads, instanciates and returns the classes defined in the properties files.

Returns:
array containing the classes defined in the properties files.
Throws:
java.io.IOException - thrown if the properties files cannot be found or read, and hard failure is ON.
java.lang.ClassNotFoundException - thrown if one of the classes defined in the properties files cannot be loaded and hard failure is ON.
java.lang.InstantiationException - thrown if one of the classes defined in the properties files cannot be instantiated and hard failure is ON.


Copyright © 2004 Sun Microsystems. All Rights Reserved.