KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > IFR


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@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): Philippe Merle.
23 Contributor(s): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 /**
30  * This IFR class implements some common features for IFR objects:
31  * global object storing and error managements.
32  *
33  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
34  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
35  *
36  * @version 0.4
37  */

38
39 public class IFR
40 {
41     // ==================================================================
42
//
43
// Internal states.
44
//
45
// ==================================================================
46

47     /** Conversion table between TIE Servant <---> IFRObject. */
48     protected java.util.Map JavaDoc tie2impl_;
49
50     /** Reference to the RootPOA singleton. */
51     protected org.omg.PortableServer.POA JavaDoc rootPOA_;
52
53     /** Reference to the CORBA::ComponentIR::Repository singleton. */
54     protected ComponentRepository_impl repository_;
55
56     // ==================================================================
57
//
58
// Constructors.
59
//
60
// ==================================================================
61

62     /**
63      * The default constructor.
64      */

65     public
66     IFR()
67     {
68         this(true);
69     }
70              
71     /**
72      * Constructor with mapping parameter.
73      *
74      * @param with_mapping - If true, creates the singleton Repository object
75      * with mappings enabled.
76      */

77     public
78     IFR(boolean with_mapping)
79     {
80         // create conversion table.
81
tie2impl_ = new java.util.HashMap JavaDoc();
82
83         rootPOA_ = org.objectweb.openccm.corba.TheRootPOA.getRootPOA();
84
85         // create the singleton Repository object
86
// with mappings enabled.
87
repository_ = new ComponentRepository_impl(this, with_mapping);
88     }
89
90     // ==================================================================
91
//
92
// Public methods.
93
//
94
// ==================================================================
95

96     /**
97      * Obtain the Repository object.
98      */

99     public ComponentRepository_impl
100     getRepository()
101     {
102         return repository_;
103     }
104
105     /**
106      * Obtain the TypeCodeFactory object.
107      */

108     public org.omg.CORBA.ORB JavaDoc
109     getTCF()
110     {
111         return org.objectweb.openccm.corba.TheORB.getORB();
112     }
113
114     /**
115      * Activate TIE servant.
116      */

117     public void
118     activate(org.omg.PortableServer.Servant JavaDoc servant,
119              IFRObject impl)
120     {
121         log(100,"activate " + servant.toString() + " for " + impl.toString());
122         activateServant(servant);
123         tie2impl_.put(servant, impl);
124     }
125
126     /**
127      * Deactivate TIE servant.
128      */

129     public void
130     deactivate(org.omg.PortableServer.Servant JavaDoc servant)
131     {
132         log(100,"deactivate " + servant.toString());
133         deactivateServant(servant);
134         tie2impl_.remove(servant);
135     }
136
137     /**
138      * Obtain the IFRObject implementing the object reference.
139      */

140     public IFRObject
141     toImpl(org.omg.CORBA.Object JavaDoc object)
142     {
143        org.omg.PortableServer.Servant JavaDoc servant = toServant(object);
144        if (servant == null)
145            return null;
146
147        IFRObject impl = (IFRObject)tie2impl_.get(servant);
148        return impl;
149     }
150
151     /**
152      * Activate a Servant.
153      */

154     public void
155     activateServant(org.omg.PortableServer.Servant JavaDoc servant)
156     {
157        try
158        {
159            byte[] oid = rootPOA_.activate_object(servant);
160        }
161        catch(Exception JavaDoc ex)
162        {
163            ex.printStackTrace();
164        }
165     }
166
167     /**
168      * Deactivate a Servant.
169      */

170     public void
171     deactivateServant(org.omg.PortableServer.Servant JavaDoc servant)
172     {
173        try
174        {
175            byte[] oid = rootPOA_.servant_to_id(servant);
176            rootPOA_.deactivate_object(oid);
177        }
178        catch(Exception JavaDoc ex)
179        {
180            ex.printStackTrace();
181        }
182     }
183
184     /**
185      * Obtain the Servant implementing the object reference.
186      */

187     public org.omg.PortableServer.Servant JavaDoc
188     toServant(org.omg.CORBA.Object JavaDoc object)
189     {
190        if(object != null)
191        {
192            try
193            {
194                return rootPOA_.reference_to_servant(object);
195            }
196            catch(Exception JavaDoc ex)
197            {
198                ex.printStackTrace();
199            }
200        }
201        return null;
202     }
203
204     /**
205      * Log a message.
206      */

207     public void
208     log(int level, String JavaDoc message)
209     {
210         if(level < 10)
211            System.err.println("(Level=" + level + "): " + message);
212     }
213 }
214
Popular Tags