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.MediaFormat; 15 16 24 public class ReflectionMediaFormatRegistry extends SimpleMediaFormatRegistry 25 { 26 public ReflectionMediaFormatRegistry() 27 { 28 super(); 29 } 30 31 public ReflectionMediaFormatRegistry(Map initialEntries) 32 { 33 this(); 34 35 Iterator it = initialEntries.keySet().iterator(); 36 37 while (it.hasNext()) 38 { 39 String fileExtension = (String ) it.next(); 40 41 String mediaFormatClassName = 42 (String ) initialEntries.get(fileExtension); 43 44 try 45 { 46 this.bind(fileExtension, mediaFormatClassName); 47 } 48 catch (FormatAlreadyBoundException ignore) 49 { 50 } 51 } 52 53 } 54 55 public void bind(String fileExtension, String mediaFormatClassName) 56 throws FormatAlreadyBoundException 57 { 58 try 59 { 60 Class mediaFormatClass = Class.forName(mediaFormatClassName); 61 62 MediaFormat mediaFormat = (MediaFormat) mediaFormatClass.newInstance(); 65 66 super.bind(fileExtension, mediaFormat); 67 } 68 catch (ClassNotFoundException e) 69 { 70 throw new IllegalArgumentException (e.getMessage()); 71 } 72 catch (InstantiationException e) 73 { 74 throw new IllegalArgumentException (e.getMessage()); 75 } 76 catch (IllegalAccessException e) 77 { 78 throw new IllegalArgumentException (e.getMessage()); 79 } 80 } 81 82 public void rebind(String fileExtension, String mediaFormatClassName) 83 { 84 try 85 { 86 Class mediaFormatClass = Class.forName(mediaFormatClassName); 87 MediaFormat mediaFormat = (MediaFormat) mediaFormatClass.newInstance(); 88 super.rebind(fileExtension, mediaFormat); 89 } 90 catch (ClassNotFoundException e) 91 { 92 throw new IllegalArgumentException (e.getMessage()); 93 } 94 catch (InstantiationException e) 95 { 96 throw new IllegalArgumentException (e.getMessage()); 97 } 98 catch (IllegalAccessException e) 99 { 100 throw new IllegalArgumentException (e.getMessage()); 101 } 102 } 103 } 104 | Popular Tags |