01: package org.jacorb.transport;
02:
03: /*
04: * JacORB - a free Java ORB
05: *
06: * Copyright (C) 1997-2004 Gerald Brose.
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Library General Public
10: * License as published by the Free Software Foundation; either
11: * version 2 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Library General Public License for more details.
17: *
18: * You should have received a copy of the GNU Library General Public
19: * License along with this library; if not, write to the Free
20: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: */
22:
23: import java.net.Socket;
24:
25: import org.jacorb.orb.iiop.IIOPAddress;
26: import org.jacorb.orb.iiop.IIOPConnection;
27: import org.jacorb.orb.iiop.IIOPProfile;
28: import org.jacorb.transport.iiop.Current;
29: import org.omg.IOP.TAG_INTERNET_IOP;
30:
31: /**
32: * An instance of this class plugs-in the ORB initialization mechanism to make
33: * sure the infrastructure the IIOP-specific Transport Current needs, is
34: * properly initialized.
35: *
36: * @author Iliyan Jeliazkov
37: */
38:
39: public class IIOPCurrentImpl extends DefaultCurrentImpl implements
40: Current {
41:
42: /**
43: * ctor
44: *
45: * @param c -
46: * Configuration
47: */
48: public IIOPCurrentImpl() {
49: }
50:
51: public int remote_port() throws NoContext {
52:
53: return ((IIOPAddress) ((IIOPProfile) getLatestTransportCurentEvent()
54: .profile()).getAddress()).getPort();
55: }
56:
57: public String remote_host() throws NoContext {
58:
59: return ((IIOPAddress) ((IIOPProfile) getLatestTransportCurentEvent()
60: .profile()).getAddress()).getHostname();
61: }
62:
63: public int local_port() throws NoContext {
64:
65: Socket so = ((IIOPConnection) getLatestTransportCurentEvent()
66: .transport()).getSocket();
67: if (so == null)
68: return 0;
69: return so.getLocalPort();
70: }
71:
72: public String local_host() throws NoContext {
73:
74: Socket so = ((IIOPConnection) getLatestTransportCurentEvent()
75: .transport()).getSocket();
76: if (so == null)
77: return null;
78: return so.getLocalAddress().getCanonicalHostName();
79: }
80:
81: public String toString() {
82:
83: try {
84: return getClass().getName() + "[ " + local_host() + ':'
85: + local_port() + '-' + remote_host() + ':'
86: + remote_port() + ']';
87: } catch (NoContext e) {
88: return getClass().getName() + "[ NoContext ]";
89: }
90: }
91:
92: }
|