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.config.server; 017 018import java.util.Collection; 019 020import org.forgerock.i18n.LocalizableMessage; 021 022/** 023 * An interface for performing server-side constraint validation. 024 * <p> 025 * Constraints are evaluated immediately before and after write operations are 026 * performed. Server-side constraints are evaluated in two phases: the first 027 * phase determines if the proposed add, delete, or modification is acceptable 028 * according to the constraint. If one or more constraints fails, the write 029 * write operation is refused, and the client will receive an 030 * <code>OperationRejectedException</code> exception. The second phase is 031 * invoked once the add, delete, or modification request has been allowed and 032 * any changes applied. The second phase gives the constraint handler a chance 033 * to register listener call-backs if required. 034 * <p> 035 * A server constraint handler must override at least one of the provided 036 * methods. 037 * 038 * @see org.forgerock.opendj.config.Constraint 039 */ 040public abstract class ServerConstraintHandler { 041 042 /** 043 * Creates a new server constraint handler. 044 */ 045 protected ServerConstraintHandler() { 046 // No implementation required. 047 } 048 049 /** 050 * Determines whether or not the existing managed object can be deleted from 051 * the server's configuration. For example, an implementation might enforce 052 * referential integrity by preventing referenced managed objects from being 053 * deleted. 054 * <p> 055 * If the constraint is not satisfied, the implementation must return 056 * <code>false</code> and add a message describing why the managed object 057 * cannot be deleted. 058 * <p> 059 * The default implementation is to return <code>true</code>. 060 * 061 * @param managedObject 062 * The managed object which is about to be deleted. 063 * @param unacceptableReasons 064 * A list of messages to which error messages should be added. 065 * @return Returns <code>true</code> if this constraint is satisfied, or 066 * <code>false</code> if it is not and the managed object cannot be 067 * deleted. 068 * @throws ConfigException 069 * If an configuration exception prevented this constraint from 070 * being evaluated. 071 */ 072 public boolean isDeleteAllowed(ServerManagedObject<?> managedObject, 073 Collection<LocalizableMessage> unacceptableReasons) throws ConfigException { 074 return true; 075 } 076 077 /** 078 * Determines whether or not the provided managed object can be used by the 079 * server. This method is invoked each time a managed object is decoded by 080 * the administration framework: when an attempt is made to add a new 081 * configuration, modify an existing configuration, or during server 082 * initialization. If the constraint is not satisfied the managed object 083 * will be rejected. 084 * <p> 085 * If the constraint is not satisfied, the implementation must return 086 * <code>false</code> and add a message describing why the managed object is 087 * not usable. 088 * <p> 089 * The default implementation is to return <code>true</code>. 090 * 091 * @param managedObject 092 * The new managed object. 093 * @param unacceptableReasons 094 * A list of messages to which error messages should be added. 095 * @return Returns <code>true</code> if this constraint is satisfied, or 096 * <code>false</code> if it is not and the managed object cannot be 097 * used. 098 * @throws ConfigException 099 * If an configuration exception prevented this constraint from 100 * being evaluated. 101 */ 102 public boolean isUsable(ServerManagedObject<?> managedObject, Collection<LocalizableMessage> unacceptableReasons) 103 throws ConfigException { 104 return true; 105 } 106 107 /** 108 * Performs any post-add processing required by this constraint. This method 109 * is invoked after a new managed object has been accepted for use by the 110 * administration framework. This might occur during initialization or when 111 * a managed object is added at run-time. 112 * <p> 113 * The default implementation is to do nothing. 114 * 115 * @param managedObject 116 * The managed object which has just been added to the server's 117 * configuration. 118 * @throws ConfigException 119 * If the post-add processing fails due to a configuration 120 * exception. 121 */ 122 public void performPostAdd(ServerManagedObject<?> managedObject) throws ConfigException { 123 // Do nothing. 124 } 125 126 /** 127 * Performs any post-delete processing required by this constraint. This 128 * method is invoked after a managed object has been accepted for deletion 129 * from the server's configuration. 130 * <p> 131 * The default implementation is to do nothing. 132 * 133 * @param managedObject 134 * The managed object which was deleted. 135 * @throws ConfigException 136 * If the post-delete processing fails due to a configuration 137 * exception. 138 */ 139 public void performPostDelete(ServerManagedObject<?> managedObject) throws ConfigException { 140 // Do nothing. 141 } 142 143 /** 144 * Performs any post-modify processing required by this constraint. This 145 * method is invoked after changes to an existing managed object have been 146 * accepted. 147 * <p> 148 * The default implementation is to do nothing. 149 * 150 * @param managedObject 151 * The managed object which was modified. 152 * @throws ConfigException 153 * If the post-modify processing fails due to a configuration 154 * exception. 155 */ 156 public void performPostModify(ServerManagedObject<?> managedObject) throws ConfigException { 157 // Do nothing. 158 } 159}