001: package org.jacorb.notification;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1999-2004 Gerald Brose
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: import org.jacorb.notification.conf.Attributes;
025: import org.jacorb.notification.conf.Default;
026: import org.jacorb.notification.container.CORBAObjectComponentAdapter;
027: import org.omg.CORBA.IntHolder;
028: import org.omg.CORBA.ORB;
029: import org.omg.CORBA.UserException;
030: import org.omg.CosNotification.Property;
031: import org.omg.CosNotification.UnsupportedAdmin;
032: import org.omg.CosNotification.UnsupportedQoS;
033: import org.omg.CosNotifyChannelAdmin.ChannelNotFound;
034: import org.omg.CosNotifyChannelAdmin.EventChannel;
035: import org.omg.CosNotifyChannelAdmin.EventChannelFactory;
036: import org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper;
037: import org.omg.CosNotifyChannelAdmin.EventChannelHelper;
038: import org.omg.PortableServer.Servant;
039: import org.picocontainer.MutablePicoContainer;
040:
041: /**
042: * <code>EventChannelFactoryImpl</code> is a implementation of the
043: * <code>EventChannelFactory</code> interface which defines operations for creating and managing
044: * new Notification Service style event channels. It supports a routine that creates new instances
045: * of Notification Service event channels and assigns unique numeric identifiers to them. In
046: * addition the <code>EventChannelFactory</code> interface supports a routing, which can return
047: * the unique identifiers assigned to all event channels created by a given instance of
048: * <code>EventChannelFactory</code>, and another routine which, given the unique identifier of an
049: * event channel created by a target <code>EventChannelFactory</code> instance, returns the object
050: * reference of that event channel. <br>
051: *
052: * @author Alphonse Bendt
053: * @version $Id: EventChannelFactoryImpl.java,v 1.45 2006/05/23 10:40:35 alphonse.bendt Exp $
054: */
055:
056: public class EventChannelFactoryImpl extends AbstractChannelFactory
057: implements JacORBEventChannelFactoryOperations {
058: // //////////////////////////////////////
059:
060: protected String getShortcut() {
061: return "NotificationService";
062: }
063:
064: protected String getObjectName() {
065: return "_ECFactory";
066: }
067:
068: // //////////////////////////////////////
069:
070: public EventChannelFactoryImpl(MutablePicoContainer container,
071: ORB orb) throws UserException {
072: super (container, orb);
073:
074: container_.registerComponent(new CORBAObjectComponentAdapter(
075: EventChannelFactory.class, EventChannelFactoryHelper
076: .narrow(this Ref_)));
077: }
078:
079: /**
080: * The <code>create_channel</code> operation is invoked to create a new instance of the
081: * Notification Service style event channel. This operation accepts two input parameters. The
082: * first input parameter is a list of name-value pairs, which specify the initial QoS property
083: * settings for the new channel. The second input parameter is a list of name-value pairs, which
084: * specify the initial administrative property settings for the new channel. <br>
085: * If no implementation of the <code>EventChannel</code> Interface exists that can support all
086: * of the requested administrative property settings, the <code>UnsupportedAdmin</code>
087: * exception is raised This exception contains as data a sequence of data structures, each
088: * identifies the name of an administrative property in the input list whose requested setting
089: * could not be satisfied, along with an error code and a range of settings for the property
090: * which could be satisfied. The meanings of the error codes that might be returned are
091: * described in <a href="%%%NOTIFICATION_SPEC_URL%%%">Notification Service Specification </a>
092: * Table 2-5 on page 2-46. <br>
093: * If neither of these exceptions is raised, the <code>create_channel</code> operation will
094: * return a reference to a new Notification Service style event channel. In addition, the
095: * operation assigns to this new event channel a numeric identifier, which is unique among all
096: * event channels created by the target object. This numeric identifier is returned as an output
097: * parameter.
098: *
099: * @param qualitiyOfServiceProperties
100: * a list of name-value pairs, which specify the initial QoS property settings for
101: * the new channel
102: * @param administrativeProperties
103: * a list of name-value pairs, which specify the initial administrative property
104: * settings for the new channel
105: * @param channelIdentifier
106: * a reference to the new event channel
107: * @return a newly created event channel
108: * @exception UnsupportedAdmin
109: * if no implementation supports the requested administrative settings
110: * @exception UnsupportedQoS
111: * if no implementation supports the requested QoS settings
112: */
113: public EventChannel create_channel(
114: Property[] qualitiyOfServiceProperties,
115: Property[] administrativeProperties,
116: IntHolder channelIdentifier) throws UnsupportedAdmin,
117: UnsupportedQoS {
118: try {
119: AbstractEventChannel _channelServant = create_channel_servant(
120: channelIdentifier, qualitiyOfServiceProperties,
121: administrativeProperties);
122:
123: addToChannels(channelIdentifier.value, _channelServant);
124:
125: return EventChannelHelper
126: .narrow(_channelServant.activate());
127: } catch (UnsupportedQoS e) {
128: throw e;
129: } catch (UnsupportedAdmin e) {
130: throw e;
131: } catch (Exception e) {
132: logger_.fatalError("create_channel", e);
133:
134: throw new RuntimeException();
135: }
136: }
137:
138: protected AbstractEventChannel newEventChannel() {
139: final MutablePicoContainer _channelContainer = newContainerForChannel();
140:
141: _channelContainer.registerComponentImplementation(
142: AbstractEventChannel.class, EventChannelImpl.class);
143:
144: AbstractEventChannel channel = (AbstractEventChannel) _channelContainer
145: .getComponentInstanceOfType(AbstractEventChannel.class);
146:
147: return channel;
148: }
149:
150: protected void channelCreated(AbstractEventChannel channel) {
151: if (config_.getAttributeAsBoolean(
152: Attributes.LAZY_DEFAULT_ADMIN_INIT,
153: Default.DEFAULT_LAZY_DEFAULT_ADMIN_INIT)) {
154: ((EventChannelImpl) channel).default_consumer_admin();
155: ((EventChannelImpl) channel).default_supplier_admin();
156: }
157: }
158:
159: /**
160: * The <code>get_all_channels</code> operation returns a sequence of all of the unique numeric
161: * identifiers corresponding to Notification Service event channels, which have been created by
162: * the target object.
163: *
164: * @return an <code>int[]</code> value
165: */
166: public int[] get_all_channels() {
167: return getAllChannels();
168: }
169:
170: /**
171: * The <code>get_event_channel</code> operation accepts as input a numeric value that is
172: * supposed to be the unique identifier of a Notification Service event channel, which has been
173: * created by the target object. If this input value does not correspond to such a unique
174: * identifier, the <code>ChannelNotFound</code> exception is raised. Otherwise, the operation
175: * returns the object reference of the Notification Service event channel corresponding to the
176: * input identifier.
177: *
178: * @param id
179: * an <code>int</code> the unique identifier of a Notification Service event
180: * channel
181: * @return an <code>EventChannel</code> corresponding to the input identifier
182: * @exception ChannelNotFound
183: * if the input value does not correspond to a Notification Service event channel
184: */
185: public EventChannel get_event_channel(int id)
186: throws ChannelNotFound {
187: return EventChannelHelper.narrow(get_event_channel_servant(id)
188: .activate());
189: }
190:
191: public EventChannelFactory getEventChannelFactory() {
192: return EventChannelFactoryHelper.narrow(this Ref_);
193: }
194:
195: public Servant getServant() {
196: return new JacORBEventChannelFactoryPOATie(this );
197: }
198:
199: protected org.omg.CORBA.Object create_abstract_channel(
200: Property[] admin, Property[] qos, IntHolder id)
201: throws UnsupportedAdmin, UnsupportedQoS {
202: return create_channel(admin, qos, id);
203: }
204: }
|