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