KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 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
24 import org.jacorb.notification.container.CORBAObjectComponentAdapter;
25 import org.omg.CORBA.IntHolder JavaDoc;
26 import org.omg.CORBA.ORB JavaDoc;
27 import org.omg.CORBA.UserException JavaDoc;
28 import org.omg.CosNotification.Property;
29 import org.omg.CosNotification.UnsupportedAdmin;
30 import org.omg.CosNotification.UnsupportedQoS;
31 import org.omg.CosNotifyChannelAdmin.ChannelNotFound;
32 import org.omg.CosNotifyChannelAdmin.EventChannel;
33 import org.omg.CosNotifyChannelAdmin.EventChannelFactory;
34 import org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper;
35 import org.omg.CosNotifyChannelAdmin.EventChannelHelper;
36 import org.omg.PortableServer.Servant JavaDoc;
37 import org.picocontainer.ComponentAdapter;
38 import org.picocontainer.MutablePicoContainer;
39 import org.picocontainer.PicoContainer;
40 import org.picocontainer.defaults.CachingComponentAdapter;
41
42 /**
43  * <code>EventChannelFactoryImpl</code> is a implementation of the
44  * <code>EventChannelFactory</code> interface which defines operations for creating and managing
45  * new Notification Service style event channels. It supports a routine that creates new instances
46  * of Notification Service event channels and assigns unique numeric identifiers to them. In
47  * addition the <code>EventChannelFactory</code> interface supports a routing, which can return
48  * the unique identifiers assigned to all event channels created by a given instance of
49  * <code>EventChannelFactory</code>, and another routine which, given the unique identifier of an
50  * event channel created by a target <code>EventChannelFactory</code> instance, returns the object
51  * reference of that event channel. <br>
52  *
53  * @author Alphonse Bendt
54  * @version $Id: EventChannelFactoryImpl.java,v 1.43 2005/05/04 13:58:47 alphonse.bendt Exp $
55  */

