001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2010 Sun Microsystems, Inc. 025 * Portions copyright 2013-2015 ForgeRock AS. 026 */ 027package org.forgerock.opendj.ldap.controls; 028 029/** 030 * A persistent search change type as defined in draft-ietf-ldapext-psearch is 031 * used to indicate the type of update operation that caused an entry change 032 * notification to occur. 033 * 034 * @see PersistentSearchRequestControl 035 * @see EntryChangeNotificationResponseControl 036 * @see <a 037 * href="http://tools.ietf.org/html/draft-ietf-ldapext-psearch">draft-ietf-ldapext-psearch 038 * - Persistent Search: A Simple LDAP Change Notification Mechanism </a> 039 */ 040public enum PersistentSearchChangeType { 041 /** 042 * Indicates that an Add operation triggered the entry change notification. 043 */ 044 ADD(1, "add"), 045 046 /** 047 * Indicates that an Delete operation triggered the entry change 048 * notification. 049 */ 050 DELETE(2, "delete"), 051 052 /** 053 * Indicates that an Modify operation triggered the entry change 054 * notification. 055 */ 056 MODIFY(4, "modify"), 057 058 /** 059 * Indicates that an Modify DN operation triggered the entry change 060 * notification. 061 */ 062 MODIFY_DN(8, "modifyDN"); 063 064 private final String name; 065 private final int intValue; 066 067 private PersistentSearchChangeType(final int intValue, final String name) { 068 this.name = name; 069 this.intValue = intValue; 070 } 071 072 /** {@inheritDoc} */ 073 @Override 074 public String toString() { 075 return name; 076 } 077 078 /** 079 * Returns the integer value for this change type as defined in the internet 080 * draft. 081 * 082 * @return The integer value for this change type. 083 */ 084 public int intValue() { 085 return intValue; 086 } 087 088 /** 089 * Returns the enum value that would return the provided argument value from its {@link #intValue} method. 090 * 091 * @param value The value to match. 092 * @return The appropriate enum value. 093 */ 094 public static PersistentSearchChangeType valueOf(int value) { 095 switch (value) { 096 case 1: 097 return ADD; 098 case 2: 099 return DELETE; 100 case 4: 101 return MODIFY; 102 case 8: 103 return MODIFY_DN; 104 default: 105 throw new IllegalArgumentException("Unknown int value: " + value); 106 } 107 } 108}