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