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    /** {@inheritDoc} */
119    public String toString() { return name; }
120
121  }
122
123
124
125  /** The "base-dn" property definition. */
126  private static final DNPropertyDefinition PD_BASE_DN;
127
128
129
130  /** The "filter" property definition. */
131  private static final StringPropertyDefinition PD_FILTER;
132
133
134
135  /** The "name" property definition. */
136  private static final StringPropertyDefinition PD_NAME;
137
138
139
140  /** The "scope" property definition. */
141  private static final EnumPropertyDefinition<Scope> PD_SCOPE;
142
143
144
145  /** The "sort-order" property definition. */
146  private static final StringPropertyDefinition PD_SORT_ORDER;
147
148
149
150  /** Build the "base-dn" property definition. */
151  static {
152      DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "base-dn");
153      builder.setOption(PropertyOption.MANDATORY);
154      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "base-dn"));
155      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<DN>());
156      PD_BASE_DN = builder.getInstance();
157      INSTANCE.registerPropertyDefinition(PD_BASE_DN);
158  }
159
160
161
162  /** Build the "filter" property definition. */
163  static {
164      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "filter");
165      builder.setOption(PropertyOption.MANDATORY);
166      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "filter"));
167      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
168      builder.setPattern(".*", "STRING");
169      PD_FILTER = builder.getInstance();
170      INSTANCE.registerPropertyDefinition(PD_FILTER);
171  }
172
173
174
175  /** Build the "name" property definition. */
176  static {
177      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "name");
178      builder.setOption(PropertyOption.READ_ONLY);
179      builder.setOption(PropertyOption.MANDATORY);
180      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "name"));
181      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
182      PD_NAME = builder.getInstance();
183      INSTANCE.registerPropertyDefinition(PD_NAME);
184  }
185
186
187
188  /** Build the "scope" property definition. */
189  static {
190      EnumPropertyDefinition.Builder<Scope> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "scope");
191      builder.setOption(PropertyOption.MANDATORY);
192      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "scope"));
193      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Scope>());
194      builder.setEnumClass(Scope.class);
195      PD_SCOPE = builder.getInstance();
196      INSTANCE.registerPropertyDefinition(PD_SCOPE);
197  }
198
199
200
201  /** Build the "sort-order" property definition. */
202  static {
203      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "sort-order");
204      builder.setOption(PropertyOption.MANDATORY);
205      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "sort-order"));
206      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
207      builder.setPattern(".*", "STRING");
208      PD_SORT_ORDER = builder.getInstance();
209      INSTANCE.registerPropertyDefinition(PD_SORT_ORDER);
210  }
211
212
213
214  // Register the tags associated with this managed object definition.
215  static {
216    INSTANCE.registerTag(Tag.valueOf("database"));
217  }
218
219
220
221  /**
222   * Get the Backend VLV Index configuration definition singleton.
223   *
224   * @return Returns the Backend VLV Index configuration definition
225   *         singleton.
226   */
227  public static BackendVLVIndexCfgDefn getInstance() {
228    return INSTANCE;
229  }
230
231
232
233  /**
234   * Private constructor.
235   */
236  private BackendVLVIndexCfgDefn() {
237    super("backend-vlv-index", TopCfgDefn.getInstance());
238  }
239
240
241
242  /** {@inheritDoc} */
243  public BackendVLVIndexCfgClient createClientConfiguration(
244      ManagedObject<? extends BackendVLVIndexCfgClient> impl) {
245    return new BackendVLVIndexCfgClientImpl(impl);
246  }
247
248
249
250  /** {@inheritDoc} */
251  public BackendVLVIndexCfg createServerConfiguration(
252      ServerManagedObject<? extends BackendVLVIndexCfg> impl) {
253    return new BackendVLVIndexCfgServerImpl(impl);
254  }
255
256
257
258  /** {@inheritDoc} */
259  public Class<BackendVLVIndexCfg> getServerConfigurationClass() {
260    return BackendVLVIndexCfg.class;
261  }
262
263
264
265  /**
266   * Get the "base-dn" property definition.
267   * <p>
268   * Specifies the base DN used in the search query that is being
269   * indexed.
270   *
271   * @return Returns the "base-dn" property definition.
272   */
273  public DNPropertyDefinition getBaseDNPropertyDefinition() {
274    return PD_BASE_DN;
275  }
276
277
278
279  /**
280   * Get the "filter" property definition.
281   * <p>
282   * Specifies the LDAP filter used in the query that is being
283   * indexed.
284   *
285   * @return Returns the "filter" property definition.
286   */
287  public StringPropertyDefinition getFilterPropertyDefinition() {
288    return PD_FILTER;
289  }
290
291
292
293  /**
294   * Get the "name" property definition.
295   * <p>
296   * Specifies a unique name for this VLV index.
297   *
298   * @return Returns the "name" property definition.
299   */
300  public StringPropertyDefinition getNamePropertyDefinition() {
301    return PD_NAME;
302  }
303
304
305
306  /**
307   * Get the "scope" property definition.
308   * <p>
309   * Specifies the LDAP scope of the query that is being indexed.
310   *
311   * @return Returns the "scope" property definition.
312   */
313  public EnumPropertyDefinition<Scope> getScopePropertyDefinition() {
314    return PD_SCOPE;
315  }
316
317
318
319  /**
320   * Get the "sort-order" property definition.
321   * <p>
322   * Specifies the names of the attributes that are used to sort the
323   * entries for the query being indexed.
324   * <p>
325   * Multiple attributes can be used to determine the sort order by
326   * listing the attribute names from highest to lowest precedence.
327   * Optionally, + or - can be prefixed to the attribute name to sort
328   * the attribute in ascending order or descending order respectively.
329   *
330   * @return Returns the "sort-order" property definition.
331   */
332  public StringPropertyDefinition getSortOrderPropertyDefinition() {
333    return PD_SORT_ORDER;
334  }
335
336
337
338  /**
339   * Managed object client implementation.
340   */
341  private static class BackendVLVIndexCfgClientImpl implements
342    BackendVLVIndexCfgClient {
343
344    /** Private implementation. */
345    private ManagedObject<? extends BackendVLVIndexCfgClient> impl;
346
347
348
349    /** Private constructor. */
350    private BackendVLVIndexCfgClientImpl(
351        ManagedObject<? extends BackendVLVIndexCfgClient> impl) {
352      this.impl = impl;
353    }
354
355
356
357    /** {@inheritDoc} */
358    public DN getBaseDN() {
359      return impl.getPropertyValue(INSTANCE.getBaseDNPropertyDefinition());
360    }
361
362
363
364    /** {@inheritDoc} */
365    public void setBaseDN(DN value) {
366      impl.setPropertyValue(INSTANCE.getBaseDNPropertyDefinition(), value);
367    }
368
369
370
371    /** {@inheritDoc} */
372    public String getFilter() {
373      return impl.getPropertyValue(INSTANCE.getFilterPropertyDefinition());
374    }
375
376
377
378    /** {@inheritDoc} */
379    public void setFilter(String value) {
380      impl.setPropertyValue(INSTANCE.getFilterPropertyDefinition(), value);
381    }
382
383
384
385    /** {@inheritDoc} */
386    public String getName() {
387      return impl.getPropertyValue(INSTANCE.getNamePropertyDefinition());
388    }
389
390
391
392    /** {@inheritDoc} */
393    public void setName(String value) throws PropertyException {
394      impl.setPropertyValue(INSTANCE.getNamePropertyDefinition(), value);
395    }
396
397
398
399    /** {@inheritDoc} */
400    public Scope getScope() {
401      return impl.getPropertyValue(INSTANCE.getScopePropertyDefinition());
402    }
403
404
405
406    /** {@inheritDoc} */
407    public void setScope(Scope value) {
408      impl.setPropertyValue(INSTANCE.getScopePropertyDefinition(), value);
409    }
410
411
412
413    /** {@inheritDoc} */
414    public String getSortOrder() {
415      return impl.getPropertyValue(INSTANCE.getSortOrderPropertyDefinition());
416    }
417
418
419
420    /** {@inheritDoc} */
421    public void setSortOrder(String value) {
422      impl.setPropertyValue(INSTANCE.getSortOrderPropertyDefinition(), value);
423    }
424
425
426
427    /** {@inheritDoc} */
428    public ManagedObjectDefinition<? extends BackendVLVIndexCfgClient, ? extends BackendVLVIndexCfg> definition() {
429      return INSTANCE;
430    }
431
432
433
434    /** {@inheritDoc} */
435    public PropertyProvider properties() {
436      return impl;
437    }
438
439
440
441    /** {@inheritDoc} */
442    public void commit() throws ManagedObjectAlreadyExistsException,
443        MissingMandatoryPropertiesException, ConcurrentModificationException,
444        OperationRejectedException, LdapException {
445      impl.commit();
446    }
447
448
449
450    /** {@inheritDoc} */
451    public String toString() {
452      return impl.toString();
453    }
454  }
455
456
457
458  /**
459   * Managed object server implementation.
460   */
461  private static class BackendVLVIndexCfgServerImpl implements
462    BackendVLVIndexCfg {
463
464    /** Private implementation. */
465    private ServerManagedObject<? extends BackendVLVIndexCfg> impl;
466
467    /** The value of the "base-dn" property. */
468    private final DN pBaseDN;
469
470    /** The value of the "filter" property. */
471    private final String pFilter;
472
473    /** The value of the "name" property. */
474    private final String pName;
475
476    /** The value of the "scope" property. */
477    private final Scope pScope;
478
479    /** The value of the "sort-order" property. */
480    private final String pSortOrder;
481
482
483
484    /** Private constructor. */
485    private BackendVLVIndexCfgServerImpl(ServerManagedObject<? extends BackendVLVIndexCfg> impl) {
486      this.impl = impl;
487      this.pBaseDN = impl.getPropertyValue(INSTANCE.getBaseDNPropertyDefinition());
488      this.pFilter = impl.getPropertyValue(INSTANCE.getFilterPropertyDefinition());
489      this.pName = impl.getPropertyValue(INSTANCE.getNamePropertyDefinition());
490      this.pScope = impl.getPropertyValue(INSTANCE.getScopePropertyDefinition());
491      this.pSortOrder = impl.getPropertyValue(INSTANCE.getSortOrderPropertyDefinition());
492    }
493
494
495
496    /** {@inheritDoc} */
497    public void addChangeListener(
498        ConfigurationChangeListener<BackendVLVIndexCfg> listener) {
499      impl.registerChangeListener(listener);
500    }
501
502
503
504    /** {@inheritDoc} */
505    public void removeChangeListener(
506        ConfigurationChangeListener<BackendVLVIndexCfg> listener) {
507      impl.deregisterChangeListener(listener);
508    }
509
510
511
512    /** {@inheritDoc} */
513    public DN getBaseDN() {
514      return pBaseDN;
515    }
516
517
518
519    /** {@inheritDoc} */
520    public String getFilter() {
521      return pFilter;
522    }
523
524
525
526    /** {@inheritDoc} */
527    public String getName() {
528      return pName;
529    }
530
531
532
533    /** {@inheritDoc} */
534    public Scope getScope() {
535      return pScope;
536    }
537
538
539
540    /** {@inheritDoc} */
541    public String getSortOrder() {
542      return pSortOrder;
543    }
544
545
546
547    /** {@inheritDoc} */
548    public Class<? extends BackendVLVIndexCfg> configurationClass() {
549      return BackendVLVIndexCfg.class;
550    }
551
552
553
554    /** {@inheritDoc} */
555    public DN dn() {
556      return impl.getDN();
557    }
558
559
560
561    /** {@inheritDoc} */
562    public String toString() {
563      return impl.toString();
564    }
565  }
566}