001/*
002 * Copyright 2010-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2010-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) 2010-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.controls;
037
038
039
040import com.unboundid.util.StaticUtils;
041
042
043
044/**
045 * This enum defines the synchronization states for entries returned with the
046 * content synchronization state control.  See the documentation for the
047 * {@link ContentSyncRequestControl} class for more information about using the
048 * content synchronization operation.
049 */
050public enum ContentSyncInfoType
051{
052  /**
053   * Indicates that the associated content synchronization info response only
054   * provides a new state cookie.
055   */
056  NEW_COOKIE((byte) 0x80),
057
058
059
060  /**
061   * Indicates that the associated content synchronization info response is used
062   * to indicate that a delete phase has ended.
063   */
064  REFRESH_DELETE((byte) 0xA1),
065
066
067
068  /**
069   * Indicates that the associated content synchronization info response is used
070   * to indicate that a present phase has ended.
071   */
072  REFRESH_PRESENT((byte) 0xA2),
073
074
075
076  /**
077   * Indicates that the associated content synchronization info response is used
078   * to provide information about multiple entries which have been deleted or
079   * multiple entries which have remained unchanged.
080   */
081  SYNC_ID_SET((byte) 0xA3);
082
083
084
085  // The BER type used for this sync info type in the value of a content
086  // synchronization info message.
087  private final byte type;
088
089
090
091  /**
092   * Creates a new content synchronization info type value with the specified
093   * BER type.
094   *
095   * @param  type  The BER type used for this sync info type in the value of a
096   *               content synchronization info message.
097   */
098  ContentSyncInfoType(final byte type)
099  {
100    this.type = type;
101  }
102
103
104
105  /**
106   * Retrieves the BER type for this synchronization info type value.
107   *
108   * @return  The BER type for this synchronization info type value.
109   */
110  public byte getType()
111  {
112    return type;
113  }
114
115
116
117  /**
118   * Retrieves the content synchronization info type with the specified BER
119   * type.
120   *
121   * @param  type  The BER type of the content synchronization info type value
122   *               to retrieve.
123   *
124   * @return  The content synchronization info value with the specified BER
125   *          type, or {@code null} if the given value does not correspond with
126   *          any defined type.
127   */
128  public static ContentSyncInfoType valueOf(final byte type)
129  {
130    if (type == NEW_COOKIE.getType())
131    {
132      return NEW_COOKIE;
133    }
134    else if (type == REFRESH_DELETE.getType())
135    {
136      return REFRESH_DELETE;
137    }
138    else if (type == REFRESH_PRESENT.getType())
139    {
140      return REFRESH_PRESENT;
141    }
142    else if (type == SYNC_ID_SET.getType())
143    {
144      return SYNC_ID_SET;
145    }
146    else
147    {
148      return null;
149    }
150  }
151
152
153
154  /**
155   * Retrieves the content synchronization info type with the specified name.
156   *
157   * @param  name  The name of the content synchronization info type to
158   *               retrieve.  It must not be {@code null}.
159   *
160   * @return  The requested content sync info type, or {@code null} if no such
161   *          type is defined.
162   */
163  public static ContentSyncInfoType forName(final String name)
164  {
165    switch (StaticUtils.toLowerCase(name))
166    {
167      case "newcookie":
168      case "new-cookie":
169      case "new_cookie":
170        return NEW_COOKIE;
171      case "refreshdelete":
172      case "refresh-delete":
173      case "refresh_delete":
174        return REFRESH_DELETE;
175      case "refreshpresent":
176      case "refresh-present":
177      case "refresh_present":
178        return REFRESH_PRESENT;
179      case "syncidset":
180      case "sync-id-set":
181      case "sync_id_set":
182        return SYNC_ID_SET;
183      default:
184        return null;
185    }
186  }
187}