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