Java Reference
In-Depth Information
4.
throws JDMException, ClassNotFoundException {
5.
Class lClass
Class.forName(iConnectionFactoryImpl);
6.
ConnectionFactory lConnectionFactory;
7.
try {
8.
lConnectionFactory
(ConnectionFactory) lClass.newInstance();
9.
ConnectionSpec lCSpec
lConnectionFactory.getConnectionSpec();
10.
lCSpec.setURI(iURI);
11.
lCSpec.setName(iUserName);
12.
lCSpec.setPassword(iPassword);
13.
return lConnectionFactory.getConnection(lCSpec);
14.
} catch (InstantiationException lException) {
15.
lException.printStackTrace();
16.
} catch (IllegalAccessException lException) {
17.
lException.printStackTrace();
18.
}
19.
return null;
20. }
When using the introspection mechanism, we can receive an
InstantiationException
or an
IllegalAccessException
. The
Instantiation-
Exception
would be raised if the specified class object cannot be
instantiated because it is an interface or an abstract class. The
IllegalAccessException
would be raised if the application was trying to
reflectively create an instance but the currently executing method
does not have access to the definition of the specified class, field,
method, or constructor (if, for example, the constructor has been
declared as private). These two exceptions are low-level exceptions
that would be raised if the system can access the class specified by
the user but cannot use it for instantiation. Not much can be done to
offer any fallback in these scenarios. The
ClassNotFoundException,
which is thrown when the user-specified factory Java class name is
invalid, is re-raised to the caller. As a result, the graphical interface
will show an error message to ask for another connection factory
implementation.
13.2.2
Retrieving the List of Classes That Can Be Saved
As presented in Chapter 7, vendors may choose to implement the
persistence of certain named objects into a repository. If objects are
not persisted, they are discarded when the connection is closed. The
first operation performed by the administrative (Admin) console is
to determine which of the named objects are persisted and to pro-
vide them as a drop-down list for selection by the user. This list is
stored into a graphical combo box,
mPersistentObjectsCombo
, which
Search WWH ::
Custom Search