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 org.forgerock.opendj.config.AdministratorAction; 021import org.forgerock.opendj.config.BooleanPropertyDefinition; 022import org.forgerock.opendj.config.ClassPropertyDefinition; 023import org.forgerock.opendj.config.client.ConcurrentModificationException; 024import org.forgerock.opendj.config.client.ManagedObject; 025import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 026import org.forgerock.opendj.config.client.OperationRejectedException; 027import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 028import org.forgerock.opendj.config.ManagedObjectDefinition; 029import org.forgerock.opendj.config.PropertyOption; 030import org.forgerock.opendj.config.PropertyProvider; 031import org.forgerock.opendj.config.server.ConfigurationChangeListener; 032import org.forgerock.opendj.config.server.ServerManagedObject; 033import org.forgerock.opendj.config.Tag; 034import org.forgerock.opendj.config.TopCfgDefn; 035import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 036import org.forgerock.opendj.ldap.DN; 037import org.forgerock.opendj.ldap.LdapException; 038import org.forgerock.opendj.server.config.client.MatchingRuleCfgClient; 039import org.forgerock.opendj.server.config.server.MatchingRuleCfg; 040 041 042 043/** 044 * An interface for querying the Matching Rule managed object 045 * definition meta information. 046 * <p> 047 * Matching Rules define a set of rules for performing matching 048 * operations against assertion values. 049 */ 050public final class MatchingRuleCfgDefn extends ManagedObjectDefinition<MatchingRuleCfgClient, MatchingRuleCfg> { 051 052 /** The singleton configuration definition instance. */ 053 private static final MatchingRuleCfgDefn INSTANCE = new MatchingRuleCfgDefn(); 054 055 056 057 /** The "enabled" property definition. */ 058 private static final BooleanPropertyDefinition PD_ENABLED; 059 060 061 062 /** The "java-class" property definition. */ 063 private static final ClassPropertyDefinition PD_JAVA_CLASS; 064 065 066 067 /** Build the "enabled" property definition. */ 068 static { 069 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 070 builder.setOption(PropertyOption.MANDATORY); 071 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 072 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 073 PD_ENABLED = builder.getInstance(); 074 INSTANCE.registerPropertyDefinition(PD_ENABLED); 075 } 076 077 078 079 /** Build the "java-class" property definition. */ 080 static { 081 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 082 builder.setOption(PropertyOption.MANDATORY); 083 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 084 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 085 builder.addInstanceOf("org.opends.server.api.MatchingRuleFactory"); 086 PD_JAVA_CLASS = builder.getInstance(); 087 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 088 } 089 090 091 092 // Register the tags associated with this managed object definition. 093 static { 094 INSTANCE.registerTag(Tag.valueOf("core-server")); 095 } 096 097 098 099 /** 100 * Get the Matching Rule configuration definition singleton. 101 * 102 * @return Returns the Matching Rule configuration definition 103 * singleton. 104 */ 105 public static MatchingRuleCfgDefn getInstance() { 106 return INSTANCE; 107 } 108 109 110 111 /** 112 * Private constructor. 113 */ 114 private MatchingRuleCfgDefn() { 115 super("matching-rule", TopCfgDefn.getInstance()); 116 } 117 118 119 120 /** {@inheritDoc} */ 121 public MatchingRuleCfgClient createClientConfiguration( 122 ManagedObject<? extends MatchingRuleCfgClient> impl) { 123 return new MatchingRuleCfgClientImpl(impl); 124 } 125 126 127 128 /** {@inheritDoc} */ 129 public MatchingRuleCfg createServerConfiguration( 130 ServerManagedObject<? extends MatchingRuleCfg> impl) { 131 return new MatchingRuleCfgServerImpl(impl); 132 } 133 134 135 136 /** {@inheritDoc} */ 137 public Class<MatchingRuleCfg> getServerConfigurationClass() { 138 return MatchingRuleCfg.class; 139 } 140 141 142 143 /** 144 * Get the "enabled" property definition. 145 * <p> 146 * Indicates whether the Matching Rule is enabled for use. 147 * 148 * @return Returns the "enabled" property definition. 149 */ 150 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 151 return PD_ENABLED; 152 } 153 154 155 156 /** 157 * Get the "java-class" property definition. 158 * <p> 159 * Specifies the fully-qualified name of the Java class that 160 * provides the Matching Rule implementation. 161 * 162 * @return Returns the "java-class" property definition. 163 */ 164 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 165 return PD_JAVA_CLASS; 166 } 167 168 169 170 /** 171 * Managed object client implementation. 172 */ 173 private static class MatchingRuleCfgClientImpl implements 174 MatchingRuleCfgClient { 175 176 /** Private implementation. */ 177 private ManagedObject<? extends MatchingRuleCfgClient> impl; 178 179 180 181 /** Private constructor. */ 182 private MatchingRuleCfgClientImpl( 183 ManagedObject<? extends MatchingRuleCfgClient> impl) { 184 this.impl = impl; 185 } 186 187 188 189 /** {@inheritDoc} */ 190 public Boolean isEnabled() { 191 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 192 } 193 194 195 196 /** {@inheritDoc} */ 197 public void setEnabled(boolean value) { 198 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 199 } 200 201 202 203 /** {@inheritDoc} */ 204 public String getJavaClass() { 205 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 206 } 207 208 209 210 /** {@inheritDoc} */ 211 public void setJavaClass(String value) { 212 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 213 } 214 215 216 217 /** {@inheritDoc} */ 218 public ManagedObjectDefinition<? extends MatchingRuleCfgClient, ? extends MatchingRuleCfg> definition() { 219 return INSTANCE; 220 } 221 222 223 224 /** {@inheritDoc} */ 225 public PropertyProvider properties() { 226 return impl; 227 } 228 229 230 231 /** {@inheritDoc} */ 232 public void commit() throws ManagedObjectAlreadyExistsException, 233 MissingMandatoryPropertiesException, ConcurrentModificationException, 234 OperationRejectedException, LdapException { 235 impl.commit(); 236 } 237 238 239 240 /** {@inheritDoc} */ 241 public String toString() { 242 return impl.toString(); 243 } 244 } 245 246 247 248 /** 249 * Managed object server implementation. 250 */ 251 private static class MatchingRuleCfgServerImpl implements 252 MatchingRuleCfg { 253 254 /** Private implementation. */ 255 private ServerManagedObject<? extends MatchingRuleCfg> impl; 256 257 /** The value of the "enabled" property. */ 258 private final boolean pEnabled; 259 260 /** The value of the "java-class" property. */ 261 private final String pJavaClass; 262 263 264 265 /** Private constructor. */ 266 private MatchingRuleCfgServerImpl(ServerManagedObject<? extends MatchingRuleCfg> impl) { 267 this.impl = impl; 268 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 269 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 270 } 271 272 273 274 /** {@inheritDoc} */ 275 public void addChangeListener( 276 ConfigurationChangeListener<MatchingRuleCfg> listener) { 277 impl.registerChangeListener(listener); 278 } 279 280 281 282 /** {@inheritDoc} */ 283 public void removeChangeListener( 284 ConfigurationChangeListener<MatchingRuleCfg> listener) { 285 impl.deregisterChangeListener(listener); 286 } 287 288 289 290 /** {@inheritDoc} */ 291 public boolean isEnabled() { 292 return pEnabled; 293 } 294 295 296 297 /** {@inheritDoc} */ 298 public String getJavaClass() { 299 return pJavaClass; 300 } 301 302 303 304 /** {@inheritDoc} */ 305 public Class<? extends MatchingRuleCfg> configurationClass() { 306 return MatchingRuleCfg.class; 307 } 308 309 310 311 /** {@inheritDoc} */ 312 public DN dn() { 313 return impl.getDN(); 314 } 315 316 317 318 /** {@inheritDoc} */ 319 public String toString() { 320 return impl.toString(); 321 } 322 } 323}