001: package org.jacorb.notification.util;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-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: import java.util.ArrayList;
024: import java.util.Collections;
025: import java.util.HashSet;
026: import java.util.List;
027: import java.util.Set;
028:
029: import org.apache.avalon.framework.configuration.Configuration;
030: import org.jacorb.notification.conf.Attributes;
031: import org.jacorb.notification.conf.Default;
032: import org.omg.CORBA.Any;
033: import org.omg.CosNotification.MaxConsumers;
034: import org.omg.CosNotification.MaxQueueLength;
035: import org.omg.CosNotification.MaxSuppliers;
036: import org.omg.CosNotification.Property;
037: import org.omg.CosNotification.PropertyError;
038: import org.omg.CosNotification.RejectNewEvents;
039: import org.omg.CosNotification.UnsupportedAdmin;
040:
041: /**
042: * @author Alphonse Bendt
043: * @version $Id: AdminPropertySet.java,v 1.7 2005/04/10 14:30:31 alphonse.bendt Exp $
044: */
045:
046: public class AdminPropertySet extends PropertySet {
047:
048: private final static Set sAdminPropertyNames_;
049:
050: private final Property[] defaultProperties_;
051:
052: static {
053: HashSet _adminProps = new HashSet();
054:
055: _adminProps.add(MaxQueueLength.value);
056: _adminProps.add(MaxConsumers.value);
057: _adminProps.add(MaxSuppliers.value);
058: _adminProps.add(RejectNewEvents.value);
059:
060: sAdminPropertyNames_ = Collections.unmodifiableSet(_adminProps);
061: }
062:
063: ////////////////////////////////////////
064:
065: private final Set validNames_ = sAdminPropertyNames_;
066:
067: ////////////////////////////////////////
068:
069: public AdminPropertySet(Configuration config) {
070: super ();
071:
072: int _maxConsumersDefault = config.getAttributeAsInteger(
073: Attributes.MAX_NUMBER_CONSUMERS,
074: Default.DEFAULT_MAX_NUMBER_CONSUMERS);
075:
076: Any _maxConsumersDefaultAny = sORB.create_any();
077: _maxConsumersDefaultAny.insert_long(_maxConsumersDefault);
078:
079: //////////////////////////////
080:
081: int _maxSuppliersDefault = config.getAttributeAsInteger(
082: Attributes.MAX_NUMBER_SUPPLIERS,
083: Default.DEFAULT_MAX_NUMBER_SUPPLIERS);
084:
085: Any _maxSuppliersDefaultAny = sORB.create_any();
086: _maxSuppliersDefaultAny.insert_long(_maxSuppliersDefault);
087:
088: //////////////////////////////
089:
090: int _maxQueueLength = config.getAttributeAsInteger(
091: Attributes.MAX_QUEUE_LENGTH,
092: Default.DEFAULT_MAX_QUEUE_LENGTH);
093:
094: Any _maxQueueLengthAny = sORB.create_any();
095: _maxQueueLengthAny.insert_long(_maxQueueLength);
096:
097: //////////////////////////////
098:
099: boolean _rejectNewEvents = config.getAttribute(
100: Attributes.REJECT_NEW_EVENTS,
101: Default.DEFAULT_REJECT_NEW_EVENTS).equals("on");
102:
103: Any _rejectNewEventsAny = sORB.create_any();
104: _rejectNewEventsAny.insert_boolean(_rejectNewEvents);
105:
106: //////////////////////////////
107:
108: defaultProperties_ = new Property[] {
109: new Property(MaxConsumers.value,
110: _maxConsumersDefaultAny),
111: new Property(MaxSuppliers.value,
112: _maxSuppliersDefaultAny),
113: new Property(MaxQueueLength.value, _maxQueueLengthAny),
114: new Property(RejectNewEvents.value, _rejectNewEventsAny) };
115:
116: set_admin(defaultProperties_);
117: }
118:
119: public Set getValidNames() {
120: return validNames_;
121: }
122:
123: public void set_admin(Property[] ps) {
124: set_properties(ps);
125: }
126:
127: public Property[] get_admin() {
128: return toArray();
129: }
130:
131: public void validate_admin(Property[] ps) throws UnsupportedAdmin {
132: List _errors = new ArrayList();
133:
134: checkPropertyExistence(ps, _errors);
135:
136: if (!_errors.isEmpty()) {
137: throw new UnsupportedAdmin((PropertyError[]) _errors
138: .toArray(PROPERTY_ERROR_ARRAY_TEMPLATE));
139: }
140: }
141: }
|