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 java.util.Collection;
031import java.util.SortedSet;
032import org.forgerock.opendj.config.AdministratorAction;
033import org.forgerock.opendj.config.BooleanPropertyDefinition;
034import org.forgerock.opendj.config.ClassPropertyDefinition;
035import org.forgerock.opendj.config.client.ConcurrentModificationException;
036import org.forgerock.opendj.config.client.ManagedObject;
037import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
038import org.forgerock.opendj.config.client.OperationRejectedException;
039import org.forgerock.opendj.config.DefaultBehaviorProvider;
040import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
041import org.forgerock.opendj.config.EnumPropertyDefinition;
042import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
043import org.forgerock.opendj.config.ManagedObjectDefinition;
044import org.forgerock.opendj.config.PropertyOption;
045import org.forgerock.opendj.config.PropertyProvider;
046import org.forgerock.opendj.config.server.ConfigurationChangeListener;
047import org.forgerock.opendj.config.server.ServerManagedObject;
048import org.forgerock.opendj.config.StringPropertyDefinition;
049import org.forgerock.opendj.config.Tag;
050import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
051import org.forgerock.opendj.ldap.DN;
052import org.forgerock.opendj.ldap.LdapException;
053import org.forgerock.opendj.server.config.client.CollationMatchingRuleCfgClient;
054import org.forgerock.opendj.server.config.server.CollationMatchingRuleCfg;
055import org.forgerock.opendj.server.config.server.MatchingRuleCfg;
056
057
058
059/**
060 * An interface for querying the Collation Matching Rule managed
061 * object definition meta information.
062 * <p>
063 * Collation Matching Rules provide support for locale-specific
064 * filtering and indexing.
065 */
066public final class CollationMatchingRuleCfgDefn extends ManagedObjectDefinition<CollationMatchingRuleCfgClient, CollationMatchingRuleCfg> {
067
068  // The singleton configuration definition instance.
069  private static final CollationMatchingRuleCfgDefn INSTANCE = new CollationMatchingRuleCfgDefn();
070
071
072
073  /**
074   * Defines the set of permissable values for the "matching-rule-type" property.
075   * <p>
076   * the types of matching rules that should be supported for each
077   * locale
078   */
079  public static enum MatchingRuleType {
080
081    /**
082     * Specifies if equality type collation matching rule needs to be
083     * created for each locale.
084     */
085    EQUALITY("equality"),
086
087
088
089    /**
090     * Specifies if greater-than type collation matching rule needs to
091     * be created for each locale.
092     */
093    GREATER_THAN("greater-than"),
094
095
096
097    /**
098     * Specifies if greater-than-or-equal-to type collation matching
099     * rule needs to be created for each locale.
100     */
101    GREATER_THAN_OR_EQUAL_TO("greater-than-or-equal-to"),
102
103
104
105    /**
106     * Specifies if less-than type collation matching rule needs to be
107     * created for each locale.
108     */
109    LESS_THAN("less-than"),
110
111
112
113    /**
114     * Specifies if less-than-or-equal-to type collation matching rule
115     * needs to be created for each locale.
116     */
117    LESS_THAN_OR_EQUAL_TO("less-than-or-equal-to"),
118
119
120
121    /**
122     * Specifies if substring type collation matching rule needs to be
123     * created for each locale.
124     */
125    SUBSTRING("substring");
126
127
128
129    // String representation of the value.
130    private final String name;
131
132
133
134    // Private constructor.
135    private MatchingRuleType(String name) { this.name = name; }
136
137
138
139    /**
140     * {@inheritDoc}
141     */
142    public String toString() { return name; }
143
144  }
145
146
147
148  // The "collation" property definition.
149  private static final StringPropertyDefinition PD_COLLATION;
150
151
152
153  // The "java-class" property definition.
154  private static final ClassPropertyDefinition PD_JAVA_CLASS;
155
156
157
158  // The "matching-rule-type" property definition.
159  private static final EnumPropertyDefinition<MatchingRuleType> PD_MATCHING_RULE_TYPE;
160
161
162
163  // Build the "collation" property definition.
164  static {
165      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "collation");
166      builder.setOption(PropertyOption.MULTI_VALUED);
167      builder.setOption(PropertyOption.MANDATORY);
168      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "collation"));
169      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
170      builder.setPattern("^[a-z-A-Z]+:[0-9.]+\\d$", "LOCALE:OID");
171      PD_COLLATION = builder.getInstance();
172      INSTANCE.registerPropertyDefinition(PD_COLLATION);
173  }
174
175
176
177  // Build the "java-class" property definition.
178  static {
179      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
180      builder.setOption(PropertyOption.MANDATORY);
181      builder.setOption(PropertyOption.ADVANCED);
182      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
183      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.schema.CollationMatchingRuleFactory");
184      builder.setDefaultBehaviorProvider(provider);
185      builder.addInstanceOf("org.opends.server.api.MatchingRuleFactory");
186      PD_JAVA_CLASS = builder.getInstance();
187      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
188  }
189
190
191
192  // Build the "matching-rule-type" property definition.
193  static {
194      EnumPropertyDefinition.Builder<MatchingRuleType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "matching-rule-type");
195      builder.setOption(PropertyOption.MULTI_VALUED);
196      builder.setOption(PropertyOption.MANDATORY);
197      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "matching-rule-type"));
198      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<MatchingRuleType>());
199      builder.setEnumClass(MatchingRuleType.class);
200      PD_MATCHING_RULE_TYPE = builder.getInstance();
201      INSTANCE.registerPropertyDefinition(PD_MATCHING_RULE_TYPE);
202  }
203
204
205
206  // Register the tags associated with this managed object definition.
207  static {
208    INSTANCE.registerTag(Tag.valueOf("core-server"));
209  }
210
211
212
213  /**
214   * Get the Collation Matching Rule configuration definition
215   * singleton.
216   *
217   * @return Returns the Collation Matching Rule configuration
218   *         definition singleton.
219   */
220  public static CollationMatchingRuleCfgDefn getInstance() {
221    return INSTANCE;
222  }
223
224
225
226  /**
227   * Private constructor.
228   */
229  private CollationMatchingRuleCfgDefn() {
230    super("collation-matching-rule", MatchingRuleCfgDefn.getInstance());
231  }
232
233
234
235  /**
236   * {@inheritDoc}
237   */
238  public CollationMatchingRuleCfgClient createClientConfiguration(
239      ManagedObject<? extends CollationMatchingRuleCfgClient> impl) {
240    return new CollationMatchingRuleCfgClientImpl(impl);
241  }
242
243
244
245  /**
246   * {@inheritDoc}
247   */
248  public CollationMatchingRuleCfg createServerConfiguration(
249      ServerManagedObject<? extends CollationMatchingRuleCfg> impl) {
250    return new CollationMatchingRuleCfgServerImpl(impl);
251  }
252
253
254
255  /**
256   * {@inheritDoc}
257   */
258  public Class<CollationMatchingRuleCfg> getServerConfigurationClass() {
259    return CollationMatchingRuleCfg.class;
260  }
261
262
263
264  /**
265   * Get the "collation" property definition.
266   * <p>
267   * the set of supported locales
268   * <p>
269   * Collation must be specified using the syntax: LOCALE:OID
270   *
271   * @return Returns the "collation" property definition.
272   */
273  public StringPropertyDefinition getCollationPropertyDefinition() {
274    return PD_COLLATION;
275  }
276
277
278
279  /**
280   * Get the "enabled" property definition.
281   * <p>
282   * Indicates whether the Collation Matching Rule is enabled for use.
283   *
284   * @return Returns the "enabled" property definition.
285   */
286  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
287    return MatchingRuleCfgDefn.getInstance().getEnabledPropertyDefinition();
288  }
289
290
291
292  /**
293   * Get the "java-class" property definition.
294   * <p>
295   * Specifies the fully-qualified name of the Java class that
296   * provides the Collation Matching Rule implementation.
297   *
298   * @return Returns the "java-class" property definition.
299   */
300  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
301    return PD_JAVA_CLASS;
302  }
303
304
305
306  /**
307   * Get the "matching-rule-type" property definition.
308   * <p>
309   * the types of matching rules that should be supported for each
310   * locale
311   *
312   * @return Returns the "matching-rule-type" property definition.
313   */
314  public EnumPropertyDefinition<MatchingRuleType> getMatchingRuleTypePropertyDefinition() {
315    return PD_MATCHING_RULE_TYPE;
316  }
317
318
319
320  /**
321   * Managed object client implementation.
322   */
323  private static class CollationMatchingRuleCfgClientImpl implements
324    CollationMatchingRuleCfgClient {
325
326    // Private implementation.
327    private ManagedObject<? extends CollationMatchingRuleCfgClient> impl;
328
329
330
331    // Private constructor.
332    private CollationMatchingRuleCfgClientImpl(
333        ManagedObject<? extends CollationMatchingRuleCfgClient> impl) {
334      this.impl = impl;
335    }
336
337
338
339    /**
340     * {@inheritDoc}
341     */
342    public SortedSet<String> getCollation() {
343      return impl.getPropertyValues(INSTANCE.getCollationPropertyDefinition());
344    }
345
346
347
348    /**
349     * {@inheritDoc}
350     */
351    public void setCollation(Collection<String> values) {
352      impl.setPropertyValues(INSTANCE.getCollationPropertyDefinition(), values);
353    }
354
355
356
357    /**
358     * {@inheritDoc}
359     */
360    public Boolean isEnabled() {
361      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
362    }
363
364
365
366    /**
367     * {@inheritDoc}
368     */
369    public void setEnabled(boolean value) {
370      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
371    }
372
373
374
375    /**
376     * {@inheritDoc}
377     */
378    public String getJavaClass() {
379      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
380    }
381
382
383
384    /**
385     * {@inheritDoc}
386     */
387    public void setJavaClass(String value) {
388      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
389    }
390
391
392
393    /**
394     * {@inheritDoc}
395     */
396    public SortedSet<MatchingRuleType> getMatchingRuleType() {
397      return impl.getPropertyValues(INSTANCE.getMatchingRuleTypePropertyDefinition());
398    }
399
400
401
402    /**
403     * {@inheritDoc}
404     */
405    public void setMatchingRuleType(Collection<MatchingRuleType> values) {
406      impl.setPropertyValues(INSTANCE.getMatchingRuleTypePropertyDefinition(), values);
407    }
408
409
410
411    /**
412     * {@inheritDoc}
413     */
414    public ManagedObjectDefinition<? extends CollationMatchingRuleCfgClient, ? extends CollationMatchingRuleCfg> definition() {
415      return INSTANCE;
416    }
417
418
419
420    /**
421     * {@inheritDoc}
422     */
423    public PropertyProvider properties() {
424      return impl;
425    }
426
427
428
429    /**
430     * {@inheritDoc}
431     */
432    public void commit() throws ManagedObjectAlreadyExistsException,
433        MissingMandatoryPropertiesException, ConcurrentModificationException,
434        OperationRejectedException, LdapException {
435      impl.commit();
436    }
437
438  }
439
440
441
442  /**
443   * Managed object server implementation.
444   */
445  private static class CollationMatchingRuleCfgServerImpl implements
446    CollationMatchingRuleCfg {
447
448    // Private implementation.
449    private ServerManagedObject<? extends CollationMatchingRuleCfg> impl;
450
451    // The value of the "collation" property.
452    private final SortedSet<String> pCollation;
453
454    // The value of the "enabled" property.
455    private final boolean pEnabled;
456
457    // The value of the "java-class" property.
458    private final String pJavaClass;
459
460    // The value of the "matching-rule-type" property.
461    private final SortedSet<MatchingRuleType> pMatchingRuleType;
462
463
464
465    // Private constructor.
466    private CollationMatchingRuleCfgServerImpl(ServerManagedObject<? extends CollationMatchingRuleCfg> impl) {
467      this.impl = impl;
468      this.pCollation = impl.getPropertyValues(INSTANCE.getCollationPropertyDefinition());
469      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
470      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
471      this.pMatchingRuleType = impl.getPropertyValues(INSTANCE.getMatchingRuleTypePropertyDefinition());
472    }
473
474
475
476    /**
477     * {@inheritDoc}
478     */
479    public void addCollationChangeListener(
480        ConfigurationChangeListener<CollationMatchingRuleCfg> listener) {
481      impl.registerChangeListener(listener);
482    }
483
484
485
486    /**
487     * {@inheritDoc}
488     */
489    public void removeCollationChangeListener(
490        ConfigurationChangeListener<CollationMatchingRuleCfg> listener) {
491      impl.deregisterChangeListener(listener);
492    }
493    /**
494     * {@inheritDoc}
495     */
496    public void addChangeListener(
497        ConfigurationChangeListener<MatchingRuleCfg> listener) {
498      impl.registerChangeListener(listener);
499    }
500
501
502
503    /**
504     * {@inheritDoc}
505     */
506    public void removeChangeListener(
507        ConfigurationChangeListener<MatchingRuleCfg> listener) {
508      impl.deregisterChangeListener(listener);
509    }
510
511
512
513    /**
514     * {@inheritDoc}
515     */
516    public SortedSet<String> getCollation() {
517      return pCollation;
518    }
519
520
521
522    /**
523     * {@inheritDoc}
524     */
525    public boolean isEnabled() {
526      return pEnabled;
527    }
528
529
530
531    /**
532     * {@inheritDoc}
533     */
534    public String getJavaClass() {
535      return pJavaClass;
536    }
537
538
539
540    /**
541     * {@inheritDoc}
542     */
543    public SortedSet<MatchingRuleType> getMatchingRuleType() {
544      return pMatchingRuleType;
545    }
546
547
548
549    /**
550     * {@inheritDoc}
551     */
552    public Class<? extends CollationMatchingRuleCfg> configurationClass() {
553      return CollationMatchingRuleCfg.class;
554    }
555
556
557
558    /**
559     * {@inheritDoc}
560     */
561    public DN dn() {
562      return impl.getDN();
563    }
564
565  }
566}