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