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