KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ServiceDuplicatorImpl


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: dream@objectweb.org
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s):
23  */

24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.objectweb.fractal.api.NoSuchInterfaceException;
29 import org.objectweb.fractal.api.control.BindingController;
30 import org.objectweb.fractal.api.control.IllegalBindingException;
31 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
32
33 /**
34  * Duplicate calls on service.
35  */

36 public class ServiceDuplicatorImpl implements Service, BindingController
37 {
38
39   Map JavaDoc services = new HashMap JavaDoc();
40
41   public void print(String JavaDoc msg)
42   {
43     Iterator JavaDoc iter = services.values().iterator();
44     while (iter.hasNext())
45     {
46       Service serviceItf = (Service) iter.next();
47       serviceItf.print(msg);
48     }
49   }
50
51   public String JavaDoc[] listFc()
52   {
53     return (String JavaDoc[]) services.keySet().toArray(new String JavaDoc[services.size()]);
54   }
55
56   public Object JavaDoc lookupFc(String JavaDoc clientItfName) throws NoSuchInterfaceException
57   {
58     return services.get(clientItfName);
59   }
60
61   public void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
62       throws NoSuchInterfaceException, IllegalBindingException,
63       IllegalLifeCycleException
64   {
65     if (clientItfName.startsWith("clientService"))
66     {
67       services.put(clientItfName, serverItf);
68     }
69   }
70
71   public void unbindFc(String JavaDoc clientItfName) throws NoSuchInterfaceException,
72       IllegalBindingException, IllegalLifeCycleException
73   {
74     if (clientItfName.startsWith("clientService"))
75     {
76       services.remove(clientItfName);
77     }
78   }
79 }
Popular Tags