KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > orb > IIOPAddressServerImpl


1 package org.jacorb.test.orb;
2
3 import org.omg.PortableServer.*;
4
5 import org.jacorb.orb.IIOPAddress;
6 import org.jacorb.config.Configuration;
7
8 import org.jacorb.test.*;
9
10 import org.apache.avalon.framework.configuration.Configurable;
11
12 /**
13  * @author Andre Spiegel
14  * @version $Id: IIOPAddressServerImpl.java,v 1.3 2004/07/30 15:31:30 simon.mcqueen Exp $
15  */

16 public class IIOPAddressServerImpl extends IIOPAddressServerPOA
17     implements Configurable
18 {
19     private Configuration config = null;
20
21     public void configure (org.apache.avalon.framework.configuration.Configuration c)
22     {
23         config = (org.jacorb.config.Configuration)c;
24     }
25
26     public void setSocketAddress(String JavaDoc host, int port)
27     {
28         config.setAttribute ("OAIAddr",host);
29         if (port != -1)
30             config.setAttribute ("OAPort", Integer.toString(port));
31         try
32         {
33             config.getORB().configure(config);
34         }
35         catch( org.apache.avalon.framework.configuration.ConfigurationException ce )
36         {
37             throw new org.omg.CORBA.INTERNAL JavaDoc("ConfigurationException: " + ce.getMessage());
38         }
39     }
40
41     public void clearSocketAddress()
42     {
43         config.setAttribute ("OAIAddr", null);
44         config.setAttribute ("OAPort", null);
45         try
46         {
47             config.getORB().configure(config);
48         }
49         catch( org.apache.avalon.framework.configuration.ConfigurationException ce )
50         {
51             throw new org.omg.CORBA.INTERNAL JavaDoc("ConfigurationException: " + ce.getMessage());
52         }
53     }
54
55     public void setIORAddress(String JavaDoc host, int port)
56     {
57         config.setAttribute ("jacorb.ior_proxy_host", host);
58         if (port != -1)
59             config.setAttribute ("jacorb.ior_proxy_port",Integer.toString(port));
60         try
61         {
62             config.getORB().configure(config);
63         }
64         catch( org.apache.avalon.framework.configuration.ConfigurationException ce )
65         {
66             throw new org.omg.CORBA.INTERNAL JavaDoc("ConfigurationException: " + ce.getMessage());
67         }
68     }
69
70     public void clearIORAddress()
71     {
72         config.setAttribute ("jacorb.ior_proxy_host", null);
73         config.setAttribute ("jacorb.ior_proxy_port", null);
74         try
75         {
76             config.getORB().configure(config);
77         }
78         catch( org.apache.avalon.framework.configuration.ConfigurationException ce )
79         {
80             throw new org.omg.CORBA.INTERNAL JavaDoc("ConfigurationException: " + ce.getMessage());
81         }
82     }
83
84     public void addAlternateAddress(String JavaDoc host, int port)
85     {
86         IIOPAddressInterceptor.alternateAddresses.add (new IIOPAddress (host, port));
87     }
88
89     public void clearAlternateAddresses()
90     {
91         IIOPAddressInterceptor.alternateAddresses.clear();
92     }
93
94     /**
95      * Returns a sample object, using a new POA so that the address settings
96      * we made are incorporated into the IOR.
97      */

98     public Sample getObject()
99     {
100         try
101         {
102             SampleImpl result = new SampleImpl();
103             POA poa = _default_POA().create_POA("poa-" + System.currentTimeMillis(),
104                                                 null, null);
105             poa.the_POAManager().activate();
106             poa.activate_object(result);
107             org.omg.CORBA.Object JavaDoc obj = poa.servant_to_reference (result);
108             return SampleHelper.narrow (obj);
109         }
110         catch (Exception JavaDoc ex)
111         {
112             throw new RuntimeException JavaDoc ("Exception creating result object: "
113                                         + ex);
114         }
115     }
116 }
117
Popular Tags