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