2. Evaluación en Educación y en Educación Física: Concepto, Características y Racionalidad
2.2. Concepto de evaluación en Educación y en Educación Física
2.2.2. Concepto de evaluación en Educación Física
Because of theconnect( )method’s size and importance, we will examine it closely, line by line. Theconnect( )method begins with these lines:
// Display Connect dialog box.
ConnectDialog dialog = new ConnectDialog(this); dialog.show();
Before a connection can be made to an e-mail server, the connection settings have to be entered into the application. AConnectDialogis instantiated and displayed to capture the connection settings.
Once the connection settings have been captured by theConnectDialog, they are used to create a JavaMail connection URL.
// Build connection URL from Connect dialog box settings. StringBuffer connectionUrl = new StringBuffer();
connectionUrl.append(dialog.getType() + "://"); connectionUrl.append(dialog.getUsername() + ":"); connectionUrl.append(dialog.getPassword() + "@"); connectionUrl.append(dialog.getServer() + "/");
JavaMail connection URLs have the following scheme:
protocol://username:password@hostname
For example, to connect to a server namedmailserver.comwith a username ofjohndoe
and a password ofpass1234using the POP3 protocol, the URL would be: pop3://johndoe:[email protected]
Next, aDownloadingDialogis instantiated and then run to display an informational message on the screen while e-mail is being downloaded.
/* Display dialog box stating that messages are currently being downloaded from server. */ final DownloadingDialog downloadingDialog =
new DownloadingDialog(this);
SwingUtilities.invokeLater(new Runnable() { public void run() {
downloadingDialog.show();
P:\010Comp\ApDev\971-3\ch05.vp Monday, July 07, 2003 10:03:53 AM
Color profile: Generic CMYK printer profile Composite Default screen
} });
When a modal dialog box, likeDownloadingDialog, is displayed on the screen, the current thread of execution is halted until the dialog box is terminated. This behavior is normally the desired effect; however, it is not desirable for E-mail Client. In the case of E-mail Client, theDownloadingDialogneeds to be displayed while downloading is taking place, not prior to downloading. To achieve this, the Downloading dialog box is run in a separate thread from Swing’s main event execution thread with a call toSwingUtilities.invokeLater( ).
After launching the Downloading dialog box, the actual work of connecting to the e-mail server takes place. First, a JavaMail session is initialized by the following sequence:
// Establish JavaMail session and connect to server. Store store = null;
try {
// Initialize JavaMail session with SMTP server. Properties props = new Properties();
props.put("mail.smtp.host", dialog.getSmtpServer()); session = Session.getDefaultInstance(props, null);
Notice that the JavaMail session is passed a set of properties that contains the SMTP server address. JavaMail sessions store the configuration options and authentication information used to interact with an e-mail server. Storing this information in theSessionobject allows it to be reused throughout the application by JavaMail’s classes. In E-mail Client’s case, the session data is used by theTransportclass to send messages in thesendMessage( )method.
After initializing the JavaMail session, the connection to the e-mail server is made in the following code:
// Connect to mail server.
URLName urln = new URLName(connectionUrl.toString()); store = session.getStore(urln);
store.connect(); } catch (Exception e) {
// Close the Downloading dialog box. downloadingDialog.dispose();
// Show error dialog box.
showError("Unable to connect.", true); }
JavaMail usesStoreobjects to represent a message store and its access protocol for storing and retrieving messages. A message store is analogous to an e-mail account; thus
C h a p t e r 5 : I m p l e m e n t i n g a n E - m a i l C l i e n t i n J a v a
1 6 1
AppDev TIGHT/ The Art of Java / Schildt/Holmes / 222971-3 / Chapter 5
such as POP3 or IMAP. In the preceding code, the actual network connection to the e-mail server is established by retrieving aStorebased on the protocol entered in the Connect dialog box and then calling itsconnect( )method.
First, aURLNameobject is instantiated with the connection URL constructed earlier using data entered in the Connect dialog box. TheURLNameobject is then passed to the session’s
getStore( )method. ThegetStore( )method returns aStoreobject based on theURLName
object’s protocol. After thestorehas been retrieved, itsconnect( )method is invoked. Remember that POP3 servers only support the notion of one folder, whereas IMAP servers can have multiple folders. Thus, once the connection has been successfully established with the e-mail server, the default “INBOX” folder is opened and its messages are retrieved as shown in the following code:
// Download message headers from server. try {
// Open main "INBOX" folder.
Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_WRITE);
// Get folder's list of messages.
Message[] messages = folder.getMessages();
When a list of messages is retrieved from a folder, as shown in the preceding listing, each
Messageobject is empty. TheFolderobject’sgetMessages( )method simply returns an array of emptyMessageobjects, each one representing a message in the folder. JavaMail uses this technique to allow messages to be downloaded on demand, thus minimizing the amount of data being downloaded from an e-mail server.
Since E-mail Client needs to have each message’s data available when displaying the list of messages in the table, the following code retrieves the message headers ahead of time instead of having them loaded on demand:
// Retrieve message headers for each message in folder. FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE); folder.fetch(messages, profile);
// Put messages in table.
tableModel.setMessages(messages); } catch (Exception e) {
// Close the Downloading dialog box. downloadingDialog.dispose();
// Show error dialog box.
P:\010Comp\ApDev\971-3\ch05.vp Monday, July 07, 2003 10:03:54 AM
Color profile: Generic CMYK printer profile Composite Default screen
showError("Unable to download messages.", true); }
In order to load the messages ahead of time, aFetchProfileobject is created. Fetch profiles are used to specify the portions of a message that should be loaded or “fetched” ahead of time. TheFetchProfilecreated in the preceding code fetches the “envelope” portion of messages. Message envelopes are an aggregation of the most common message headers, such as the sender, recipient, and subject.
After retrieving the message fields ahead of time with aFetchProfile, the messages are added to the messages table with a call totableModel.setMessages( ). The messages table is then updated, listing each of the messages downloaded from the server.
Theconnect( )method wraps up by closing the modalDownloadingDialog, as shown here. The user is now free to interact with the application again.
// Close the Downloading dialog box. downloadingDialog.dispose();