001/*
002 * Copyright 2009-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-2024 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-2024 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 java.lang.annotation.ElementType;
041import java.lang.annotation.Documented;
042import java.lang.annotation.Retention;
043import java.lang.annotation.RetentionPolicy;
044import java.lang.annotation.Target;
045
046import com.unboundid.util.NotNull;
047
048
049
050/**
051 * This annotation type may be used to mark methods which may be used to set
052 * values in the associated object using attributes read from an LDAP directory
053 * server.  It should only be used for methods in classes that contain the
054 * {@link LDAPObject} annotation type.  Those methods must not be static and
055 * must take a single argument, which is the value to set from the corresponding
056 * LDAP attribute, but they may have any access modifier (including
057 * {@code public}, {@code protected}, {@code private}, or no access modifier at
058 * all indicating package-level access).  The associated attribute must not be
059 * referenced by any other {@link LDAPField} or {@code LDAPSetter} annotations
060 * in the same class, and it may be referenced by at most one {@link LDAPGetter}
061 * annotation.
062 */
063@Documented()
064@Retention(RetentionPolicy.RUNTIME)
065@Target(value={ElementType.METHOD})
066public @interface LDAPSetter
067{
068  /**
069   * Indicates whether attempts to initialize an object should fail if the LDAP
070   * attribute has a value that cannot be represented in the required argument
071   * type for the associated method.  If this is {@code true}, then an exception
072   * will be thrown in such instances.  If this is {@code false}, then the
073   * associated method will not be invoked, and attempts to modify the
074   * corresponding entry in the directory may cause the existing values to be
075   * lost.
076   *
077   * @return  {@code true} if attempts to initialize an object should fail if
078   *          the LDAP attribute has a value that cannot be represented in the
079   *          required argument type, or {@code false} if not.
080   */
081  boolean failOnInvalidValue() default true;
082
083
084
085  /**
086   * Indicates whether attempts to initialize an object should fail if the
087   * LDAP attribute has multiple values but the argument for the associated
088   * method only accepts a single value.  If this is {@code true}, then an
089   * exception will be thrown in such instances.  If this is {@code false}, then
090   * only the first value returned will be used, and attempts to modify the
091   * corresponding entry in the directory may cause those additional values to
092   * be lost.
093   *
094   * @return  {@code true} if attempts to initialize an object should fail if
095   *          the LDAP attribute has multiple values but the argument for the
096   *          associated method only accepts a single value, or {@code false} if
097   *          not.
098   */
099  boolean failOnTooManyValues() default true;
100
101
102
103  /**
104   * The class that provides the logic for encoding the value of this method to
105   * an LDAP attribute.
106   *
107   * @return  The encoder class for this method.
108   */
109  @NotNull Class<? extends ObjectEncoder> encoderClass()
110       default DefaultObjectEncoder.class;
111
112
113
114  /**
115   * The name of the attribute type in which the value of the associated method
116   * will be stored.  If this is not provided, then the method name must start
117   * with "set" and it will be assumed that the attribute name is the remainder
118   * of the method name.
119   *
120   * @return  The name of the attribute type in which the value of the
121   *          associated method will be stored, or an empty string if the
122   *          attribute name will be assumed to match the method name minus the
123   *          initial "set".
124   */
125  @NotNull String attribute() default "";
126}