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