KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > engine > MediaPluginGraph


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.engine;
9
10 import java.util.Arrays JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Map JavaDoc;
14 import java.util.Vector JavaDoc;
15
16
17 /**
18  * The plugin media graph. To be linked with the correct media
19  * @version <tt>$Revision: 1.2 $</tt>
20  * @author <a HREF="mailto:spyridon_samothrakis@yahoo.com">Spyridon Samothrakis</a>
21  */

22 public class MediaPluginGraph
23 {
24    Map JavaDoc graph = new HashMap JavaDoc();
25    
26     /**
27      * Method addPlugin.
28      * @param plugin The plugin object
29      * @param pos The position in the graph
30      * @throws MediaPluginGraphException
31      */

32    public void addPlugin ( MediaPlugin plugin , int pos)
33       throws MediaPluginGraphException
34    {
35       Integer JavaDoc position = new Integer JavaDoc ( pos ) ;
36       if(graph.containsKey(position))
37          throw new MediaPluginGraphException("A plugin already exists in position" + position);
38          
39       graph.put(position, plugin);
40    }
41    
42    
43    
44     /**
45      * Method getPluginVector.
46      * @return Vector of a series of plugins
47      */

48    public Vector JavaDoc getPluginVector()
49    {
50       Vector JavaDoc plugins = new Vector JavaDoc();
51       
52       int[] keys = new int[graph.keySet().size()];
53       
54       //get the keys
55
Iterator JavaDoc it = graph.keySet().iterator();
56       for( int i = 0 ; i < graph.keySet().size(); i++ )
57       {
58          keys[i] = ((Integer JavaDoc)it.next()).intValue();
59       }
60       
61       // sort them
62
Arrays.sort(keys);
63      
64       // add them to the vector
65
for ( int i = 0 ; i < keys.length ; i++ )
66       {
67          Object JavaDoc mediaPlugin = graph.get(new Integer JavaDoc(i));
68          plugins.add(mediaPlugin);
69       }
70       
71       return plugins;
72    }
73 }
74
Popular Tags