KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > HomeLocalReceptaclesImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p></p>
36  **/

37 public class HomeLocalReceptaclesImpl
38 {
39     // receptalces
40
static private String JavaDoc _class_name = "HomeLocalReceptaclesImpl";
41     private java.util.Hashtable JavaDoc _name2cnxs;
42     private CallInterceptorFactory _factory;
43
44     // empty constructor
45
public
46     HomeLocalReceptaclesImpl()
47     {
48         // receptalces
49
_name2cnxs = null;
50         _factory = null;
51     }
52
53     // default constructor
54
public
55     HomeLocalReceptaclesImpl(CallInterceptorFactory ifact)
56     {
57         // receptalces
58
_name2cnxs = new java.util.Hashtable JavaDoc();
59         _factory = ifact;
60     }
61
62     //
63
// public operations (for LocalReceptacleImpl class)
64
//
65

66     final public org.omg.Components.Cookie
67     connect(byte[] cid, String JavaDoc name, org.omg.CORBA.Object JavaDoc obj)
68     {
69         // obtain local connection list
70
String JavaDoc rname = new String JavaDoc(cid)+":"+name;
71         java.util.ArrayList JavaDoc cnxs = (java.util.ArrayList JavaDoc)_name2cnxs.get(rname);
72         if (cnxs==null) {
73             cnxs = new java.util.ArrayList JavaDoc();
74             _name2cnxs.put(rname, cnxs);
75         }
76
77         // create cookie
78
CookieImpl lck = new CookieImpl(name);
79
80         // create stub interceptor if available
81
if (_factory!=null) {
82             org.omg.CORBA.Object JavaDoc inter = _factory.createStubInterceptor(name, obj);
83             // add local connection (replace real stub by stub interceptor)
84
LocalConnectionImpl cnx = new LocalConnectionImpl(lck, inter);
85             cnxs.add(cnx);
86         } else {
87             // add local connection
88
LocalConnectionImpl cnx = new LocalConnectionImpl(lck, obj);
89             cnxs.add(cnx);
90         }
91
92         //
93
return lck;
94     }
95
96     final public org.omg.CORBA.Object JavaDoc
97     disconnect(byte[] cid, org.omg.Components.Cookie ck)
98     throws org.omg.Components.InvalidSubscription
99     {
100         // NOTE: ck must be a CookieImpl
101
if (!(ck instanceof CookieImpl)) {
102             // NOTE: is this the right exception ? there's no other one ...
103
throw new org.omg.Components.InvalidSubscription();
104         }
105
106         // get name from cookie
107
CookieImpl lck = (CookieImpl)ck;
108         String JavaDoc name = lck.getName();
109         String JavaDoc rname = new String JavaDoc(cid)+":"+name;
110
111         // get list of connection
112
java.util.ArrayList JavaDoc cnxs = (java.util.ArrayList JavaDoc)_name2cnxs.get(rname);
113
114         if (cnxs==null) {
115             throw new org.omg.Components.InvalidSubscription();
116         }
117
118         // remove
119
org.omg.CORBA.Object JavaDoc res = null;
120         org.omg.Components.LocalConnection lcnx = null;
121         for (int i=0;i<cnxs.size();i++) {
122             lcnx = (org.omg.Components.LocalConnection)cnxs.get(i);
123             if (lcnx.ck().equals(ck)) {
124                 res = (org.omg.CORBA.Object JavaDoc)cnxs.remove(i);
125                 break;
126             }
127         }
128
129         // check if removal occured
130
if (res==null) {
131             throw new org.omg.Components.InvalidSubscription();
132         }
133         
134         return res;
135     }
136
137     final public org.omg.Components.LocalConnection[]
138     get_connections(byte[] cid, String JavaDoc name)
139     throws org.omg.Components.InvalidName
140     {
141         // get list of connection
142
String JavaDoc rname = new String JavaDoc(cid)+":"+name;
143         java.util.ArrayList JavaDoc cnxs = (java.util.ArrayList JavaDoc)_name2cnxs.get(rname);
144
145         if (cnxs==null) {
146             throw new org.omg.Components.InvalidName();
147         }
148
149         return (org.omg.Components.LocalConnection[])cnxs.toArray(new org.omg.Components.LocalConnection[0]);
150     }
151 }
152
Popular Tags