KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > util > AdminPropertySet


1 package org.jacorb.notification.util;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-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 import java.util.ArrayList JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import org.apache.avalon.framework.configuration.Configuration;
30 import org.jacorb.notification.conf.Attributes;
31 import org.jacorb.notification.conf.Default;
32 import org.omg.CORBA.Any JavaDoc;
33 import org.omg.CosNotification.MaxConsumers;
34 import org.omg.CosNotification.MaxQueueLength;
35 import org.omg.CosNotification.MaxSuppliers;
36 import org.omg.CosNotification.Property;
37 import org.omg.CosNotification.PropertyError;
38 import org.omg.CosNotification.RejectNewEvents;
39 import org.omg.CosNotification.UnsupportedAdmin;
40
41 /**
42  * @author Alphonse Bendt
43  * @version $Id: AdminPropertySet.java,v 1.7 2005/04/10 14:30:31 alphonse.bendt Exp $
44  */

45
46 public class AdminPropertySet
47     extends PropertySet {
48
49     private final static Set JavaDoc sAdminPropertyNames_;
50
51     private final Property[] defaultProperties_;
52
53     static {
54         HashSet JavaDoc _adminProps = new HashSet JavaDoc();
55
56         _adminProps.add(MaxQueueLength.value);
57         _adminProps.add(MaxConsumers.value);
58         _adminProps.add(MaxSuppliers.value);
59         _adminProps.add(RejectNewEvents.value);
60         
61         sAdminPropertyNames_ = Collections.unmodifiableSet(_adminProps);
62     }
63
64     ////////////////////////////////////////
65

66     private final Set JavaDoc validNames_ = sAdminPropertyNames_;
67
68     ////////////////////////////////////////
69

70     public AdminPropertySet(Configuration config)
71     {
72         super();
73     
74         int _maxConsumersDefault =
75             config.getAttributeAsInteger(Attributes.MAX_NUMBER_CONSUMERS,
76                                        Default.DEFAULT_MAX_NUMBER_CONSUMERS);
77
78         Any JavaDoc _maxConsumersDefaultAny = sORB.create_any();
79         _maxConsumersDefaultAny.insert_long( _maxConsumersDefault );
80
81         //////////////////////////////
82

83         int _maxSuppliersDefault =
84             config.getAttributeAsInteger(Attributes.MAX_NUMBER_SUPPLIERS,
85                                        Default.DEFAULT_MAX_NUMBER_SUPPLIERS);
86
87         Any JavaDoc _maxSuppliersDefaultAny = sORB.create_any();
88         _maxSuppliersDefaultAny.insert_long(_maxSuppliersDefault);
89
90         //////////////////////////////
91

92         int _maxQueueLength =
93             config.getAttributeAsInteger(Attributes.MAX_QUEUE_LENGTH,
94                                        Default.DEFAULT_MAX_QUEUE_LENGTH);
95
96         Any JavaDoc _maxQueueLengthAny = sORB.create_any();
97         _maxQueueLengthAny.insert_long(_maxQueueLength);
98
99         //////////////////////////////
100

101         boolean _rejectNewEvents =
102             config.getAttribute(Attributes.REJECT_NEW_EVENTS,
103                               Default.DEFAULT_REJECT_NEW_EVENTS).equals("on");
104
105         Any JavaDoc _rejectNewEventsAny = sORB.create_any();
106         _rejectNewEventsAny.insert_boolean(_rejectNewEvents);
107
108         //////////////////////////////
109

110         defaultProperties_ = new Property[] {
111             new Property(MaxConsumers.value, _maxConsumersDefaultAny),
112             new Property(MaxSuppliers.value, _maxSuppliersDefaultAny),
113             new Property(MaxQueueLength.value, _maxQueueLengthAny),
114             new Property(RejectNewEvents.value, _rejectNewEventsAny)
115         };
116
117         set_admin(defaultProperties_);
118     }
119
120
121     public Set JavaDoc getValidNames()
122     {
123         return validNames_;
124     }
125
126
127     public void set_admin(Property[] ps)
128     {
129         set_properties(ps);
130     }
131
132
133     public Property[] get_admin()
134     {
135         return toArray();
136     }
137
138
139     public void validate_admin(Property[] ps) throws UnsupportedAdmin
140     {
141         List JavaDoc _errors = new ArrayList JavaDoc();
142
143         checkPropertyExistence(ps, _errors);
144
145         if (!_errors.isEmpty())
146             {
147                 throw new UnsupportedAdmin((PropertyError[])_errors.toArray(PROPERTY_ERROR_ARRAY_TEMPLATE));
148             }
149     }
150 }
151
Popular Tags