KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > TypedEventChannelImpl


1 package org.jacorb.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2003 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * 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 org.apache.avalon.framework.configuration.Configuration;
24 import org.jacorb.notification.container.CORBAObjectComponentAdapter;
25 import org.jacorb.notification.container.PicoContainerFactory;
26 import org.jacorb.notification.servant.AbstractAdmin;
27 import org.jacorb.notification.servant.AbstractSupplierAdmin;
28 import org.jacorb.notification.servant.IEventChannel;
29 import org.jacorb.notification.servant.ITypedEventChannel;
30 import org.jacorb.notification.servant.TypedConsumerAdminImpl;
31 import org.jacorb.notification.servant.TypedSupplierAdminImpl;
32 import org.omg.CORBA.IntHolder JavaDoc;
33 import org.omg.CORBA.ORB JavaDoc;
34 import org.omg.CosNotifyChannelAdmin.AdminNotFound;
35 import org.omg.CosNotifyChannelAdmin.EventChannel;
36 import org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator;
37 import org.omg.CosNotifyFilter.FilterFactory;
38 import org.omg.CosTypedNotifyChannelAdmin.TypedConsumerAdmin;
39 import org.omg.CosTypedNotifyChannelAdmin.TypedConsumerAdminHelper;
40 import org.omg.CosTypedNotifyChannelAdmin.TypedEventChannel;
41 import org.omg.CosTypedNotifyChannelAdmin.TypedEventChannelFactory;
42 import org.omg.CosTypedNotifyChannelAdmin.TypedEventChannelHelper;
43 import org.omg.CosTypedNotifyChannelAdmin.TypedEventChannelOperations;
44 import org.omg.CosTypedNotifyChannelAdmin.TypedEventChannelPOATie;
45 import org.omg.CosTypedNotifyChannelAdmin.TypedSupplierAdmin;
46 import org.omg.CosTypedNotifyChannelAdmin.TypedSupplierAdminHelper;
47 import org.omg.PortableServer.POA JavaDoc;
48 import org.omg.PortableServer.Servant JavaDoc;
49 import org.picocontainer.MutablePicoContainer;
50 import org.picocontainer.defaults.ConstructorInjectionComponentAdapter;
51
52 /**
53  * @author Alphonse Bendt
54  * @version $Id: TypedEventChannelImpl.java,v 1.7 2005/05/04 17:32:29 alphonse.bendt Exp $
55  */

