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