1 6 7 package javax.emb; 8 9 import java.util.Collections; 10 import java.util.HashMap; 11 import java.util.Iterator; 12 import java.util.Map; 13 14 31 public final class MediaFormatRegistry 32 { 33 public static final MediaFormatRegistry SINGLETON = 34 new MediaFormatRegistry(); 35 36 private final Map mediaFormats = Collections.synchronizedMap(new HashMap()); 37 38 42 private MediaFormatRegistry() 43 { 44 } 45 46 58 public void bind(String fileExtension, MediaFormat mediaFormat) 59 throws FormatAlreadyBoundException 60 { 61 if (fileExtension == null || mediaFormat == null) 62 { 63 throw new NullPointerException(); 64 } 65 66 fileExtension = fileExtension.toLowerCase(); 67 68 if (mediaFormats.containsKey(fileExtension)) 69 { 70 throw new FormatAlreadyBoundException(); 71 } 72 73 mediaFormats.put(fileExtension, mediaFormat); 74 } 75 76 82 public Iterator getFileExtensions() 83 { 84 synchronized (mediaFormats) 85 { 86 return mediaFormats.keySet().iterator(); 87 } 88 } 89 90 100 public MediaFormat lookup(String fileExtension) 101 throws FormatNotFoundException 102 { 103 fileExtension = fileExtension.toLowerCase(); 104 105 if (!mediaFormats.containsKey(fileExtension)) 106 { 107 throw new FormatNotFoundException(); 108 } 109 110 return (MediaFormat) mediaFormats.get(fileExtension); 111 } 112 113 124 public void rebind(String fileExtension, MediaFormat mediaFormat) 125 { 126 if (fileExtension == null || mediaFormat == null) 127 { 128 throw new NullPointerException(); 129 } 130 131 fileExtension = fileExtension.toLowerCase(); 132 133 mediaFormats.put(fileExtension, mediaFormat); 134 } 135 136 145 public void unbind(String fileExtension) throws FormatNotFoundException 146 { 147 if (fileExtension == null) 148 { 149 throw new NullPointerException(); 150 } 151 152 fileExtension = fileExtension.toLowerCase(); 153 154 if (!mediaFormats.containsKey(fileExtension)) 155 { 156 throw new FormatNotFoundException(); 157 } 158 159 mediaFormats.remove(fileExtension); 160 } 161 } | Popular Tags |