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