2
* 11/19/04 1.0 moved to LGPL.
3
* 29/01/00 Initial version. mdm@techie.com
4
*-----------------------------------------------------------------------
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU Library General Public License as published
7
* by the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*----------------------------------------------------------------------
21
package javazoom.jl.player;
23
import java.util.Enumeration;
24
import java.util.Hashtable;
26
import javazoom.jl.decoder.JavaLayerException;
29
* The <code>FactoryRegistry</code> class stores the factories for all the
30
* audio device implementations available in the system.
32
* Instances of this class are thread-safe.
38
public class FactoryRegistry extends AudioDeviceFactory {
39
static private FactoryRegistry instance = null;
41
static synchronized public FactoryRegistry systemRegistry() {
42
if (instance == null) {
43
instance = new FactoryRegistry();
44
instance.registerDefaultFactories();
49
protected Hashtable factories = new Hashtable();
52
* Registers an <code>AudioDeviceFactory</code> instance with this
55
public void addFactory(AudioDeviceFactory factory) {
56
factories.put(factory.getClass(), factory);
59
public void removeFactoryType(Class cls) {
60
factories.remove(cls);
63
public void removeFactory(AudioDeviceFactory factory) {
64
factories.remove(factory.getClass());
67
public AudioDevice createAudioDevice() throws JavaLayerException {
68
AudioDevice device = null;
69
AudioDeviceFactory[] factories = getFactoriesPriority();
71
if (factories == null)
72
throw new JavaLayerException(this + ": no factories registered");
74
JavaLayerException lastEx = null;
75
for (int i = 0; (device == null) && (i < factories.length); i++) {
77
device = factories[i].createAudioDevice();
78
} catch (JavaLayerException ex) {
83
if (device == null && lastEx != null) {
84
throw new JavaLayerException("Cannot create AudioDevice", lastEx);
90
protected AudioDeviceFactory[] getFactoriesPriority() {
91
AudioDeviceFactory[] fa = null;
92
synchronized (factories) {
93
int size = factories.size();
95
fa = new AudioDeviceFactory[size];
97
Enumeration e = factories.elements();
98
while (e.hasMoreElements()) {
99
AudioDeviceFactory factory = (AudioDeviceFactory) e
108
protected void registerDefaultFactories() {
109
addFactory(new JavaSoundAudioDeviceFactory());