001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.extras.controls.ad; 021 022import java.util.EnumSet; 023import java.util.Set; 024 025/** 026 * The flags used in the AdDirSync response. 027 * 028 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 029 */ 030public enum AdDirSyncFlag 031{ 032 /** The Object Security flag */ 033 LDAP_DIRSYNC_OBJECT_SECURITY( 0x0001, "Object Security" ), 034 035 /** The Ancestors First Order flag */ 036 LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER( 0x0800, "Ancestors First Order" ), 037 038 /** The Public Data Only flag */ 039 LDAP_DIRSYNC_PUBLIC_DATA_ONLY( 0x2000, "Public Data Only" ), 040 041 /** The Incremental Values flag */ 042 LDAP_DIRSYNC_INCREMENTAL_VALUES( 0x80000000, "Incremental Values" ); 043 044 /** The int value */ 045 private int value; 046 047 /** The string description **/ 048 private String description; 049 050 /** A private constructor that associates a value and description to each flag */ 051 AdDirSyncFlag( int value, String description ) 052 { 053 this.value = value; 054 this.description = description; 055 } 056 057 058 /** 059 * @return The associated value of a given flag 060 */ 061 public int getValue() 062 { 063 return value; 064 } 065 066 067 /** 068 * @see Object#toString() 069 */ 070 @Override 071 public String toString() 072 { 073 return this.description; 074 } 075 076 077 /** 078 * Get back the combination of flags associated with a given value 079 * @param value The integer value 080 * @return a set of all flags associated with the integer value 081 */ 082 public static Set<AdDirSyncFlag> getFlags( int value ) 083 { 084 EnumSet<AdDirSyncFlag> result = EnumSet.noneOf( AdDirSyncFlag.class ); 085 for ( AdDirSyncFlag flag : EnumSet.allOf( AdDirSyncFlag.class ) ) 086 { 087 if ( ( flag.getValue() & value ) == flag.getValue() ) 088 { 089 result.add( flag ); 090 } 091 } 092 return result; 093 } 094 095 /** 096 * Get back the bitmask (as an integer) associated with the given flags 097 * @param flags The AdDirSync flags 098 * @return a bitmask in integer form associated with the set of flags 099 */ 100 public static int getBitmask( Set<AdDirSyncFlag> flags ) 101 { 102 int mask = 0; 103 104 for ( AdDirSyncFlag flag : flags ) 105 { 106 mask += flag.getValue(); 107 } 108 109 return mask; 110 } 111}