001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.admin.std.meta;
028    
029    
030    
031    import java.util.Collection;
032    import java.util.SortedSet;
033    import java.util.TreeSet;
034    import org.opends.server.admin.AdministratorAction;
035    import org.opends.server.admin.AggregationPropertyDefinition;
036    import org.opends.server.admin.BooleanPropertyDefinition;
037    import org.opends.server.admin.client.AuthorizationException;
038    import org.opends.server.admin.client.CommunicationException;
039    import org.opends.server.admin.client.ConcurrentModificationException;
040    import org.opends.server.admin.client.ManagedObject;
041    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
042    import org.opends.server.admin.client.OperationRejectedException;
043    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
044    import org.opends.server.admin.ManagedObjectDefinition;
045    import org.opends.server.admin.PropertyIsReadOnlyException;
046    import org.opends.server.admin.PropertyOption;
047    import org.opends.server.admin.PropertyProvider;
048    import org.opends.server.admin.server.ConfigurationChangeListener;
049    import org.opends.server.admin.server.ServerManagedObject;
050    import org.opends.server.admin.std.client.NetworkGroupCfgClient;
051    import org.opends.server.admin.std.client.WorkflowCfgClient;
052    import org.opends.server.admin.std.server.NetworkGroupCfg;
053    import org.opends.server.admin.std.server.WorkflowCfg;
054    import org.opends.server.admin.StringPropertyDefinition;
055    import org.opends.server.admin.Tag;
056    import org.opends.server.admin.TopCfgDefn;
057    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
058    import org.opends.server.types.DN;
059    
060    
061    
062    /**
063     * An interface for querying the Network Group managed object
064     * definition meta information.
065     * <p>
066     * The Network Group is used to classify incoming connections and
067     * route requests to workflows.
068     */
069    public final class NetworkGroupCfgDefn extends ManagedObjectDefinition<NetworkGroupCfgClient, NetworkGroupCfg> {
070    
071      // The singleton configuration definition instance.
072      private static final NetworkGroupCfgDefn INSTANCE = new NetworkGroupCfgDefn();
073    
074    
075    
076      // The "enabled" property definition.
077      private static final BooleanPropertyDefinition PD_ENABLED;
078    
079    
080    
081      // The "network-group-id" property definition.
082      private static final StringPropertyDefinition PD_NETWORK_GROUP_ID;
083    
084    
085    
086      // The "workflow" property definition.
087      private static final AggregationPropertyDefinition<WorkflowCfgClient, WorkflowCfg> PD_WORKFLOW;
088    
089    
090    
091      // Build the "enabled" property definition.
092      static {
093          BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
094          builder.setOption(PropertyOption.MANDATORY);
095          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
096          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
097          PD_ENABLED = builder.getInstance();
098          INSTANCE.registerPropertyDefinition(PD_ENABLED);
099      }
100    
101    
102    
103      // Build the "network-group-id" property definition.
104      static {
105          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "network-group-id");
106          builder.setOption(PropertyOption.READ_ONLY);
107          builder.setOption(PropertyOption.MANDATORY);
108          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "network-group-id"));
109          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
110          PD_NETWORK_GROUP_ID = builder.getInstance();
111          INSTANCE.registerPropertyDefinition(PD_NETWORK_GROUP_ID);
112      }
113    
114    
115    
116      // Build the "workflow" property definition.
117      static {
118          AggregationPropertyDefinition.Builder<WorkflowCfgClient, WorkflowCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "workflow");
119          builder.setOption(PropertyOption.MULTI_VALUED);
120          builder.setOption(PropertyOption.READ_ONLY);
121          builder.setOption(PropertyOption.MANDATORY);
122          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "workflow"));
123          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
124          builder.setParentPath("/");
125          builder.setRelationDefinition("workflow");
126          PD_WORKFLOW = builder.getInstance();
127          INSTANCE.registerPropertyDefinition(PD_WORKFLOW);
128          INSTANCE.registerConstraint(PD_WORKFLOW.getSourceConstraint());
129      }
130    
131    
132    
133      // Register the tags associated with this managed object definition.
134      static {
135        INSTANCE.registerTag(Tag.valueOf("core-server"));
136      }
137    
138    
139    
140      /**
141       * Get the Network Group configuration definition singleton.
142       *
143       * @return Returns the Network Group configuration definition
144       *         singleton.
145       */
146      public static NetworkGroupCfgDefn getInstance() {
147        return INSTANCE;
148      }
149    
150    
151    
152      /**
153       * Private constructor.
154       */
155      private NetworkGroupCfgDefn() {
156        super("network-group", TopCfgDefn.getInstance());
157      }
158    
159    
160    
161      /**
162       * {@inheritDoc}
163       */
164      public NetworkGroupCfgClient createClientConfiguration(
165          ManagedObject<? extends NetworkGroupCfgClient> impl) {
166        return new NetworkGroupCfgClientImpl(impl);
167      }
168    
169    
170    
171      /**
172       * {@inheritDoc}
173       */
174      public NetworkGroupCfg createServerConfiguration(
175          ServerManagedObject<? extends NetworkGroupCfg> impl) {
176        return new NetworkGroupCfgServerImpl(impl);
177      }
178    
179    
180    
181      /**
182       * {@inheritDoc}
183       */
184      public Class<NetworkGroupCfg> getServerConfigurationClass() {
185        return NetworkGroupCfg.class;
186      }
187    
188    
189    
190      /**
191       * Get the "enabled" property definition.
192       * <p>
193       * Indicates whether the Network Group is enabled for use in the
194       * server.
195       * <p>
196       * If a network group is not enabled, its workflows will not be
197       * accessible when processing operations.
198       *
199       * @return Returns the "enabled" property definition.
200       */
201      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
202        return PD_ENABLED;
203      }
204    
205    
206    
207      /**
208       * Get the "network-group-id" property definition.
209       * <p>
210       * Specifies the name that is used to identify the associated
211       * Network Group .
212       * <p>
213       * The name must be unique among all the Network Groups in the
214       * server.
215       *
216       * @return Returns the "network-group-id" property definition.
217       */
218      public StringPropertyDefinition getNetworkGroupIdPropertyDefinition() {
219        return PD_NETWORK_GROUP_ID;
220      }
221    
222    
223    
224      /**
225       * Get the "workflow" property definition.
226       * <p>
227       * Identifies the workflows in the network group.
228       *
229       * @return Returns the "workflow" property definition.
230       */
231      public AggregationPropertyDefinition<WorkflowCfgClient, WorkflowCfg> getWorkflowPropertyDefinition() {
232        return PD_WORKFLOW;
233      }
234    
235    
236    
237      /**
238       * Managed object client implementation.
239       */
240      private static class NetworkGroupCfgClientImpl implements
241        NetworkGroupCfgClient {
242    
243        // Private implementation.
244        private ManagedObject<? extends NetworkGroupCfgClient> impl;
245    
246    
247    
248        // Private constructor.
249        private NetworkGroupCfgClientImpl(
250            ManagedObject<? extends NetworkGroupCfgClient> impl) {
251          this.impl = impl;
252        }
253    
254    
255    
256        /**
257         * {@inheritDoc}
258         */
259        public Boolean isEnabled() {
260          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
261        }
262    
263    
264    
265        /**
266         * {@inheritDoc}
267         */
268        public void setEnabled(boolean value) {
269          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
270        }
271    
272    
273    
274        /**
275         * {@inheritDoc}
276         */
277        public String getNetworkGroupId() {
278          return impl.getPropertyValue(INSTANCE.getNetworkGroupIdPropertyDefinition());
279        }
280    
281    
282    
283        /**
284         * {@inheritDoc}
285         */
286        public void setNetworkGroupId(String value) throws PropertyIsReadOnlyException {
287          impl.setPropertyValue(INSTANCE.getNetworkGroupIdPropertyDefinition(), value);
288        }
289    
290    
291    
292        /**
293         * {@inheritDoc}
294         */
295        public SortedSet<String> getWorkflow() {
296          return impl.getPropertyValues(INSTANCE.getWorkflowPropertyDefinition());
297        }
298    
299    
300    
301        /**
302         * {@inheritDoc}
303         */
304        public void setWorkflow(Collection<String> values) {
305          impl.setPropertyValues(INSTANCE.getWorkflowPropertyDefinition(), values);
306        }
307    
308    
309    
310        /**
311         * {@inheritDoc}
312         */
313        public ManagedObjectDefinition<? extends NetworkGroupCfgClient, ? extends NetworkGroupCfg> definition() {
314          return INSTANCE;
315        }
316    
317    
318    
319        /**
320         * {@inheritDoc}
321         */
322        public PropertyProvider properties() {
323          return impl;
324        }
325    
326    
327    
328        /**
329         * {@inheritDoc}
330         */
331        public void commit() throws ManagedObjectAlreadyExistsException,
332            MissingMandatoryPropertiesException, ConcurrentModificationException,
333            OperationRejectedException, AuthorizationException,
334            CommunicationException {
335          impl.commit();
336        }
337    
338      }
339    
340    
341    
342      /**
343       * Managed object server implementation.
344       */
345      private static class NetworkGroupCfgServerImpl implements
346        NetworkGroupCfg {
347    
348        // Private implementation.
349        private ServerManagedObject<? extends NetworkGroupCfg> impl;
350    
351        // The value of the "enabled" property.
352        private final boolean pEnabled;
353    
354        // The value of the "network-group-id" property.
355        private final String pNetworkGroupId;
356    
357        // The value of the "workflow" property.
358        private final SortedSet<String> pWorkflow;
359    
360    
361    
362        // Private constructor.
363        private NetworkGroupCfgServerImpl(ServerManagedObject<? extends NetworkGroupCfg> impl) {
364          this.impl = impl;
365          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
366          this.pNetworkGroupId = impl.getPropertyValue(INSTANCE.getNetworkGroupIdPropertyDefinition());
367          this.pWorkflow = impl.getPropertyValues(INSTANCE.getWorkflowPropertyDefinition());
368        }
369    
370    
371    
372        /**
373         * {@inheritDoc}
374         */
375        public void addChangeListener(
376            ConfigurationChangeListener<NetworkGroupCfg> listener) {
377          impl.registerChangeListener(listener);
378        }
379    
380    
381    
382        /**
383         * {@inheritDoc}
384         */
385        public void removeChangeListener(
386            ConfigurationChangeListener<NetworkGroupCfg> listener) {
387          impl.deregisterChangeListener(listener);
388        }
389    
390    
391    
392        /**
393         * {@inheritDoc}
394         */
395        public boolean isEnabled() {
396          return pEnabled;
397        }
398    
399    
400    
401        /**
402         * {@inheritDoc}
403         */
404        public String getNetworkGroupId() {
405          return pNetworkGroupId;
406        }
407    
408    
409    
410        /**
411         * {@inheritDoc}
412         */
413        public SortedSet<String> getWorkflow() {
414          return pWorkflow;
415        }
416    
417    
418    
419        /**
420         * {@inheritDoc}
421         */
422        public SortedSet<DN> getWorkflowDNs() {
423          SortedSet<String> values = getWorkflow();
424          SortedSet<DN> dnValues = new TreeSet<DN>();
425          for (String value : values) {
426            DN dn = INSTANCE.getWorkflowPropertyDefinition().getChildDN(value);
427            dnValues.add(dn);
428          }
429          return dnValues;
430        }
431    
432    
433    
434        /**
435         * {@inheritDoc}
436         */
437        public Class<? extends NetworkGroupCfg> configurationClass() {
438          return NetworkGroupCfg.class;
439        }
440    
441    
442    
443        /**
444         * {@inheritDoc}
445         */
446        public DN dn() {
447          return impl.getDN();
448        }
449    
450      }
451    }