56
57 public class TypedEventChannelImpl extends AbstractEventChannel implements
58         TypedEventChannelOperations, ITypedEventChannel
59 {
60     private final class TypedEventChannelAdapter implements IEventChannel
61     {
62         private final int adminID_;
63         private final MutablePicoContainer childContainer_;
64
65         private TypedEventChannelAdapter(MutablePicoContainer container, int adminID)
66         {
67             super();
68             
69             adminID_ = adminID;
70             childContainer_ = container;
71         }
72
73         public int getAdminID()
74         {
75             return adminID_;
76         }
77
78         public int getChannelID()
79         {
80             return getID();
81         }
82
83         public EventChannel getEventChannel()
84         {
85             return null;
86         }
87
88         public MutablePicoContainer getContainer()
89         {
90             return childContainer_;
91         }
92
93         public void destroy()
94         {
95             container_.removeChildContainer(childContainer_);
96         }
97     }
98
99     private final TypedEventChannel thisRef_;
100
101     private final TypedEventChannelFactory typedEventChannelFactory_;
102
103     private final Servant JavaDoc thisServant_;
104
105     // Implementation of org.omg.CosTypedNotifyChannelAdmin.TypedEventChannelOperations
106

107     public TypedEventChannelImpl(IFactory factory, ORB JavaDoc orb, POA JavaDoc poa, Configuration config,
108             FilterFactory filterFactory, TypedEventChannelFactory factoryRef)
109     {
110         super(factory, orb, poa, config, filterFactory);
111
112         thisServant_ = new TypedEventChannelPOATie(this);
113
114         thisRef_ = TypedEventChannelHelper.narrow(getServant()._this_object(orb_));
115
116         container_.registerComponent(new CORBAObjectComponentAdapter(TypedEventChannel.class,
117                 thisRef_));
118
119         typedEventChannelFactory_ = factoryRef;
120
121         duringConstruction_ = false;
122     }
123
124     public TypedEventChannelFactory MyFactory()
125     {
126         return typedEventChannelFactory_;
127     }
128
129     public TypedConsumerAdmin default_consumer_admin()
130     {
131         return TypedConsumerAdminHelper.narrow(getDefaultConsumerAdminServant().activate());
132     }
133
134     public TypedSupplierAdmin default_supplier_admin()
135     {
136         return TypedSupplierAdminHelper.narrow(getDefaultSupplierAdminServant().activate());
137     }
138
139     public TypedConsumerAdmin new_for_typed_notification_consumers(InterFilterGroupOperator ifg,
140             IntHolder JavaDoc intHolder)
141     {
142         AbstractAdmin _admin = new_for_consumers_servant(ifg, intHolder);
143
144         return TypedConsumerAdminHelper.narrow(_admin.activate());
145     }
146
147     public TypedSupplierAdmin new_for_typed_notification_suppliers(InterFilterGroupOperator ifg,
148             IntHolder JavaDoc intHolder)
149     {
150         AbstractAdmin _admin = new_for_suppliers_servant(ifg, intHolder);
151
152         return TypedSupplierAdminHelper.narrow(_admin.activate());
153     }
154
155     public TypedConsumerAdmin get_consumeradmin(int n) throws AdminNotFound
156     {
157         return TypedConsumerAdminHelper.narrow(get_consumeradmin_internal(n).activate());
158     }
159
160     public TypedSupplierAdmin get_supplieradmin(int n) throws AdminNotFound
161     {
162         return TypedSupplierAdminHelper.narrow(get_supplieradmin_internal(n).activate());
163     }
164
165     public org.omg.CosTypedEventChannelAdmin.TypedConsumerAdmin for_consumers()
166     {
167         return org.omg.CosTypedEventChannelAdmin.TypedConsumerAdminHelper
168                 .narrow(default_consumer_admin());
169     }
170
171     public org.omg.CosTypedEventChannelAdmin.TypedSupplierAdmin for_suppliers()
172     {
173         return org.omg.CosTypedEventChannelAdmin.TypedSupplierAdminHelper
174                 .narrow(default_supplier_admin());
175     }
176
177     protected Servant JavaDoc getServant()
178     {
179         return thisServant_;
180     }
181
182     public org.omg.CORBA.Object JavaDoc activate()
183     {
184         return thisRef_;
185     }
186
187     public AbstractSupplierAdmin newSupplierAdmin(final int id)
188     {
189         final MutablePicoContainer _container = newContainerForAdmin(id);
190
191         _container.registerComponent(new ConstructorInjectionComponentAdapter(
192                 TypedSupplierAdminImpl.class, TypedSupplierAdminImpl.class));
193
194         return (TypedSupplierAdminImpl) _container
195                 .getComponentInstance(TypedSupplierAdminImpl.class);
196     }
197
198     public AbstractAdmin newConsumerAdmin(final int id)
199     {
200         final MutablePicoContainer _container = newContainerForAdmin(id);
201
202         _container.registerComponent(new ConstructorInjectionComponentAdapter(
203                 TypedConsumerAdminImpl.class, TypedConsumerAdminImpl.class));
204         
205         return (TypedConsumerAdminImpl) _container
206                 .getComponentInstance(TypedConsumerAdminImpl.class);
207     }
208     
209     private MutablePicoContainer newContainerForAdmin(final int id)
210     {
211         final MutablePicoContainer _container = PicoContainerFactory
212                 .createChildContainer(container_);
213         
214         _container.registerComponentInstance(new TypedEventChannelAdapter(_container, id));
215        
216         return _container;
217     }
218 }
Popular Tags