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
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.admin.std.meta;
028
029
030
031 import java.util.Collection;
032 import java.util.SortedSet;
033 import org.opends.server.admin.AdministratorAction;
034 import org.opends.server.admin.BooleanPropertyDefinition;
035 import org.opends.server.admin.ClassPropertyDefinition;
036 import org.opends.server.admin.client.AuthorizationException;
037 import org.opends.server.admin.client.CommunicationException;
038 import org.opends.server.admin.client.ConcurrentModificationException;
039 import org.opends.server.admin.client.ManagedObject;
040 import org.opends.server.admin.client.MissingMandatoryPropertiesException;
041 import org.opends.server.admin.client.OperationRejectedException;
042 import org.opends.server.admin.DefaultBehaviorProvider;
043 import org.opends.server.admin.DefinedDefaultBehaviorProvider;
044 import org.opends.server.admin.EnumPropertyDefinition;
045 import org.opends.server.admin.ManagedObjectAlreadyExistsException;
046 import org.opends.server.admin.ManagedObjectDefinition;
047 import org.opends.server.admin.PropertyOption;
048 import org.opends.server.admin.PropertyProvider;
049 import org.opends.server.admin.server.ConfigurationChangeListener;
050 import org.opends.server.admin.server.ServerManagedObject;
051 import org.opends.server.admin.std.client.LastModPluginCfgClient;
052 import org.opends.server.admin.std.meta.PluginCfgDefn.PluginType;
053 import org.opends.server.admin.std.server.LastModPluginCfg;
054 import org.opends.server.admin.std.server.PluginCfg;
055 import org.opends.server.admin.Tag;
056 import org.opends.server.types.DN;
057
058
059
060 /**
061 * An interface for querying the Last Mod Plugin managed object
062 * definition meta information.
063 * <p>
064 * The Last Mod Plugin is used to ensure that the creatorsName and
065 * createTimestamp attributes are included in an entry whenever it is
066 * added to the server and also to ensure that the modifiersName and
067 * modifyTimestamp attributes are updated whenever an entry is modified
068 * or renamed.
069 */
070 public final class LastModPluginCfgDefn extends ManagedObjectDefinition<LastModPluginCfgClient, LastModPluginCfg> {
071
072 // The singleton configuration definition instance.
073 private static final LastModPluginCfgDefn INSTANCE = new LastModPluginCfgDefn();
074
075
076
077 // The "java-class" property definition.
078 private static final ClassPropertyDefinition PD_JAVA_CLASS;
079
080
081
082 // The "plugin-type" property definition.
083 private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE;
084
085
086
087 // Build the "java-class" property definition.
088 static {
089 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
090 builder.setOption(PropertyOption.MANDATORY);
091 builder.setOption(PropertyOption.ADVANCED);
092 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
093 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.LastModPlugin");
094 builder.setDefaultBehaviorProvider(provider);
095 builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin");
096 PD_JAVA_CLASS = builder.getInstance();
097 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
098 }
099
100
101
102 // Build the "plugin-type" property definition.
103 static {
104 EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type");
105 builder.setOption(PropertyOption.MULTI_VALUED);
106 builder.setOption(PropertyOption.MANDATORY);
107 builder.setOption(PropertyOption.ADVANCED);
108 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type"));
109 DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("preoperationadd", "preoperationmodify", "preoperationmodifydn");
110 builder.setDefaultBehaviorProvider(provider);
111 builder.setEnumClass(PluginType.class);
112 PD_PLUGIN_TYPE = builder.getInstance();
113 INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE);
114 }
115
116
117
118 // Register the tags associated with this managed object definition.
119 static {
120 INSTANCE.registerTag(Tag.valueOf("core-server"));
121 }
122
123
124
125 /**
126 * Get the Last Mod Plugin configuration definition singleton.
127 *
128 * @return Returns the Last Mod Plugin configuration definition
129 * singleton.
130 */
131 public static LastModPluginCfgDefn getInstance() {
132 return INSTANCE;
133 }
134
135
136
137 /**
138 * Private constructor.
139 */
140 private LastModPluginCfgDefn() {
141 super("last-mod-plugin", PluginCfgDefn.getInstance());
142 }
143
144
145
146 /**
147 * {@inheritDoc}
148 */
149 public LastModPluginCfgClient createClientConfiguration(
150 ManagedObject<? extends LastModPluginCfgClient> impl) {
151 return new LastModPluginCfgClientImpl(impl);
152 }
153
154
155
156 /**
157 * {@inheritDoc}
158 */
159 public LastModPluginCfg createServerConfiguration(
160 ServerManagedObject<? extends LastModPluginCfg> impl) {
161 return new LastModPluginCfgServerImpl(impl);
162 }
163
164
165
166 /**
167 * {@inheritDoc}
168 */
169 public Class<LastModPluginCfg> getServerConfigurationClass() {
170 return LastModPluginCfg.class;
171 }
172
173
174
175 /**
176 * Get the "enabled" property definition.
177 * <p>
178 * Indicates whether the plug-in is enabled for use.
179 *
180 * @return Returns the "enabled" property definition.
181 */
182 public BooleanPropertyDefinition getEnabledPropertyDefinition() {
183 return PluginCfgDefn.getInstance().getEnabledPropertyDefinition();
184 }
185
186
187
188 /**
189 * Get the "invoke-for-internal-operations" property definition.
190 * <p>
191 * Indicates whether the plug-in should be invoked for internal
192 * operations.
193 * <p>
194 * Any plug-in that can be invoked for internal operations must
195 * ensure that it does not create any new internal operatons that can
196 * cause the same plug-in to be re-invoked.
197 *
198 * @return Returns the "invoke-for-internal-operations" property definition.
199 */
200 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
201 return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition();
202 }
203
204
205
206 /**
207 * Get the "java-class" property definition.
208 * <p>
209 * Specifies the fully-qualified name of the Java class that
210 * provides the plug-in implementation.
211 *
212 * @return Returns the "java-class" property definition.
213 */
214 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
215 return PD_JAVA_CLASS;
216 }
217
218
219
220 /**
221 * Get the "plugin-type" property definition.
222 * <p>
223 * Specifies the set of plug-in types for the plug-in, which
224 * specifies the times at which the plug-in is invoked.
225 *
226 * @return Returns the "plugin-type" property definition.
227 */
228 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
229 return PD_PLUGIN_TYPE;
230 }
231
232
233
234 /**
235 * Managed object client implementation.
236 */
237 private static class LastModPluginCfgClientImpl implements
238 LastModPluginCfgClient {
239
240 // Private implementation.
241 private ManagedObject<? extends LastModPluginCfgClient> impl;
242
243
244
245 // Private constructor.
246 private LastModPluginCfgClientImpl(
247 ManagedObject<? extends LastModPluginCfgClient> impl) {
248 this.impl = impl;
249 }
250
251
252
253 /**
254 * {@inheritDoc}
255 */
256 public Boolean isEnabled() {
257 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
258 }
259
260
261
262 /**
263 * {@inheritDoc}
264 */
265 public void setEnabled(boolean value) {
266 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
267 }
268
269
270
271 /**
272 * {@inheritDoc}
273 */
274 public boolean isInvokeForInternalOperations() {
275 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
276 }
277
278
279
280 /**
281 * {@inheritDoc}
282 */
283 public void setInvokeForInternalOperations(Boolean value) {
284 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
285 }
286
287
288
289 /**
290 * {@inheritDoc}
291 */
292 public String getJavaClass() {
293 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
294 }
295
296
297
298 /**
299 * {@inheritDoc}
300 */
301 public void setJavaClass(String value) {
302 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
303 }
304
305
306
307 /**
308 * {@inheritDoc}
309 */
310 public SortedSet<PluginType> getPluginType() {
311 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
312 }
313
314
315
316 /**
317 * {@inheritDoc}
318 */
319 public void setPluginType(Collection<PluginType> values) {
320 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
321 }
322
323
324
325 /**
326 * {@inheritDoc}
327 */
328 public ManagedObjectDefinition<? extends LastModPluginCfgClient, ? extends LastModPluginCfg> definition() {
329 return INSTANCE;
330 }
331
332
333
334 /**
335 * {@inheritDoc}
336 */
337 public PropertyProvider properties() {
338 return impl;
339 }
340
341
342
343 /**
344 * {@inheritDoc}
345 */
346 public void commit() throws ManagedObjectAlreadyExistsException,
347 MissingMandatoryPropertiesException, ConcurrentModificationException,
348 OperationRejectedException, AuthorizationException,
349 CommunicationException {
350 impl.commit();
351 }
352
353 }
354
355
356
357 /**
358 * Managed object server implementation.
359 */
360 private static class LastModPluginCfgServerImpl implements
361 LastModPluginCfg {
362
363 // Private implementation.
364 private ServerManagedObject<? extends LastModPluginCfg> impl;
365
366 // The value of the "enabled" property.
367 private final boolean pEnabled;
368
369 // The value of the "invoke-for-internal-operations" property.
370 private final boolean pInvokeForInternalOperations;
371
372 // The value of the "java-class" property.
373 private final String pJavaClass;
374
375 // The value of the "plugin-type" property.
376 private final SortedSet<PluginType> pPluginType;
377
378
379
380 // Private constructor.
381 private LastModPluginCfgServerImpl(ServerManagedObject<? extends LastModPluginCfg> impl) {
382 this.impl = impl;
383 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
384 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
385 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
386 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
387 }
388
389
390
391 /**
392 * {@inheritDoc}
393 */
394 public void addLastModChangeListener(
395 ConfigurationChangeListener<LastModPluginCfg> listener) {
396 impl.registerChangeListener(listener);
397 }
398
399
400
401 /**
402 * {@inheritDoc}
403 */
404 public void removeLastModChangeListener(
405 ConfigurationChangeListener<LastModPluginCfg> listener) {
406 impl.deregisterChangeListener(listener);
407 }
408 /**
409 * {@inheritDoc}
410 */
411 public void addChangeListener(
412 ConfigurationChangeListener<PluginCfg> listener) {
413 impl.registerChangeListener(listener);
414 }
415
416
417
418 /**
419 * {@inheritDoc}
420 */
421 public void removeChangeListener(
422 ConfigurationChangeListener<PluginCfg> listener) {
423 impl.deregisterChangeListener(listener);
424 }
425
426
427
428 /**
429 * {@inheritDoc}
430 */
431 public boolean isEnabled() {
432 return pEnabled;
433 }
434
435
436
437 /**
438 * {@inheritDoc}
439 */
440 public boolean isInvokeForInternalOperations() {
441 return pInvokeForInternalOperations;
442 }
443
444
445
446 /**
447 * {@inheritDoc}
448 */
449 public String getJavaClass() {
450 return pJavaClass;
451 }
452
453
454
455 /**
456 * {@inheritDoc}
457 */
458 public SortedSet<PluginType> getPluginType() {
459 return pPluginType;
460 }
461
462
463
464 /**
465 * {@inheritDoc}
466 */
467 public Class<? extends LastModPluginCfg> configurationClass() {
468 return LastModPluginCfg.class;
469 }
470
471
472
473 /**
474 * {@inheritDoc}
475 */
476 public DN dn() {
477 return impl.getDN();
478 }
479
480 }
481 }