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