1 7 8 package org.jboss.media.registry; 9 10 import java.util.Iterator ; 11 import java.util.Map ; 12 13 import javax.emb.FormatAlreadyBoundException; 14 import javax.emb.FormatNotFoundException; 15 import javax.emb.MediaFormat; 16 import javax.management.MBeanServer ; 17 import javax.management.MalformedObjectNameException ; 18 import javax.management.ObjectName ; 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 35 public class JBossMediaFormatRegistry 36 { 37 private SimpleMediaFormatRegistry mediaFormatRegistry; 39 40 private static final String OBJECT_NAME = 44 "jboss.emb:service=ManagedMediaFormatRegistry"; 45 private static boolean INITIALIZED = false; 46 private static MBeanServer SERVER; 47 48 51 public JBossMediaFormatRegistry() throws FormatAlreadyBoundException 52 { 53 Map mediaFormats = createMediaFormats(); 54 mediaFormatRegistry = new SimpleMediaFormatRegistry(mediaFormats); 55 } 56 57 public void bind(String fileExtension, MediaFormat mediaFormat) 58 throws FormatAlreadyBoundException 59 { 60 mediaFormatRegistry.bind(fileExtension, mediaFormat); 61 } 62 63 public void rebind(String fileExtension, MediaFormat mediaFormat) 64 { 65 mediaFormatRegistry.rebind(fileExtension, mediaFormat); 66 } 67 68 public void unbind(String fileExtension) throws FormatNotFoundException 69 { 70 mediaFormatRegistry.unbind(fileExtension); 71 } 72 73 public MediaFormat lookup(String fileExtension) 74 throws FormatNotFoundException 75 { 76 return mediaFormatRegistry.lookup(fileExtension); 77 } 78 79 public Iterator getFileExtensions() 80 { 81 return mediaFormatRegistry.fileExtensions(); 82 } 83 84 private static ManagedMediaFormatRegistryMBean getInstance() 86 { 87 try 88 { 89 ObjectName objectName = new ObjectName (OBJECT_NAME); 90 return (ManagedMediaFormatRegistryMBean) MBeanProxy.get( 91 ManagedMediaFormatRegistryMBean.class, 92 objectName, 93 SERVER); 94 } 95 catch (MalformedObjectNameException e) 96 { 97 return null; 98 } 99 catch (MBeanProxyCreationException e) 100 { 101 return null; 102 } 103 } 104 105 public static Map createMediaFormats() 106 { 107 Map mediaFormats = IIOMediaFormatFactory.createMediaFormats(); 109 110 mediaFormats.put("mp3", new MpegAudioFormat()); 112 113 return mediaFormats; 114 } 115 } 116 | Popular Tags |