1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * https://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.extras.controls.ad; 21 22 import java.util.EnumSet; 23 import java.util.Set; 24 25 /** 26 * The flags used in the AdDirSync response. 27 * 28 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 29 */ 30 public enum AdDirSyncResponseFlag 31 { 32 /** The Object Security flag */ 33 LDAP_DIRSYNC_OBJECT_SECURITY( 0x0001, "Object Security" ), 34 35 /** The Ancestors First Order flag */ 36 LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER( 0x0800, "Ancestors First Order" ), 37 38 /** The Public Data Only flag */ 39 LDAP_DIRSYNC_PUBLIC_DATA_ONLY( 0x2000, "Public Data Only" ), 40 41 /** The Incremental Values flag */ 42 LDAP_DIRSYNC_INCREMENTAL_VALUES( 0x80000000, "Incremental Values" ); 43 44 /** The int value */ 45 private int value; 46 47 /** The string description **/ 48 private String description; 49 50 /** 51 * A private constructor that associates a value and description to each flag 52 * 53 * @param value The AdDirSync integer value 54 * @param description The AdDirSync description 55 **/ 56 AdDirSyncResponseFlag( int value, String description ) 57 { 58 this.value = value; 59 this.description = description; 60 } 61 62 63 /** 64 * @return The associated value of a given flag 65 */ 66 public int getValue() 67 { 68 return value; 69 } 70 71 72 /** 73 * @see Object#toString() 74 */ 75 @Override 76 public String toString() 77 { 78 return this.description; 79 } 80 81 82 /** 83 * Get back the combination of flags associated with a given value 84 * @param value The integer value 85 * @return a set of all flags associated with the integer value 86 */ 87 public static Set<AdDirSyncResponseFlag> getFlags( int value ) 88 { 89 EnumSet<AdDirSyncResponseFlag> result = EnumSet.noneOf( AdDirSyncResponseFlag.class ); 90 for ( AdDirSyncResponseFlag flag : EnumSet.allOf( AdDirSyncResponseFlag.class ) ) 91 { 92 if ( ( flag.getValue() & value ) == flag.getValue() ) 93 { 94 result.add( flag ); 95 } 96 } 97 return result; 98 } 99 100 101 /** 102 * Get back the bitmask (as an integer) associated with the given flags 103 * @param flags The AdDirSync flags 104 * @return a bitmask in integer form associated with the set of flags 105 */ 106 public static int getBitmask( Set<AdDirSyncResponseFlag> flags ) 107 { 108 int mask = 0; 109 110 for ( AdDirSyncResponseFlag flag : flags ) 111 { 112 mask += flag.getValue(); 113 } 114 115 return mask; 116 } 117 }