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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 */
026package org.forgerock.opendj.server.config.meta;
027
028
029
030import org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.client.ConcurrentModificationException;
032import org.forgerock.opendj.config.client.ManagedObject;
033import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
034import org.forgerock.opendj.config.client.OperationRejectedException;
035import org.forgerock.opendj.config.DNPropertyDefinition;
036import org.forgerock.opendj.config.EnumPropertyDefinition;
037import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
038import org.forgerock.opendj.config.ManagedObjectDefinition;
039import org.forgerock.opendj.config.PropertyException;
040import org.forgerock.opendj.config.PropertyOption;
041import org.forgerock.opendj.config.PropertyProvider;
042import org.forgerock.opendj.config.server.ConfigurationChangeListener;
043import org.forgerock.opendj.config.server.ServerManagedObject;
044import org.forgerock.opendj.config.StringPropertyDefinition;
045import org.forgerock.opendj.config.Tag;
046import org.forgerock.opendj.config.TopCfgDefn;
047import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
048import org.forgerock.opendj.ldap.DN;
049import org.forgerock.opendj.ldap.LdapException;
050import org.forgerock.opendj.server.config.client.BackendVLVIndexCfgClient;
051import org.forgerock.opendj.server.config.server.BackendVLVIndexCfg;
052
053
054
055/**
056 * An interface for querying the Backend VLV Index managed object
057 * definition meta information.
058 * <p>
059 * Backend VLV Indexes are used to store information about a specific
060 * search request that makes it possible to efficiently process them
061 * using the VLV control.
062 */
063public final class BackendVLVIndexCfgDefn extends ManagedObjectDefinition<BackendVLVIndexCfgClient, BackendVLVIndexCfg> {
064
065  // The singleton configuration definition instance.
066  private static final BackendVLVIndexCfgDefn INSTANCE = new BackendVLVIndexCfgDefn();
067
068
069
070  /**
071   * Defines the set of permissable values for the "scope" property.
072   * <p>
073   * Specifies the LDAP scope of the query that is being indexed.
074   */
075  public static enum Scope {
076
077    /**
078     * Search the base object only.
079     */
080    BASE_OBJECT("base-object"),
081
082
083
084    /**
085     * Search the immediate children of the base object but do not
086     * include any of their descendants or the base object itself.
087     */
088    SINGLE_LEVEL("single-level"),
089
090
091
092    /**
093     * Search the entire subtree below the base object but do not
094     * include the base object itself.
095     */
096    SUBORDINATE_SUBTREE("subordinate-subtree"),
097
098
099
100    /**
101     * Search the base object and the entire subtree below the base
102     * object.
103     */
104    WHOLE_SUBTREE("whole-subtree");
105
106
107
108    // String representation of the value.
109    private final String name;
110
111
112
113    // Private constructor.
114    private Scope(String name) { this.name = name; }
115
116
117
118    /**
119     * {@inheritDoc}
120     */
121    public String toString() { return name; }
122
123  }
124
125
126
127  // The "base-dn" property definition.
128  private static final DNPropertyDefinition PD_BASE_DN;
129
130
131
132  // The "filter" property definition.
133  private static final StringPropertyDefinition PD_FILTER;
134
135
136
137  // The "name" property definition.
138  private static final StringPropertyDefinition PD_NAME;
139
140
141
142  // The "scope" property definition.
143  private static final EnumPropertyDefinition<Scope> PD_SCOPE;
144
145
146
147  // The "sort-order" property definition.
148  private static final StringPropertyDefinition PD_SORT_ORDER;
149
150
151
152  // Build the "base-dn" property definition.
153  static {
154      DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "base-dn");
155      builder.setOption(PropertyOption.MANDATORY);
156      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "base-dn"));
157      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<DN>());
158      PD_BASE_DN = builder.getInstance();
159      INSTANCE.registerPropertyDefinition(PD_BASE_DN);
160  }
161
162
163
164  // Build the "filter" property definition.
165  static {
166      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "filter");
167      builder.setOption(PropertyOption.MANDATORY);
168      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "filter"));
169      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
170      builder.setPattern(".*", "STRING");
171      PD_FILTER = builder.getInstance();
172      INSTANCE.registerPropertyDefinition(PD_FILTER);
173  }
174
175
176
177  // Build the "name" property definition.
178  static {
179      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "name");
180      builder.setOption(PropertyOption.READ_ONLY);
181      builder.setOption(PropertyOption.MANDATORY);
182      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "name"));
183      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
184      PD_NAME = builder.getInstance();
185      INSTANCE.registerPropertyDefinition(PD_NAME);
186  }
187
188
189
190  // Build the "scope" property definition.
191  static {
192      EnumPropertyDefinition.Builder<Scope> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "scope");
193      builder.setOption(PropertyOption.MANDATORY);
194      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "scope"));
195      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Scope>());
196      builder.setEnumClass(Scope.class);
197      PD_SCOPE = builder.getInstance();
198      INSTANCE.registerPropertyDefinition(PD_SCOPE);
199  }
200
201
202
203  // Build the "sort-order" property definition.
204  static {
205      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "sort-order");
206      builder.setOption(PropertyOption.MANDATORY);
207      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "sort-order"));
208      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
209      builder.setPattern(".*", "STRING");
210      PD_SORT_ORDER = builder.getInstance();
211      INSTANCE.registerPropertyDefinition(PD_SORT_ORDER);
212  }
213
214
215
216  // Register the tags associated with this managed object definition.
217  static {
218    INSTANCE.registerTag(Tag.valueOf("database"));
219  }
220
221
222
223  /**
224   * Get the Backend VLV Index configuration definition singleton.
225   *
226   * @return Returns the Backend VLV Index configuration definition
227   *         singleton.
228   */
229  public static BackendVLVIndexCfgDefn getInstance() {
230    return INSTANCE;
231  }
232
233
234
235  /**
236   * Private constructor.
237   */
238  private BackendVLVIndexCfgDefn() {
239    super("backend-vlv-index", TopCfgDefn.getInstance());
240  }
241
242
243
244  /**
245   * {@inheritDoc}
246   */
247  public BackendVLVIndexCfgClient createClientConfiguration(
248      ManagedObject<? extends BackendVLVIndexCfgClient> impl) {
249    return new BackendVLVIndexCfgClientImpl(impl);
250  }
251
252
253
254  /**
255   * {@inheritDoc}
256   */
257  public BackendVLVIndexCfg createServerConfiguration(
258      ServerManagedObject<? extends BackendVLVIndexCfg> impl) {
259    return new BackendVLVIndexCfgServerImpl(impl);
260  }
261
262
263
264  /**
265   * {@inheritDoc}
266   */
267  public Class<BackendVLVIndexCfg> getServerConfigurationClass() {
268    return BackendVLVIndexCfg.class;
269  }
270
271
272
273  /**
274   * Get the "base-dn" property definition.
275   * <p>
276   * Specifies the base DN used in the search query that is being
277   * indexed.
278   *
279   * @return Returns the "base-dn" property definition.
280   */
281  public DNPropertyDefinition getBaseDNPropertyDefinition() {
282    return PD_BASE_DN;
283  }
284
285
286
287  /**
288   * Get the "filter" property definition.
289   * <p>
290   * Specifies the LDAP filter used in the query that is being
291   * indexed.
292   *
293   * @return Returns the "filter" property definition.
294   */
295  public StringPropertyDefinition getFilterPropertyDefinition() {
296    return PD_FILTER;
297  }
298
299
300
301  /**
302   * Get the "name" property definition.
303   * <p>
304   * Specifies a unique name for this VLV index.
305   *
306   * @return Returns the "name" property definition.
307   */
308  public StringPropertyDefinition getNamePropertyDefinition() {
309    return PD_NAME;
310  }
311
312
313
314  /**
315   * Get the "scope" property definition.
316   * <p>
317   * Specifies the LDAP scope of the query that is being indexed.
318   *
319   * @return Returns the "scope" property definition.
320   */
321  public EnumPropertyDefinition<Scope> getScopePropertyDefinition() {
322    return PD_SCOPE;
323  }
324
325
326
327  /**
328   * Get the "sort-order" property definition.
329   * <p>
330   * Specifies the names of the attributes that are used to sort the
331   * entries for the query being indexed.
332   * <p>
333   * Multiple attributes can be used to determine the sort order by
334   * listing the attribute names from highest to lowest precedence.
335   * Optionally, + or - can be prefixed to the attribute name to sort
336   * the attribute in ascending order or descending order respectively.
337   *
338   * @return Returns the "sort-order" property definition.
339   */
340  public StringPropertyDefinition getSortOrderPropertyDefinition() {
341    return PD_SORT_ORDER;
342  }
343
344
345
346  /**
347   * Managed object client implementation.
348   */
349  private static class BackendVLVIndexCfgClientImpl implements
350    BackendVLVIndexCfgClient {
351
352    // Private implementation.
353    private ManagedObject<? extends BackendVLVIndexCfgClient> impl;
354
355
356
357    // Private constructor.
358    private BackendVLVIndexCfgClientImpl(
359        ManagedObject<? extends BackendVLVIndexCfgClient> impl) {
360      this.impl = impl;
361    }
362
363
364
365    /**
366     * {@inheritDoc}
367     */
368    public DN getBaseDN() {
369      return impl.getPropertyValue(INSTANCE.getBaseDNPropertyDefinition());
370    }
371
372
373
374    /**
375     * {@inheritDoc}
376     */
377    public void setBaseDN(DN value) {
378      impl.setPropertyValue(INSTANCE.getBaseDNPropertyDefinition(), value);
379    }
380
381
382
383    /**
384     * {@inheritDoc}
385     */
386    public String getFilter() {
387      return impl.getPropertyValue(INSTANCE.getFilterPropertyDefinition());
388    }
389
390
391
392    /**
393     * {@inheritDoc}
394     */
395    public void setFilter(String value) {
396      impl.setPropertyValue(INSTANCE.getFilterPropertyDefinition(), value);
397    }
398
399
400
401    /**
402     * {@inheritDoc}
403     */
404    public String getName() {
405      return impl.getPropertyValue(INSTANCE.getNamePropertyDefinition());
406    }
407
408
409
410    /**
411     * {@inheritDoc}
412     */
413    public void setName(String value) throws PropertyException {
414      impl.setPropertyValue(INSTANCE.getNamePropertyDefinition(), value);
415    }
416
417
418
419    /**
420     * {@inheritDoc}
421     */
422    public Scope getScope() {
423      return impl.getPropertyValue(INSTANCE.getScopePropertyDefinition());
424    }
425
426
427
428    /**
429     * {@inheritDoc}
430     */
431    public void setScope(Scope value) {
432      impl.setPropertyValue(INSTANCE.getScopePropertyDefinition(), value);
433    }
434
435
436
437    /**
438     * {@inheritDoc}
439     */
440    public String getSortOrder() {
441      return impl.getPropertyValue(INSTANCE.getSortOrderPropertyDefinition());
442    }
443
444
445
446    /**
447     * {@inheritDoc}
448     */
449    public void setSortOrder(String value) {
450      impl.setPropertyValue(INSTANCE.getSortOrderPropertyDefinition(), value);
451    }
452
453
454
455    /**
456     * {@inheritDoc}
457     */
458    public ManagedObjectDefinition<? extends BackendVLVIndexCfgClient, ? extends BackendVLVIndexCfg> definition() {
459      return INSTANCE;
460    }
461
462
463
464    /**
465     * {@inheritDoc}
466     */
467    public PropertyProvider properties() {
468      return impl;
469    }
470
471
472
473    /**
474     * {@inheritDoc}
475     */
476    public void commit() throws ManagedObjectAlreadyExistsException,
477        MissingMandatoryPropertiesException, ConcurrentModificationException,
478        OperationRejectedException, LdapException {
479      impl.commit();
480    }
481
482  }
483
484
485
486  /**
487   * Managed object server implementation.
488   */
489  private static class BackendVLVIndexCfgServerImpl implements
490    BackendVLVIndexCfg {
491
492    // Private implementation.
493    private ServerManagedObject<? extends BackendVLVIndexCfg> impl;
494
495    // The value of the "base-dn" property.
496    private final DN pBaseDN;
497
498    // The value of the "filter" property.
499    private final String pFilter;
500
501    // The value of the "name" property.
502    private final String pName;
503
504    // The value of the "scope" property.
505    private final Scope pScope;
506
507    // The value of the "sort-order" property.
508    private final String pSortOrder;
509
510
511
512    // Private constructor.
513    private BackendVLVIndexCfgServerImpl(ServerManagedObject<? extends BackendVLVIndexCfg> impl) {
514      this.impl = impl;
515      this.pBaseDN = impl.getPropertyValue(INSTANCE.getBaseDNPropertyDefinition());
516      this.pFilter = impl.getPropertyValue(INSTANCE.getFilterPropertyDefinition());
517      this.pName = impl.getPropertyValue(INSTANCE.getNamePropertyDefinition());
518      this.pScope = impl.getPropertyValue(INSTANCE.getScopePropertyDefinition());
519      this.pSortOrder = impl.getPropertyValue(INSTANCE.getSortOrderPropertyDefinition());
520    }
521
522
523
524    /**
525     * {@inheritDoc}
526     */
527    public void addChangeListener(
528        ConfigurationChangeListener<BackendVLVIndexCfg> listener) {
529      impl.registerChangeListener(listener);
530    }
531
532
533
534    /**
535     * {@inheritDoc}
536     */
537    public void removeChangeListener(
538        ConfigurationChangeListener<BackendVLVIndexCfg> listener) {
539      impl.deregisterChangeListener(listener);
540    }
541
542
543
544    /**
545     * {@inheritDoc}
546     */
547    public DN getBaseDN() {
548      return pBaseDN;
549    }
550
551
552
553    /**
554     * {@inheritDoc}
555     */
556    public String getFilter() {
557      return pFilter;
558    }
559
560
561
562    /**
563     * {@inheritDoc}
564     */
565    public String getName() {
566      return pName;
567    }
568
569
570
571    /**
572     * {@inheritDoc}
573     */
574    public Scope getScope() {
575      return pScope;
576    }
577
578
579
580    /**
581     * {@inheritDoc}
582     */
583    public String getSortOrder() {
584      return pSortOrder;
585    }
586
587
588
589    /**
590     * {@inheritDoc}
591     */
592    public Class<? extends BackendVLVIndexCfg> configurationClass() {
593      return BackendVLVIndexCfg.class;
594    }
595
596
597
598    /**
599     * {@inheritDoc}
600     */
601    public DN dn() {
602      return impl.getDN();
603    }
604
605  }
606}