001/*
002 * Copyright 2010-2019 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2010-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.controls;
022
023
024
025import com.unboundid.util.StaticUtils;
026
027
028
029/**
030 * This enum defines the modes which may be used with the content
031 * synchronization request control.  See the documentation for the
032 * {@link ContentSyncRequestControl} class for more information about using the
033 * content synchronization operation.
034 */
035public enum ContentSyncRequestMode
036{
037  /**
038   * Indicates that the client only wishes to retrieve information about entries
039   * which have changed up to this point.
040   */
041  REFRESH_ONLY(1),
042
043
044
045  /**
046   * Indicates that the client wishes to retrieve information about entries
047   * which have changed up to this point, and also to be notified of any
048   * additional matching changes in the future.
049   */
050  REFRESH_AND_PERSIST(3);
051
052
053
054  // The integer value of this request mode.
055  private final int intValue;
056
057
058
059  /**
060   * Creates a new content synchronization request mode with the specified
061   * integer value.
062   *
063   * @param  intValue  The integer value for this request mode.
064   */
065  ContentSyncRequestMode(final int intValue)
066  {
067    this.intValue = intValue;
068  }
069
070
071
072  /**
073   * Retrieves the integer value for this request mode.
074   *
075   * @return  The integer value for this request mode.
076   */
077  public int intValue()
078  {
079    return intValue;
080  }
081
082
083
084  /**
085   * Retrieves the content synchronization request mode with the specified
086   * integer value.
087   *
088   * @param  intValue  The integer value for which to retrieve the corresponding
089   *                   request mode.
090   *
091   * @return  The content synchronization mode with the specified integer value,
092   *          or {@code null} if the given value does not correspond with any
093   *          defined mode.
094   */
095  public static ContentSyncRequestMode valueOf(final int intValue)
096  {
097    if (intValue == REFRESH_ONLY.intValue())
098    {
099      return REFRESH_ONLY;
100    }
101    else if (intValue == REFRESH_AND_PERSIST.intValue())
102    {
103      return REFRESH_AND_PERSIST;
104    }
105    else
106    {
107      return null;
108    }
109  }
110
111
112
113  /**
114   * Retrieves the content synchronization request mode with the specified name.
115   *
116   * @param  name  The name of the content synchronization request mode to
117   *               retrieve.  It must not be {@code null}.
118   *
119   * @return  The requested content sync request mode, or {@code null} if no
120   *          such mode is defined.
121   */
122  public static ContentSyncRequestMode forName(final String name)
123  {
124    switch (StaticUtils.toLowerCase(name))
125    {
126      case "refreshonly":
127      case "refresh-only":
128      case "refresh_only":
129        return REFRESH_ONLY;
130      case "refreshandpersist":
131      case "refresh-and-persist":
132      case "refresh_and_persist":
133        return REFRESH_AND_PERSIST;
134      default:
135        return null;
136    }
137  }
138}