KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > common > lib > BindingFeature


1 /*====================================================================
2
3 GoTM: GoTM is an open Transaction Monitor
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: gotm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Romain Rouvoy.
23 Contributor(s): .
24
25 ---------------------------------------------------------------------
26 $Id: BindingFeature.java,v 1.1 2004/11/08 16:13:50 moroy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.explorer.core.common.lib;
30
31 import java.util.HashMap JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import org.objectweb.fractal.api.NoSuchInterfaceException;
35 import org.objectweb.fractal.api.control.BindingController;
36 import org.objectweb.fractal.api.control.IllegalBindingException;
37 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
38
39
40 /**
41  * Abstract implementation of a feature using client interfaces.
42  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
43  * @version 0.1
44  */

45 public abstract class BindingFeature
46               extends BasicLoggable
47            implements BindingController
48 {
49     /** the list of bindings. */
50     private Map JavaDoc fcBindings ;
51     
52     /**
53      * @return Returns the fcBindings.
54      */

55     private Map JavaDoc getFcBindings() {
56         return fcBindings;
57     }
58     
59     /**
60      * @param fcBindings The fcBindings to set.
61      */

62     private void setFcBindings(Map JavaDoc fcBindings) {
63         this.fcBindings = fcBindings;
64     }
65     
66     public BindingFeature() {
67         setFcBindings(new HashMap JavaDoc());
68     }
69     
70     /**
71      * Checks if the interface name is allowed to be binded.
72      * @param name the interface to check.
73      * @return the name of the allowed interface.
74      * @throws NoSuchInterfaceException if the interface is unknown.
75      */

76     private String JavaDoc checkBinding(String JavaDoc name)
77         throws NoSuchInterfaceException
78     {
79         String JavaDoc[] list = clientFc();
80         for (int i=0 ; i < list.length ; i++)
81             if (name.startsWith(list[i]))
82                 return name ;
83         throw new NoSuchInterfaceException(name);
84     }
85     
86     protected Object JavaDoc lookupFc(int index) {
87         try {
88             return lookupFc(listFc()[index]);
89         } catch (NoSuchInterfaceException e) {
90             return null;
91         } catch (ArrayIndexOutOfBoundsException JavaDoc e2) {
92             return null;
93         }
94     }
95     
96     public abstract String JavaDoc[] clientFc();
97     
98     /* (non-Javadoc)
99      * @see org.objectweb.fractal.api.control.BindingController#listFc()
100      */

101     public String JavaDoc[] listFc() {
102         return (String JavaDoc[]) getFcBindings().keySet().toArray(new String JavaDoc[0]);
103     }
104
105     /* (non-Javadoc)
106      * @see org.objectweb.fractal.api.control.BindingController#lookupFc(java.lang.String)
107      */

108     public Object JavaDoc lookupFc(String JavaDoc arg0)
109         throws NoSuchInterfaceException
110     {
111         return getFcBindings().get(checkBinding(arg0));
112     }
113     
114     /* (non-Javadoc)
115      * @see org.objectweb.fractal.api.control.BindingController#bindFc(java.lang.String, java.lang.Object)
116      */

117     public void bindFc(String JavaDoc arg0, Object JavaDoc arg1)
118         throws NoSuchInterfaceException,
119                IllegalBindingException,
120                IllegalLifeCycleException
121     {
122         getFcBindings().put(checkBinding(arg0),arg1);
123     }
124     
125     /* (non-Javadoc)
126      * @see org.objectweb.fractal.api.control.BindingController#unbindFc(java.lang.String)
127      */

128     public void unbindFc(String JavaDoc arg0)
129         throws NoSuchInterfaceException,
130                IllegalBindingException,
131                IllegalLifeCycleException
132     {
133         getFcBindings().remove(checkBinding(arg0));
134     }
135 }
Popular Tags