001 /*
002 * This file is part of the Echo Point Project. This project is a
003 * collection of Components that have extended the Echo Web Application
004 * Framework Version 3.
005 *
006 * Version: MPL 1.1
007 *
008 * The contents of this file are subject to the Mozilla Public License Version
009 * 1.1 (the "License"); you may not use this file except in compliance with
010 * the License. You may obtain a copy of the License at
011 * http://www.mozilla.org/MPL/
012 *
013 * Software distributed under the License is distributed on an "AS IS" basis,
014 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015 * for the specific language governing rights and limitations under the
016 * License.
017 */
018 package echopoint.tucana.event;
019
020 import java.util.logging.Logger;
021 import java.util.logging.Level;
022
023 /**
024 * An adapter class that logs the progress of a download command.
025 *
026 * @author Rakesh 2008-11-11
027 * @version $Id: DownloadCallbackAdapter.java 92 2008-11-11 19:49:44Z sptrakesh $
028 */
029 public class DownloadCallbackAdapter implements DownloadCallback
030 {
031 private static final long serialVersionUID = 1l;
032
033 /** The logger to use to log the download progress. */
034 protected static final Logger logger = Logger.getAnonymousLogger();
035
036 /** The log level to use. */
037 protected Level level;
038
039 /**
040 * Default constructor. Sets {@link #level} to {@link java.util.logging.Level#FINE}
041 */
042 public DownloadCallbackAdapter()
043 {
044 level = Level.FINE;
045 }
046
047 /**
048 * Create a new instance with the specified logging level.
049 *
050 * @param level The logging level to use.
051 */
052 public DownloadCallbackAdapter( final Level level )
053 {
054 this.level = level;
055 }
056
057 /**
058 * Indicate that a content download process has been started.
059 *
060 * @param event The download event object.
061 */
062 public void downloadStarted( final DownloadStartEvent event )
063 {
064 logger.log( level, "Download of file: " + event.getFileName() +
065 ", of size: " + event.getContentLength() +
066 ", and contentType: " + event.getContentType() + " started" );
067 }
068
069 /**
070 * Indicate that a content download process has ended successfully.
071 *
072 * @param event The download event object.
073 */
074 public void downloadFinished( final DownloadFinishEvent event )
075 {
076 logger.log( level, "Download of file: " + event.getFileName() +
077 ", of size: " + event.getContentLength() +
078 ", and contentType: " + event.getContentType() + " finished" );
079 }
080
081 /**
082 * Indicate that a content download process failed, usually due to reasons
083 * other than client cancellation.
084 *
085 * @param event The download fail event object.
086 */
087 public void downloadFailed( final DownloadFailEvent event )
088 {
089 logger.log( level, "Download of file: " + event.getFileName() +
090 ", of size: " + event.getContentLength() +
091 ", and contentType: " + event.getContentType() + " failed",
092 event.getException() );
093 }
094
095 /**
096 * Accessor for property 'level'.
097 *
098 * @return Value for property 'level'.
099 */
100 public Level getLevel()
101 {
102 return level;
103 }
104
105 /**
106 * Mutator for property 'level'.
107 *
108 * @param level Value to set for property 'level'.
109 */
110 public void setLevel( final Level level )
111 {
112 this.level = level;
113 }
114 }