KickJava   Java API By Example, From Geeks To Geeks.

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


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
17 import org.jboss.media.util.registry.MapRegistry;
18 import org.jboss.media.util.registry.ObjectAlreadyBoundException;
19 import org.jboss.media.util.registry.ObjectNotBoundException;
20 import org.jboss.media.util.registry.Registry;
21
22 /**
23  * A simple implementation of a MediaFormat registry.
24  *
25  * @version <tt>$Revision: 1.2 $</tt>
26  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo Argüello</a>
27  */

28 public class SimpleMediaFormatRegistry
29 {
30    private final Registry registry;
31
32    public SimpleMediaFormatRegistry()
33    {
34       registry = new MapRegistry();
35    }
36
37    public SimpleMediaFormatRegistry(Map JavaDoc initialEntries)
38       throws FormatAlreadyBoundException
39    {
40       try
41       {
42          registry = new MapRegistry(initialEntries);
43       }
44       catch (ObjectAlreadyBoundException e)
45       {
46          throw new FormatAlreadyBoundException();
47       }
48    }
49
50    public void bind(String JavaDoc fileExtension, MediaFormat mediaFormat)
51       throws FormatAlreadyBoundException
52    {
53       try
54       {
55          registry.bind(fileExtension, mediaFormat);
56       }
57       catch (ObjectAlreadyBoundException e)
58       {
59          throw new FormatAlreadyBoundException();
60       }
61    }
62
63    public void rebind(String JavaDoc fileExtension, MediaFormat mediaFormat)
64    {
65       registry.rebind(fileExtension, mediaFormat);
66    }
67
68    public void unbind(String JavaDoc fileExtension) throws FormatNotFoundException
69    {
70       try
71       {
72          registry.unbind(fileExtension);
73       }
74       catch (ObjectNotBoundException e)
75       {
76          throw new FormatNotFoundException();
77       }
78    }
79
80    public MediaFormat lookup(String JavaDoc fileExtension)
81       throws FormatNotFoundException
82    {
83       try
84       {
85          return (MediaFormat) registry.lookup(fileExtension);
86       }
87       catch (ObjectNotBoundException e)
88       {
89          throw new FormatNotFoundException();
90       }
91    }
92
93    public Iterator JavaDoc fileExtensions()
94    {
95       return registry.keyIterator();
96    }
97 }
98
Popular Tags