本文件为JAVA开发的一个UFO游戏综合设计案例,直接在JAVA开发环境上运行,无需解压密码!

源代码在线查看: playlistfactory.java

软件大小: 25 K
上传用户: hcwlxhyq
关键词: JAVA UFO 综合设计 案例
下载地址: 免注册下载 普通下载 VIP

相关代码

				package javazoom.jlGui.playlist;
				
				import javazoom.Util.*;
				import java.lang.reflect.*;
				
				//PlaylistFactory.
				public class PlaylistFactory
				{
					private static PlaylistFactory	_instance = null;
					private	Playlist				_playlistInstance = null;
					private	Config					_config = null;
				
					/**
					 * Constructor.
					 */
					private PlaylistFactory()
					{
						_config = Config.getInstance();
					}
				
					/**
					 * Returns instance of PlaylistFactory.
					 */
					public synchronized static PlaylistFactory getInstance()
					{
						if (_instance == null)
						{
							_instance = new PlaylistFactory();
						}
						return _instance;
					}
				
					/**
					 * Returns Playlist instantied from full qualified class name.
					 */
					public Playlist getPlaylist()
					{
						if (_playlistInstance == null)
						{
				          String classname = _config.getPlaylistClassName();
				          boolean interfaceFound = false;
				          try
				          {
				            Class aClass = Class.forName(classname);
				            Class superClass = aClass;
				          	// Looking for Playlist interface implementation.
				            while (superClass != null)
				            {
				            	Class[] interfaces = superClass.getInterfaces();
				            	for (int i = 0; i < interfaces.length;i++)
				            	{
				            		if ( (interfaces[i].getName()).equals("javazoom.jlGui.playlist.Playlist") )
				            		{
				            		  interfaceFound = true;
				            		  break;
				            		}
								}
				            	if (interfaceFound == true) break;
				            	superClass = superClass.getSuperclass();
							}
				           	if (interfaceFound == false)
				           	{
				           	  trace(0,""+getClass().getName(),"Error : Playlist implementation not found in "+classname+" hierarchy");
				           	}
				           	else
				           	{
				       		  Class[] argsClass = new Class[] {};
				       		  Constructor c = aClass.getConstructor(argsClass);
				       		  _playlistInstance = (Playlist) (c.newInstance(null));
				       		  trace(0,""+getClass().getName(),classname + " loaded");
							}
				          } catch (Exception e)
				            {
				              trace(0,""+getClass().getName(),"Error : "+classname+" : "+e.getMessage());
				            }
						}
						return _playlistInstance;
					}
				
					/**
					 * Sends traces to Debug.
					 */
					private void trace(int level, String msg1, String msg2)
					{
						Debug dbg = Debug.getInstance();
						dbg.log(level,msg1+":"+msg2);
					}
				}
							

相关资源