001/*
002 * Copyright 2007-2019 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2008-2019 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk;
022
023
024
025import com.unboundid.util.StaticUtils;
026import com.unboundid.util.ThreadSafety;
027import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031/**
032 * This enum defines a set of change types that are associated with operations
033 * that may be processed in an LDAP directory server.  The defined change types
034 * are "add", "delete", "modify", and "modify DN".
035 */
036@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
037public enum ChangeType
038{
039  /**
040   * Indicates that the change type is for an add operation.
041   */
042  ADD("add"),
043
044
045
046  /**
047   * Indicates that the change type is for a delete operation.
048   */
049  DELETE("delete"),
050
051
052
053  /**
054   * Indicates that the change type is for a modify operation.
055   */
056  MODIFY("modify"),
057
058
059
060  /**
061   * Indicates that the change type is for a modify DN operation.
062   */
063  MODIFY_DN("moddn");
064
065
066
067  // The human-readable name for this change type.
068  private final String name;
069
070
071
072  /**
073   * Creates a new change type with the specified name.
074   *
075   * @param  name  The human-readable name for this change type.
076   */
077  ChangeType(final String name)
078  {
079    this.name = name;
080  }
081
082
083
084  /**
085   * Retrieves the human-readable name for this change type.
086   *
087   * @return  The human-readable name for this change type.
088   */
089  public String getName()
090  {
091    return name;
092  }
093
094
095
096  /**
097   * Retrieves the change type with the specified name.
098   *
099   * @param  name  The name of the change type to retrieve.  It must not be
100   *               {@code null}.
101   *
102   * @return  The requested change type, or {@code null} if no such change type
103   *          is defined.
104   */
105  public static ChangeType forName(final String name)
106  {
107    switch (StaticUtils.toLowerCase(name))
108    {
109      case "add":
110        return ADD;
111      case "delete":
112      case "del":
113        return DELETE;
114      case "modify":
115      case "mod":
116        return MODIFY;
117      case "modifydn":
118      case "modify-dn":
119      case "modify_dn":
120      case "moddn":
121      case "mod-dn":
122      case "mod_dn":
123      case "modifyrdn":
124      case "modify-rdn":
125      case "modify_rdn":
126      case "modrdn":
127      case "mod-rdn":
128      case "mod_rdn":
129        return MODIFY_DN;
130      default:
131        return null;
132    }
133  }
134
135
136
137  /**
138   * Retrieves a string representation for this change type.
139   *
140   * @return  A string representation for this change type.
141   */
142  @Override()
143  public String toString()
144  {
145    return name;
146  }
147}