56
57 public class EventChannelFactoryImpl extends AbstractChannelFactory implements
58         JacORBEventChannelFactoryOperations
59 {
60     // //////////////////////////////////////
61

62     protected String JavaDoc getShortcut()
63     {
64         return "NotificationService";
65     }
66
67     protected String JavaDoc getObjectName()
68     {
69         return "_ECFactory";
70     }
71
72     // //////////////////////////////////////
73

74     public EventChannelFactoryImpl(PicoContainer container, ORB JavaDoc orb) throws UserException JavaDoc
75     {
76         super(container, orb);
77
78         container_.registerComponent(new CORBAObjectComponentAdapter(EventChannelFactory.class,
79                 EventChannelFactoryHelper.narrow(thisRef_)));
80     }
81
82     /**
83      * The <code>create_channel</code> operation is invoked to create a new instance of the
84      * Notification Service style event channel. This operation accepts two input parameters. The
85      * first input parameter is a list of name-value pairs, which specify the initial QoS property
86      * settings for the new channel. The second input parameter is a list of name-value pairs, which
87      * specify the initial administrative property settings for the new channel. <br>
88      * If no implementation of the <code>EventChannel</code> Interface exists that can support all
89      * of the requested administrative property settings, the <code>UnsupportedAdmin</code>
90      * exception is raised This exception contains as data a sequence of data structures, each
91      * identifies the name of an administrative property in the input list whose requested setting
92      * could not be satisfied, along with an error code and a range of settings for the property
93      * which could be satisfied. The meanings of the error codes that might be returned are
94      * described in <a HREF="%%%NOTIFICATION_SPEC_URL%%%">Notification Service Specification </a>
95      * Table 2-5 on page 2-46. <br>
96      * If neither of these exceptions is raised, the <code>create_channel</code> operation will
97      * return a reference to a new Notification Service style event channel. In addition, the
98      * operation assigns to this new event channel a numeric identifier, which is unique among all
99      * event channels created by the target object. This numeric identifier is returned as an output
100      * parameter.
101      *
102      * @param qualitiyOfServiceProperties
103      * a list of name-value pairs, which specify the initial QoS property settings for
104      * the new channel
105      * @param administrativeProperties
106      * a list of name-value pairs, which specify the initial administrative property
107      * settings for the new channel
108      * @param channelIdentifier
109      * a reference to the new event channel
110      * @return a newly created event channel
111      * @exception UnsupportedAdmin
112      * if no implementation supports the requested administrative settings
113      * @exception UnsupportedQoS
114      * if no implementation supports the requested QoS settings
115      */

116     public EventChannel create_channel(Property[] qualitiyOfServiceProperties,
117             Property[] administrativeProperties, IntHolder JavaDoc channelIdentifier)
118             throws UnsupportedAdmin, UnsupportedQoS
119     {
120         try
121         {
122             AbstractEventChannel _channelServant = create_channel_servant(channelIdentifier,
123                     qualitiyOfServiceProperties, administrativeProperties);
124
125             addToChannels(channelIdentifier.value, _channelServant);
126
127             return EventChannelHelper.narrow(_channelServant.activate());
128         } catch (UnsupportedQoS e)
129         {
130             throw e;
131         } catch (UnsupportedAdmin e)
132         {
133             throw e;
134         } catch (Exception JavaDoc e)
135         {
136             logger_.fatalError("create_channel", e);
137
138             throw new RuntimeException JavaDoc();
139         }
140     }
141
142     protected AbstractEventChannel newEventChannel()
143     {
144         final MutablePicoContainer _channelContainer = newContainerForChannel();
145
146         ComponentAdapter _channelComponentAdapter = componentAdapterFactory_
147                 .createComponentAdapter(EventChannelImpl.class, EventChannelImpl.class, null);
148
149         _channelContainer.registerComponent(new CachingComponentAdapter(_channelComponentAdapter));
150
151         EventChannelImpl channel = (EventChannelImpl) _channelContainer
152                 .getComponentInstance(EventChannelImpl.class);
153
154         return channel;
155     }
156
157     /**
158      * The <code>get_all_channels</code> operation returns a sequence of all of the unique numeric
159      * identifiers corresponding to Notification Service event channels, which have been created by
160      * the target object.
161      *
162      * @return an <code>int[]</code> value
163      */

164     public int[] get_all_channels()
165     {
166         return getAllChannels();
167     }
168
169     /**
170      * The <code>get_event_channel</code> operation accepts as input a numeric value that is
171      * supposed to be the unique identifier of a Notification Service event channel, which has been
172      * created by the target object. If this input value does not correspond to such a unique
173      * identifier, the <code>ChannelNotFound</code> exception is raised. Otherwise, the operation
174      * returns the object reference of the Notification Service event channel corresponding to the
175      * input identifier.
176      *
177      * @param id
178      * an <code>int</code> the unique identifier of a Notification Service event
179      * channel
180      * @return an <code>EventChannel</code> corresponding to the input identifier
181      * @exception ChannelNotFound
182      * if the input value does not correspond to a Notification Service event channel
183      */

184     public EventChannel get_event_channel(int id) throws ChannelNotFound
185     {
186         return EventChannelHelper.narrow(get_event_channel_servant(id).activate());
187     }
188
189     public EventChannelFactory getEventChannelFactory()
190     {
191         return EventChannelFactoryHelper.narrow(thisRef_);
192     }
193
194     public Servant JavaDoc getServant()
195     {
196         return new JacORBEventChannelFactoryPOATie(this);
197     }
198
199     protected org.omg.CORBA.Object JavaDoc create_abstract_channel(Property[] admin, Property[] qos,
200             IntHolder JavaDoc id) throws UnsupportedAdmin, UnsupportedQoS
201     {
202         return create_channel(admin, qos, id);
203     }
204 }
Popular Tags