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 /** {@inheritDoc} */ 140 public String toString() { return name; } 141 142 } 143 144 145 146 /** The "collation" property definition. */ 147 private static final StringPropertyDefinition PD_COLLATION; 148 149 150 151 /** The "java-class" property definition. */ 152 private static final ClassPropertyDefinition PD_JAVA_CLASS; 153 154 155 156 /** The "matching-rule-type" property definition. */ 157 private static final EnumPropertyDefinition<MatchingRuleType> PD_MATCHING_RULE_TYPE; 158 159 160 161 /** Build the "collation" property definition. */ 162 static { 163 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "collation"); 164 builder.setOption(PropertyOption.MULTI_VALUED); 165 builder.setOption(PropertyOption.MANDATORY); 166 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "collation")); 167 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 168 builder.setPattern("^[a-z-A-Z]+:[0-9.]+\\d$", "LOCALE:OID"); 169 PD_COLLATION = builder.getInstance(); 170 INSTANCE.registerPropertyDefinition(PD_COLLATION); 171 } 172 173 174 175 /** Build the "java-class" property definition. */ 176 static { 177 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 178 builder.setOption(PropertyOption.MANDATORY); 179 builder.setOption(PropertyOption.ADVANCED); 180 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 181 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.schema.CollationMatchingRuleFactory"); 182 builder.setDefaultBehaviorProvider(provider); 183 builder.addInstanceOf("org.opends.server.api.MatchingRuleFactory"); 184 PD_JAVA_CLASS = builder.getInstance(); 185 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 186 } 187 188 189 190 /** Build the "matching-rule-type" property definition. */ 191 static { 192 EnumPropertyDefinition.Builder<MatchingRuleType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "matching-rule-type"); 193 builder.setOption(PropertyOption.MULTI_VALUED); 194 builder.setOption(PropertyOption.MANDATORY); 195 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "matching-rule-type")); 196 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<MatchingRuleType>()); 197 builder.setEnumClass(MatchingRuleType.class); 198 PD_MATCHING_RULE_TYPE = builder.getInstance(); 199 INSTANCE.registerPropertyDefinition(PD_MATCHING_RULE_TYPE); 200 } 201 202 203 204 // Register the tags associated with this managed object definition. 205 static { 206 INSTANCE.registerTag(Tag.valueOf("core-server")); 207 } 208 209 210 211 /** 212 * Get the Collation Matching Rule configuration definition 213 * singleton. 214 * 215 * @return Returns the Collation Matching Rule configuration 216 * definition singleton. 217 */ 218 public static CollationMatchingRuleCfgDefn getInstance() { 219 return INSTANCE; 220 } 221 222 223 224 /** 225 * Private constructor. 226 */ 227 private CollationMatchingRuleCfgDefn() { 228 super("collation-matching-rule", MatchingRuleCfgDefn.getInstance()); 229 } 230 231 232 233 /** {@inheritDoc} */ 234 public CollationMatchingRuleCfgClient createClientConfiguration( 235 ManagedObject<? extends CollationMatchingRuleCfgClient> impl) { 236 return new CollationMatchingRuleCfgClientImpl(impl); 237 } 238 239 240 241 /** {@inheritDoc} */ 242 public CollationMatchingRuleCfg createServerConfiguration( 243 ServerManagedObject<? extends CollationMatchingRuleCfg> impl) { 244 return new CollationMatchingRuleCfgServerImpl(impl); 245 } 246 247 248 249 /** {@inheritDoc} */ 250 public Class<CollationMatchingRuleCfg> getServerConfigurationClass() { 251 return CollationMatchingRuleCfg.class; 252 } 253 254 255 256 /** 257 * Get the "collation" property definition. 258 * <p> 259 * the set of supported locales 260 * <p> 261 * Collation must be specified using the syntax: LOCALE:OID 262 * 263 * @return Returns the "collation" property definition. 264 */ 265 public StringPropertyDefinition getCollationPropertyDefinition() { 266 return PD_COLLATION; 267 } 268 269 270 271 /** 272 * Get the "enabled" property definition. 273 * <p> 274 * Indicates whether the Collation Matching Rule is enabled for use. 275 * 276 * @return Returns the "enabled" property definition. 277 */ 278 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 279 return MatchingRuleCfgDefn.getInstance().getEnabledPropertyDefinition(); 280 } 281 282 283 284 /** 285 * Get the "java-class" property definition. 286 * <p> 287 * Specifies the fully-qualified name of the Java class that 288 * provides the Collation Matching Rule implementation. 289 * 290 * @return Returns the "java-class" property definition. 291 */ 292 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 293 return PD_JAVA_CLASS; 294 } 295 296 297 298 /** 299 * Get the "matching-rule-type" property definition. 300 * <p> 301 * the types of matching rules that should be supported for each 302 * locale 303 * 304 * @return Returns the "matching-rule-type" property definition. 305 */ 306 public EnumPropertyDefinition<MatchingRuleType> getMatchingRuleTypePropertyDefinition() { 307 return PD_MATCHING_RULE_TYPE; 308 } 309 310 311 312 /** 313 * Managed object client implementation. 314 */ 315 private static class CollationMatchingRuleCfgClientImpl implements 316 CollationMatchingRuleCfgClient { 317 318 /** Private implementation. */ 319 private ManagedObject<? extends CollationMatchingRuleCfgClient> impl; 320 321 322 323 /** Private constructor. */ 324 private CollationMatchingRuleCfgClientImpl( 325 ManagedObject<? extends CollationMatchingRuleCfgClient> impl) { 326 this.impl = impl; 327 } 328 329 330 331 /** {@inheritDoc} */ 332 public SortedSet<String> getCollation() { 333 return impl.getPropertyValues(INSTANCE.getCollationPropertyDefinition()); 334 } 335 336 337 338 /** {@inheritDoc} */ 339 public void setCollation(Collection<String> values) { 340 impl.setPropertyValues(INSTANCE.getCollationPropertyDefinition(), values); 341 } 342 343 344 345 /** {@inheritDoc} */ 346 public Boolean isEnabled() { 347 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 348 } 349 350 351 352 /** {@inheritDoc} */ 353 public void setEnabled(boolean value) { 354 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 355 } 356 357 358 359 /** {@inheritDoc} */ 360 public String getJavaClass() { 361 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 362 } 363 364 365 366 /** {@inheritDoc} */ 367 public void setJavaClass(String value) { 368 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 369 } 370 371 372 373 /** {@inheritDoc} */ 374 public SortedSet<MatchingRuleType> getMatchingRuleType() { 375 return impl.getPropertyValues(INSTANCE.getMatchingRuleTypePropertyDefinition()); 376 } 377 378 379 380 /** {@inheritDoc} */ 381 public void setMatchingRuleType(Collection<MatchingRuleType> values) { 382 impl.setPropertyValues(INSTANCE.getMatchingRuleTypePropertyDefinition(), values); 383 } 384 385 386 387 /** {@inheritDoc} */ 388 public ManagedObjectDefinition<? extends CollationMatchingRuleCfgClient, ? extends CollationMatchingRuleCfg> definition() { 389 return INSTANCE; 390 } 391 392 393 394 /** {@inheritDoc} */ 395 public PropertyProvider properties() { 396 return impl; 397 } 398 399 400 401 /** {@inheritDoc} */ 402 public void commit() throws ManagedObjectAlreadyExistsException, 403 MissingMandatoryPropertiesException, ConcurrentModificationException, 404 OperationRejectedException, LdapException { 405 impl.commit(); 406 } 407 408 409 410 /** {@inheritDoc} */ 411 public String toString() { 412 return impl.toString(); 413 } 414 } 415 416 417 418 /** 419 * Managed object server implementation. 420 */ 421 private static class CollationMatchingRuleCfgServerImpl implements 422 CollationMatchingRuleCfg { 423 424 /** Private implementation. */ 425 private ServerManagedObject<? extends CollationMatchingRuleCfg> impl; 426 427 /** The value of the "collation" property. */ 428 private final SortedSet<String> pCollation; 429 430 /** The value of the "enabled" property. */ 431 private final boolean pEnabled; 432 433 /** The value of the "java-class" property. */ 434 private final String pJavaClass; 435 436 /** The value of the "matching-rule-type" property. */ 437 private final SortedSet<MatchingRuleType> pMatchingRuleType; 438 439 440 441 /** Private constructor. */ 442 private CollationMatchingRuleCfgServerImpl(ServerManagedObject<? extends CollationMatchingRuleCfg> impl) { 443 this.impl = impl; 444 this.pCollation = impl.getPropertyValues(INSTANCE.getCollationPropertyDefinition()); 445 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 446 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 447 this.pMatchingRuleType = impl.getPropertyValues(INSTANCE.getMatchingRuleTypePropertyDefinition()); 448 } 449 450 451 452 /** {@inheritDoc} */ 453 public void addCollationChangeListener( 454 ConfigurationChangeListener<CollationMatchingRuleCfg> listener) { 455 impl.registerChangeListener(listener); 456 } 457 458 459 460 /** {@inheritDoc} */ 461 public void removeCollationChangeListener( 462 ConfigurationChangeListener<CollationMatchingRuleCfg> listener) { 463 impl.deregisterChangeListener(listener); 464 } 465 /** {@inheritDoc} */ 466 public void addChangeListener( 467 ConfigurationChangeListener<MatchingRuleCfg> listener) { 468 impl.registerChangeListener(listener); 469 } 470 471 472 473 /** {@inheritDoc} */ 474 public void removeChangeListener( 475 ConfigurationChangeListener<MatchingRuleCfg> listener) { 476 impl.deregisterChangeListener(listener); 477 } 478 479 480 481 /** {@inheritDoc} */ 482 public SortedSet<String> getCollation() { 483 return pCollation; 484 } 485 486 487 488 /** {@inheritDoc} */ 489 public boolean isEnabled() { 490 return pEnabled; 491 } 492 493 494 495 /** {@inheritDoc} */ 496 public String getJavaClass() { 497 return pJavaClass; 498 } 499 500 501 502 /** {@inheritDoc} */ 503 public SortedSet<MatchingRuleType> getMatchingRuleType() { 504 return pMatchingRuleType; 505 } 506 507 508 509 /** {@inheritDoc} */ 510 public Class<? extends CollationMatchingRuleCfg> configurationClass() { 511 return CollationMatchingRuleCfg.class; 512 } 513 514 515 516 /** {@inheritDoc} */ 517 public DN dn() { 518 return impl.getDN(); 519 } 520 521 522 523 /** {@inheritDoc} */ 524 public String toString() { 525 return impl.toString(); 526 } 527 } 528}