KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Run > Deployment > ComponentAccess


1 /* $Id: ComponentAccess.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Run.Deployment;
3
4 import java.net.InetAddress JavaDoc;
5 import java.net.UnknownHostException JavaDoc;
6
7 import org.omg.CosNaming.NameComponent JavaDoc;
8
9 import SOFA.SOFAnode.Run.DeplDockRegistry.DeplDockRegistry;
10 import SOFA.SOFAnode.Run.DeplDockRegistry.DeplDockRegistryHelper;
11
12 /** Allows acess to SOFA components from ordinary applications.
13   *
14   * @author Petr Hnetynka
15   */

16 public class ComponentAccess {
17   
18   private SOFA.Component.ThreadIDRegistry thrReg;
19   private SOFA.Util.CORBAAccess ca;
20   
21   /** Reference to deployment dock registry. */
22   public DeplDockRegistry ddr;
23   
24   /** Constructor.
25     *
26     * @throws ComponentAccessException cannot initialize all necessary objects
27     */

28   public ComponentAccess() throws ComponentAccessException {
29     if (System.getSecurityManager() == null) {
30       System.setSecurityManager(new java.rmi.RMISecurityManager JavaDoc());
31     }
32
33     String JavaDoc sofaNodeName = System.getProperty("sofa.nodename","");
34     if (sofaNodeName.compareTo("")==0) {
35       try {
36         sofaNodeName = InetAddress.getLocalHost().getHostName();
37       } catch (UnknownHostException JavaDoc e) {
38         throw new ComponentAccessException("Can't get host name. Set name to property \"sofa.nodename\"", e);
39       }
40     }
41
42     System.setProperty("sofa.nodename",sofaNodeName);
43     thrReg = new SOFA.Component.ThreadIDRegistryImpl(sofaNodeName);
44
45     ca = new SOFA.Util.CORBAAccess();
46     NameComponent JavaDoc nc = new NameComponent JavaDoc("DeplDockRegistry", "");
47     NameComponent JavaDoc path[] = {nc};
48     try {
49       ddr = DeplDockRegistryHelper.narrow(SOFA.Util.CORBAAccess.ncRef.resolve(path));
50     } catch (Exception JavaDoc e) {
51       throw new ComponentAccessException("Can't get DeplDock registry.", e);
52     }
53   }
54
55   /** Corrects connector part in order to be used in non component application. It assumes that connector
56     * is obtained via component introspection (Component.getFcInterface[s]).
57     *
58     * @param rb connector part
59     * @return corrected connector part
60     */

61   public SOFA.Connector.RoleBase correctRoleBase(SOFA.Connector.RoleBase rb) {
62     rb.setThrIDRegistry(thrReg);
63     return rb;
64   }
65
66   /** Returns deployment dock.
67     *
68     * @param name name of the dock
69     * @return deployment dock
70     * @throws ComponentAccessException
71     */

72   public SOFA.SOFAnode.Run.Deployment.DeplDock getDock(String JavaDoc name) throws ComponentAccessException {
73     byte[] serRef = null;
74     try {
75       serRef = ddr.lookup(name);
76     } catch (SOFA.SOFAnode.Run.DeplDockRegistry.NotFoundException e) {
77       throw new ComponentAccessException("No deployment dock with name \""+name+"\".");
78     }
79
80     SOFA.Connector.Reference ddRef = SOFA.SOFAnode.Run.Deployment.DeplDockImpl.bytesToSofaReference(serRef);
81
82     SOFA.SOFAnode.Run.Deployment.DeplDock ddock = null;
83     try {
84       ddock = (SOFA.SOFAnode.Run.Deployment.DeplDock) SOFA.Connector.Boot.DeplDockConnector.createClt(ddRef);
85     } catch (SOFA.Connector.ConnectorException e) {
86       throw new ComponentAccessException("Can't create connector to deployment dock.");
87     }
88     return ddock;
89   }
90
91
92 }
93
Popular Tags