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