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 * Portions Copyright 2014 ForgeRock AS 026 */ 027package org.forgerock.opendj.config.client; 028 029import java.util.Collection; 030 031import org.forgerock.i18n.LocalizableMessage; 032import org.forgerock.opendj.config.ManagedObjectPath; 033import org.forgerock.opendj.ldap.LdapException; 034 035/** 036 * An interface for performing client-side constraint validation. 037 * <p> 038 * Constraints are evaluated immediately before the client performs a write 039 * operation. If one or more constraints fails, the write operation is refused 040 * and fails with an {@link OperationRejectedException}. 041 * <p> 042 * A client constraint handler must override at least one of the provided 043 * methods. 044 * 045 * @see org.forgerock.opendj.config.Constraint 046 */ 047public abstract class ClientConstraintHandler { 048 049 /** 050 * Creates a new client constraint handler. 051 */ 052 protected ClientConstraintHandler() { 053 // No implementation required. 054 } 055 056 /** 057 * Determines whether or not the newly created managed object which is about 058 * to be added to the server configuration satisfies this constraint. 059 * <p> 060 * If the constraint is not satisfied, the implementation must return 061 * <code>false</code> and add a message describing why the constraint was 062 * not satisfied. 063 * <p> 064 * The default implementation is to return <code>true</code>. 065 * 066 * @param context 067 * The management context. 068 * @param managedObject 069 * The new managed object. 070 * @param unacceptableReasons 071 * A list of messages to which error messages should be added. 072 * @return Returns <code>true</code> if this constraint is satisfied, or 073 * <code>false</code> if it is not. 074 * @throws LdapException 075 * If an error occurs. 076 */ 077 public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, 078 Collection<LocalizableMessage> unacceptableReasons) throws LdapException { 079 return true; 080 } 081 082 /** 083 * Determines whether or not the changes to an existing managed object which 084 * are about to be committed to the server configuration satisfies this 085 * constraint. 086 * <p> 087 * If the constraint is not satisfied, the implementation must return 088 * <code>false</code> and add a message describing why the constraint was 089 * not satisfied. 090 * <p> 091 * The default implementation is to return <code>true</code>. 092 * 093 * @param context 094 * The management context. 095 * @param managedObject 096 * The modified managed object. 097 * @param unacceptableReasons 098 * A list of messages to which error messages should be added. 099 * @return Returns <code>true</code> if this modify is satisfied, or 100 * <code>false</code> if it is not. 101 * @throws LdapException 102 * If an error occurs. 103 */ 104 public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, 105 Collection<LocalizableMessage> unacceptableReasons) throws LdapException { 106 return true; 107 } 108 109 /** 110 * Determines whether or not the existing managed object which is about to 111 * be deleted from the server configuration satisfies this constraint. 112 * <p> 113 * If the constraint is not satisfied, the implementation must return 114 * <code>false</code> and add a message describing why the constraint was 115 * not satisfied. 116 * <p> 117 * The default implementation is to return <code>true</code>. 118 * 119 * @param context 120 * The management context. 121 * @param path 122 * The path of the managed object which is about to be deleted. 123 * @param unacceptableReasons 124 * A list of messages to which error messages should be added. 125 * @return Returns <code>true</code> if this constraint is satisfied, or 126 * <code>false</code> if it is not. 127 * @throws LdapException 128 * If an error occurs. 129 */ 130 public boolean isDeleteAcceptable(ManagementContext context, ManagedObjectPath<?, ?> path, 131 Collection<LocalizableMessage> unacceptableReasons) throws LdapException { 132 return true; 133 } 134}