001/* 002 * Copyright 2010-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2010-2024 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2010-2024 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.controls; 037 038 039 040import com.unboundid.util.NotNull; 041import com.unboundid.util.Nullable; 042import com.unboundid.util.StaticUtils; 043 044 045 046/** 047 * This enum defines the synchronization states for entries returned with the 048 * content synchronization state control. See the documentation for the 049 * {@link ContentSyncRequestControl} class for more information about using the 050 * content synchronization operation. 051 */ 052public enum ContentSyncState 053{ 054 /** 055 * Indicates that the associated entry or reference was already present in 056 * the server when the synchronization was initiated. 057 */ 058 PRESENT(0), 059 060 061 062 /** 063 * Indicates that the associated entry or reference was just created by an 064 * add or modify DN operation. 065 */ 066 ADD(1), 067 068 069 070 /** 071 * Indicates that the associated entry or reference was just updated by a 072 * modify or modify DN operation. 073 */ 074 MODIFY(2), 075 076 077 078 /** 079 * Indicates that the associated entry or reference was just removed by a 080 * delete or modify DN operation. 081 */ 082 DELETE(3); 083 084 085 086 // The integer value of this state. 087 private final int intValue; 088 089 090 091 /** 092 * Creates a new content synchronization state with the specified integer 093 * value. 094 * 095 * @param intValue The integer value for this request mode. 096 */ 097 ContentSyncState(final int intValue) 098 { 099 this.intValue = intValue; 100 } 101 102 103 104 /** 105 * Retrieves the integer value for this synchronization state. 106 * 107 * @return The integer value for this synchronization state. 108 */ 109 public int intValue() 110 { 111 return intValue; 112 } 113 114 115 116 /** 117 * Retrieves the content synchronization state with the specified integer 118 * value. 119 * 120 * @param intValue The integer value for which to retrieve the corresponding 121 * synchronization state. 122 * 123 * @return The content synchronization state with the specified integer 124 * value, or {@code null} if the given value does not correspond with 125 * any defined state. 126 */ 127 @Nullable() 128 public static ContentSyncState valueOf(final int intValue) 129 { 130 if (intValue == PRESENT.intValue()) 131 { 132 return PRESENT; 133 } 134 else if (intValue == ADD.intValue()) 135 { 136 return ADD; 137 } 138 else if (intValue == MODIFY.intValue()) 139 { 140 return MODIFY; 141 } 142 else if (intValue == DELETE.intValue()) 143 { 144 return DELETE; 145 } 146 else 147 { 148 return null; 149 } 150 } 151 152 153 154 /** 155 * Retrieves the content synchronization state with the specified name. 156 * 157 * @param name The name of the content synchronization state to retrieve. 158 * It must not be {@code null}. 159 * 160 * @return The requested content synchronization state, or {@code null} if no 161 * such state is defined. 162 */ 163 @Nullable() 164 public static ContentSyncState forName(@NotNull final String name) 165 { 166 switch (StaticUtils.toLowerCase(name)) 167 { 168 case "present": 169 return PRESENT; 170 case "add": 171 return ADD; 172 case "modify": 173 return MODIFY; 174 case "delete": 175 return DELETE; 176 default: 177 return null; 178 } 179 } 180}