001/* 002 * Copyright 2009-2023 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2009-2023 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) 2009-2023 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.persist; 037 038 039 040import com.unboundid.util.NotNull; 041import com.unboundid.util.Nullable; 042import com.unboundid.util.StaticUtils; 043 044 045 046/** 047 * This enumeration defines a set of options that indicate how the value of a 048 * field or getter method may be used in the process of constructing a search 049 * filter. The resulting filter will be constructed as a logical AND of 050 * equality components created from the structural object class and any 051 * auxiliary classes, as well as equality components created from the values of 052 * fields with the {@link LDAPField} annotation type and/or the return values of 053 * methods with the {@link LDAPGetter} annotation type. 054 * <BR><BR> 055 * If a class has any fields or getter methods with a filter usage of 056 * {@code REQUIRED}, then all fields and/or getter methods marked as 057 * {@code REQUIRED} must have a non-{@code null} value and will be included in 058 * the filter, and any other fields or getter methods marked as 059 * {@code ALWAYS_ALLOWED} or {@code CONDITIONALLY_ALLOWED} with non-{@code null} 060 * values will be included in the filter as well. 061 * <BR><BR> 062 * If a class does not have any fields or getter methods that are marked 063 * {@code REQUIRED}, then at least one field or getter method marked 064 * {@code ALWAYS_ALLOWED} must have a non-{@code null} value in order to 065 * generate a search filter from that object, and the resulting filter will 066 * contain components for all non-{@code null} fields and/or getter methods 067 * marked {@code ALWAYS_ALLOWED} or {@code CONDITIONALLY_ALLOWED}. If an object 068 * does not have any non-{@code null} fields or getter methods marked 069 * {@code REQUIRED} or {@code ALWAYS_ALLOWED}, then it will not be possible to 070 * generate a search filter from that object. 071 */ 072public enum FilterUsage 073{ 074 /** 075 * Indicates that the associated field or getter method must have a value in 076 * an object in order to be able to generate a search filter from that object. 077 * If an attempt is made to generate a search filter from an object that does 078 * not have a value for the associated field or getter method, then an 079 * exception will be thrown. 080 */ 081 REQUIRED, 082 083 084 085 /** 086 * Indicates that the associated field or getter method may always be included 087 * in a search filter if it has a value, regardless of whether any other 088 * fields or getter methods in the object may have values. If the associated 089 * field or getter method does not have a value, then it will be excluded from 090 * the generated search filter. It is generally recommended that the 091 * corresponding attribute be indexed for equality in the directory server, or 092 * that the server otherwise be configured to perform fast equality searches 093 * for filters containing this attribute. 094 */ 095 ALWAYS_ALLOWED, 096 097 098 099 /** 100 * Indicates that the associated field or getter method may be included in a 101 * generated search filter if it has a non-{@code null} value, and if at least 102 * one field or getter method marked {@code REQUIRED} or 103 * {@code ALWAYS_ALLOWED} has a non-{@code null} value. This usage indicates 104 * that the associated field or getter method may be used to help refine a 105 * search filter, but is not sufficient to be included in a search filter by 106 * itself. 107 */ 108 CONDITIONALLY_ALLOWED, 109 110 111 112 /** 113 * Indicates that the associated field or getter method will never be included 114 * in a search filter generated from an object, regardless of whether it has a 115 * value in that object. 116 */ 117 EXCLUDED; 118 119 120 121 /** 122 * Retrieves the filter usage with the specified name. 123 * 124 * @param name The name of the filter usage to retrieve. It must not be 125 * {@code null}. 126 * 127 * @return The requested filter usage, or {@code null} if no such usage is 128 * defined. 129 */ 130 @Nullable() 131 public static FilterUsage forName(@NotNull final String name) 132 { 133 switch (StaticUtils.toLowerCase(name)) 134 { 135 case "required": 136 return REQUIRED; 137 case "alwaysallowed": 138 case "always-allowed": 139 case "always_allowed": 140 return ALWAYS_ALLOWED; 141 case "conditionallyallowed": 142 case "conditionally-allowed": 143 case "conditionally_allowed": 144 return CONDITIONALLY_ALLOWED; 145 case "excluded": 146 return EXCLUDED; 147 default: 148 return null; 149 } 150 } 151}