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