Java Reference
In-Depth Information
The entry point of any program using JDM is the creation of the
ConnectionFactory
. In this example, we show the ability to switch
easily from one JDM implementation to another using the Java
introspection mechanism. The argument provided in the text field
associated with the label “
Connection Factory
Implementation”
is
stored in a
JDMConsole
member variable called
mConnectionText-
Field.
This argument, including the full package path, is used as the
Java class name to the vendor-specific
ConnectionFactory
class. This
value is used as the first argument, called
iConnectionFactoryImpl,
of
the
getJDMFactory
method and is used as a
Class.forName()
argument
to instantiate a factory. We use this mechanism to dynamically switch
between vendor implementations provided the correct jars are in the
class path.
As presented in Chapter 9, there are three ways to create a valid
connection object to a DME in JDM. It is expected that most vendors
will provide the ability to create a connection through a URI. The
GUI allows users to specify a URI from three text fields: the vendor
connection factory, user name, and password. These text fields are
called
mURICombo, mNameTextField,
and
mPasswordTextField
. The
first one is a drop-down list (called a
combo box
or
combo
later in this
chapter) because we provided some default values for the URI used
to connect to a DME.
Once the user provides the required information, he can click on
the
Connect
button. The following code is then called:
1. private final void handlerConnectButton() {
2.
String lMsg
"";
3.
try {
4.
mDmeConn
getJDMConnection(mConnectionTextField.getText(),
5.
(String)mURICombo.getSelectedItem(),
6.
mNameTextField.getText(),
7.
mPasswordTextField.getText());
8.
ConnectionMetaData lMeta
mDmeConn.getMetaData();
9.
if (lMeta !
null) {
10.
lMsg
"Provider Name: "
lMeta.getProviderName()
" "
11.
"Provider Version: "
lMeta.getProviderVersion()
" "
12.
"Version: "
lMeta.getVersion();
13.
} else {
14.
lMsg
"No Vendor Information";
15.
}
16.
mMaxNameLength
mDmeConn.getMaxNameLength();
17.
mMaxDescriptionLength
mDmeConn.getMaxDescriptionLength();
18.
start(mDmeConn);
19.
} catch (JDMException lException) {
20.
JOptionPane.showMessageDialog(this,
Search WWH ::
Custom Search