001/*
002 * Copyright 2014-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2014-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) 2014-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.unboundidds.controls;
037
038
039
040import com.unboundid.util.NotNull;
041import com.unboundid.util.Nullable;
042import com.unboundid.util.StaticUtils;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046
047
048/**
049 * This enum defines the set of routing types that may be used in a route to
050 * backend set request control.
051 * <BR>
052 * <BLOCKQUOTE>
053 *   <B>NOTE:</B>  This class, and other classes within the
054 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
055 *   supported for use against Ping Identity, UnboundID, and
056 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
057 *   for proprietary functionality or for external specifications that are not
058 *   considered stable or mature enough to be guaranteed to work in an
059 *   interoperable way with other types of LDAP servers.
060 * </BLOCKQUOTE>
061 */
062@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
063public enum RouteToBackendSetRoutingType
064{
065  /**
066   * The routing type that is used for a control which specifies the absolute
067   * collection of backend sets to which the request should be forwarded.
068   */
069  ABSOLUTE_ROUTING((byte) 0xA0),
070
071
072
073  /**
074   * The routing type that is used for a control which specifies a routing
075   * hint to use as a first guess for processing the request and an optional
076   * collection of fallback sets.
077   */
078  ROUTING_HINT((byte) 0xA1);
079
080
081
082  // The BER type that corresponds to this enum value.
083  private final byte berType;
084
085
086
087  /**
088   * Creates a new route to backend set routing type value with the provided
089   * information.
090   *
091   * @param  berType  The BER type that corresponds to this enum value.
092   */
093  RouteToBackendSetRoutingType(final byte berType)
094  {
095    this.berType = berType;
096  }
097
098
099
100  /**
101   * Retrieves the BER type for this routing type value.
102   *
103   * @return  The BER type for this routing type value.
104   */
105  public byte getBERType()
106  {
107    return berType;
108  }
109
110
111
112  /**
113   * Retrieves the routing type value for the provided BER type.
114   *
115   * @param  berType  The BER type for the routing type value to retrieve.
116   *
117   * @return  The routing type value that corresponds to the provided BER type,
118   *          or {@code null} if there is no corresponding routing type value.
119   */
120  @Nullable()
121  public static RouteToBackendSetRoutingType valueOf(final byte berType)
122  {
123    for (final RouteToBackendSetRoutingType t : values())
124    {
125      if (t.berType == berType)
126      {
127        return t;
128      }
129    }
130
131    return null;
132  }
133
134
135
136  /**
137   * Retrieves the route to backend set routing type with the specified name.
138   *
139   * @param  name  The name of the route to backend set routing type to
140   *               retrieve.  It must not be {@code null}.
141   *
142   * @return  The requested route to backend set routing type, or {@code null}
143   *          if no such type is defined.
144   */
145  @Nullable()
146  public static RouteToBackendSetRoutingType forName(@NotNull final String name)
147  {
148    switch (StaticUtils.toLowerCase(name))
149    {
150      case "absoluterouting":
151      case "absolute-routing":
152      case "absolute_routing":
153        return ABSOLUTE_ROUTING;
154      case "routinghint":
155      case "routing-hint":
156      case "routing_hint":
157        return ROUTING_HINT;
158      default:
159        return null;
160    }
161  }
162}