001 /* PAVLOV -- Multiple Choice Study System
002 * Copyright (C) 2000 - 2004 T.J. Willis
003 *
004 * This program is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU General Public License
006 * as published by the Free Software Foundation; either version 2
007 * of the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, write to the Free Software
016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
017 *
018 * $Header: /cvsroot/pavlov/net/sourceforge/pavlov/randommedia/MediaLoader.java,v 1.4 2004/05/10 14:58:54 tj_willis Exp $
019 */
020 package net.sourceforge.pavlov.randommedia;
021
022 import java.net.URL;
023 import org.apache.log4j.*;
024
025 /**
026 * Describe class <code>MediaLoader</code> here.
027 *
028 * @author <a href="mailto:tj_willis@users.sourceforge.net">T.J. Willis</a>
029 * @version 1.0
030 */
031 public class MediaLoader extends Thread {
032 private MediaCache mediaCache;
033 private URL url;
034 private static Category cat
035 = Category.getInstance(MediaLoader.class.getName());
036
037 /**
038 * Creates a new <code>MediaLoader</code> instance.
039 *
040 * @param mediaCache a <code>MediaCache</code> value
041 * @param myURL an <code>URL</code> value
042 * @param priority an <code>int</code> value
043 */
044 public MediaLoader(MediaCache mediaCache,URL myURL, int priority)
045 {
046
047 assert mediaCache!=null: "Null MediaCache";
048 url = myURL;
049 if(url==null){
050 cat.warn("url is null in mediaLoader");
051 return;
052 }
053 this.mediaCache = mediaCache;
054 setPriority(priority);
055 //cat.debug("Loader loading " + url);
056 //start(); changed this to run 28 apr 04 during junit testing
057 run();
058 }
059
060 /**
061 * Describe <code>run</code> method here.
062 *
063 */
064 public void run() {
065 //cat.debug("Loader running for: " + url);
066 ContentLoader contentLoader = mediaCache.getContentLoader();
067 assert contentLoader!=null: "ContentLoader is null";
068 //cat.debug("Loading " + url + " with " + contentLoader.getClass());
069
070 try {
071 //Object mediaObject = Applet.newAudioClip(url);
072 Object mediaObject = contentLoader.loadContent(url);
073 //cat.debug("Loaded " + url + " with " + contentLoader.getClass());
074 //Object mediaObject = url.getContent();
075 if(mediaObject == null)
076 {
077 mediaCache.decrementNumberLoading();
078 return;
079 }
080 //AudioClip audioClip = Applet.newAudioClip(url);
081 mediaCache.add(mediaObject);
082 //cat.debug("Loaded object " + url);
083 } catch (Exception ex){
084 cat.warn("Exception loading object",ex);
085 }
086
087 }
088 }