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