001/*
002 * Copyright 2007-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-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) 2007-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;
037
038
039
040import com.unboundid.util.NotNull;
041import com.unboundid.util.Nullable;
042import com.unboundid.util.StaticUtils;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046
047
048/**
049 * This enum defines a set of change types that are associated with operations
050 * that may be processed in an LDAP directory server.  The defined change types
051 * are "add", "delete", "modify", and "modify DN".
052 */
053@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
054public enum ChangeType
055{
056  /**
057   * Indicates that the change type is for an add operation.
058   */
059  ADD("add"),
060
061
062
063  /**
064   * Indicates that the change type is for a delete operation.
065   */
066  DELETE("delete"),
067
068
069
070  /**
071   * Indicates that the change type is for a modify operation.
072   */
073  MODIFY("modify"),
074
075
076
077  /**
078   * Indicates that the change type is for a modify DN operation.
079   */
080  MODIFY_DN("moddn");
081
082
083
084  // The human-readable name for this change type.
085  @NotNull private final String name;
086
087
088
089  /**
090   * Creates a new change type with the specified name.
091   *
092   * @param  name  The human-readable name for this change type.
093   */
094  ChangeType(@NotNull final String name)
095  {
096    this.name = name;
097  }
098
099
100
101  /**
102   * Retrieves the human-readable name for this change type.
103   *
104   * @return  The human-readable name for this change type.
105   */
106  @NotNull()
107  public String getName()
108  {
109    return name;
110  }
111
112
113
114  /**
115   * Retrieves the change type with the specified name.
116   *
117   * @param  name  The name of the change type to retrieve.  It must not be
118   *               {@code null}.
119   *
120   * @return  The requested change type, or {@code null} if no such change type
121   *          is defined.
122   */
123  @Nullable()
124  public static ChangeType forName(@NotNull final String name)
125  {
126    switch (StaticUtils.toLowerCase(name))
127    {
128      case "add":
129        return ADD;
130      case "delete":
131      case "del":
132        return DELETE;
133      case "modify":
134      case "mod":
135        return MODIFY;
136      case "modifydn":
137      case "modify-dn":
138      case "modify_dn":
139      case "moddn":
140      case "mod-dn":
141      case "mod_dn":
142      case "modifyrdn":
143      case "modify-rdn":
144      case "modify_rdn":
145      case "modrdn":
146      case "mod-rdn":
147      case "mod_rdn":
148        return MODIFY_DN;
149      default:
150        return null;
151    }
152  }
153
154
155
156  /**
157   * Retrieves a string representation for this change type.
158   *
159   * @return  A string representation for this change type.
160   */
161  @Override()
162  @NotNull()
163  public String toString()
164  {
165    return name;
166  }
167}