KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > registry > JBossMediaFormatRegistry


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.registry;
9
10 import java.util.Iterator JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import javax.emb.FormatAlreadyBoundException;
14 import javax.emb.FormatNotFoundException;
15 import javax.emb.MediaFormat;
16 import javax.management.MBeanServer JavaDoc;
17 import javax.management.MalformedObjectNameException JavaDoc;
18 import javax.management.ObjectName JavaDoc;
19
20 import org.jboss.media.format.audio.mpeg.MpegAudioFormat;
21 import org.jboss.media.format.image.iio.IIOMediaFormatFactory;
22 import org.jboss.mx.util.MBeanProxy;
23 import org.jboss.mx.util.MBeanProxyCreationException;
24
25 /**
26  * A facade around SimpleMediaFormatRegistry or ManagedMediaFormatRegistry.
27  *
28  * SimpleMediaFormatRegistry is simpler to test.
29  * ManagedMediaFormatRegistry should be used in deployment.
30  *
31  * @version <tt>$Revision: 1.3 $</tt>
32  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo Argüello</a>
33  * @author <a HREF="mailto:spyridon_samothrakis@yahoo.com">Spyridon Samothrakis</a>
34  */

35 public class JBossMediaFormatRegistry
36 {
37    // Simple MediaFormats registry:
38
private SimpleMediaFormatRegistry mediaFormatRegistry;
39
40    // Managed MediaFormats registry (uncomment to use this version):
41
//public static final ManagedMediaFormatRegistryMBean mediaFormatRegistry = getInstance();
42
// All these are needed by the managed registry:
43
private static final String JavaDoc OBJECT_NAME =
44       "jboss.emb:service=ManagedMediaFormatRegistry";
45    private static boolean INITIALIZED = false;
46    private static MBeanServer JavaDoc SERVER;
47
48    /**
49     * Default constructor.
50     */

51    public JBossMediaFormatRegistry() throws FormatAlreadyBoundException
52    {
53       Map JavaDoc mediaFormats = createMediaFormats();
54       mediaFormatRegistry = new SimpleMediaFormatRegistry(mediaFormats);
55    }
56
57    public void bind(String JavaDoc fileExtension, MediaFormat mediaFormat)
58       throws FormatAlreadyBoundException
59    {
60       mediaFormatRegistry.bind(fileExtension, mediaFormat);
61    }
62
63    public void rebind(String JavaDoc fileExtension, MediaFormat mediaFormat)
64    {
65       mediaFormatRegistry.rebind(fileExtension, mediaFormat);
66    }
67
68    public void unbind(String JavaDoc fileExtension) throws FormatNotFoundException
69    {
70       mediaFormatRegistry.unbind(fileExtension);
71    }
72
73    public MediaFormat lookup(String JavaDoc fileExtension)
74       throws FormatNotFoundException
75    {
76       return mediaFormatRegistry.lookup(fileExtension);
77    }
78
79    public Iterator JavaDoc getFileExtensions()
80    {
81       return mediaFormatRegistry.fileExtensions();
82    }
83
84    //-------------------------------------------------------------
85
private static ManagedMediaFormatRegistryMBean getInstance()
86    {
87       try
88       {
89          ObjectName JavaDoc objectName = new ObjectName JavaDoc(OBJECT_NAME);
90          return (ManagedMediaFormatRegistryMBean) MBeanProxy.get(
91             ManagedMediaFormatRegistryMBean.class,
92             objectName,
93             SERVER);
94       }
95       catch (MalformedObjectNameException JavaDoc e)
96       {
97          return null;
98       }
99       catch (MBeanProxyCreationException e)
100       {
101          return null;
102       }
103    }
104
105    public static Map JavaDoc createMediaFormats()
106    {
107       // Image I/O support:
108
Map JavaDoc mediaFormats = IIOMediaFormatFactory.createMediaFormats();
109
110       // MPEG support:
111
mediaFormats.put("mp3", new MpegAudioFormat());
112
113       return mediaFormats;
114    }
115 }
116
Popular Tags