KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > imr > ImRAccessImpl


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.imr;
22
23 import org.jacorb.imr.RegistrationPackage.DuplicatePOAName;
24 import org.jacorb.imr.RegistrationPackage.IllegalPOAName;
25 import org.omg.CORBA.INTERNAL JavaDoc;
26
27
28 /**
29  * ImRAccessImpl.java
30  *
31  *
32  * Created: Thu Jan 31 21:05:55 2002
33  *
34  * @author Nicolas Noffke
35  * @version $Id: ImRAccessImpl.java,v 1.8 2004/05/06 12:39:59 nicolas Exp $
36  */

37
38 public class ImRAccessImpl
39     implements org.jacorb.orb.ImRAccess
40 {
41     private Registration reg = null;
42     private ImRInfo info = null;
43
44     /**
45      * <code>ImRAccessImpl</code> private; use the static connect method.
46      */

47     private ImRAccessImpl () {}
48
49
50    /**
51     * <code>connect</code> resolves the IMR and returns a new ImRAccessImpl.
52     *
53     * @param orb an <code>org.omg.CORBA.ORB</code> value
54     * @return an <code>ImRAccessImpl</code> value
55     */

56     public static ImRAccessImpl connect (org.omg.CORBA.ORB JavaDoc orb)
57     {
58         ImRAccessImpl result = new ImRAccessImpl ();
59         try
60         {
61             result.reg = RegistrationHelper.narrow( orb.resolve_initial_references("ImplementationRepository"));
62         }
63         catch( org.omg.CORBA.ORBPackage.InvalidName JavaDoc in )
64         {
65         }
66
67         boolean non_exist = true;
68         if (result.reg != null)
69         {
70             try
71             {
72                 non_exist = result.reg._non_existent();
73             }
74             catch (org.omg.CORBA.SystemException JavaDoc e)
75             {
76                 non_exist = true;
77             }
78         }
79
80         if (non_exist)
81         {
82             throw new INTERNAL JavaDoc ("Unable to resolve reference to ImR");
83         }
84         return result;
85     }
86
87     public String JavaDoc getImRHost()
88     {
89         if( info == null )
90         {
91             info = reg.get_imr_info();
92         }
93
94         return info.host;
95     }
96
97     public int getImRPort()
98     {
99         if( info == null )
100         {
101             info = reg.get_imr_info();
102         }
103
104         return info.port;
105     }
106
107     public void registerPOA( String JavaDoc name,
108                              String JavaDoc server,
109                              String JavaDoc host,
110                              int port)
111         throws INTERNAL JavaDoc
112     {
113         try
114         {
115             reg.register_poa(name, server, host, port );
116         }
117         catch( DuplicatePOAName e )
118         {
119             throw new INTERNAL JavaDoc( "A server with the same combination of ImplName/POA-Name (" +
120                                 name +
121                                 ") is already registered and listed as active at the imr!" );
122         }
123         catch( IllegalPOAName e )
124         {
125             throw new INTERNAL JavaDoc( "The ImR replied that the POA name >>" +
126                                 e.name + "<< is illegal!" );
127         }
128         catch( UnknownServerName e )
129         {
130             throw new INTERNAL JavaDoc( "The ImR replied that the server name >>" +
131                                 e.name + "<< is unknown!" );
132         }
133     }
134
135     public void setServerDown( String JavaDoc name )
136         throws INTERNAL JavaDoc
137     {
138         try
139         {
140             reg.set_server_down( name );
141         }
142         catch(UnknownServerName e)
143         {
144             throw new INTERNAL JavaDoc( "The ImR replied that a server with name " +
145                                 name + " is unknown" );
146         }
147     }
148 }// ImRAccessImpl
149
Popular Tags