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 2008 Sun Microsystems, Inc. 025 * Portions copyright 2013 ForgeRock AS. 026 */ 027package org.forgerock.opendj.server.core; 028 029import java.util.Collections; 030import java.util.EnumSet; 031import java.util.Set; 032 033import org.forgerock.i18n.LocalizableMessage; 034import org.forgerock.util.Reject; 035 036/** 037 * An object that provides information about the source of a data provider 038 * related event. {@code DataProviderEvent} objects are generated when a data 039 * provider experiences an operational error or a state change resulting from 040 * configuration updates or administrative actions. 041 * <p> 042 * TODO: what else should this contain? 043 */ 044public final class DataProviderEvent { 045 046 /** 047 * Indicates the type of event that has occurred in the data provider. 048 */ 049 public static enum Type { 050 /** 051 * The data provider's access mode has changed. 052 */ 053 ACCESS_MODE, 054 055 /** 056 * The data provider's set of base DNs has changed. 057 */ 058 BASE_DNS, 059 060 /** 061 * The data provider's set of supported controls has changed. 062 */ 063 SUPPORTED_CONTROLS, 064 065 /** 066 * The data provider's set of supported features has changed. 067 */ 068 SUPPORTED_FEATURES; 069 } 070 071 /** A message describing this event. */ 072 private final LocalizableMessage reason; 073 074 /** The types of event that have occurred in the data provider. */ 075 private final Set<Type> types; 076 077 /** 078 * Creates a new data provider event. 079 * 080 * @param reason 081 * A message describing this event. 082 * @param types 083 * The types of event that have occurred in the data provider. 084 */ 085 public DataProviderEvent(final LocalizableMessage reason, final Set<Type> types) { 086 Reject.ifNull(reason, types); 087 Reject.ifTrue(types.isEmpty()); 088 089 this.reason = reason; 090 091 final EnumSet<Type> tmp = EnumSet.noneOf(Type.class); 092 tmp.addAll(types); 093 this.types = Collections.unmodifiableSet(tmp); 094 } 095 096 /** 097 * Returns an unmodifiable set containing the types of event that have 098 * occurred in the data provider. 099 * 100 * @return The unmodifiable set containing the types of event that have 101 * occurred in the data provider. 102 */ 103 public Set<Type> getEventTypes() { 104 return types; 105 } 106 107 /** 108 * Returns a message describing this event. 109 * 110 * @return A message describing this event. 111 */ 112 public LocalizableMessage getReason() { 113 return reason; 114 } 115 116 /** 117 * Returns a string describing this event. 118 * 119 * @return A string describing this event. 120 */ 121 @Override 122 public String toString() { 123 return reason.toString(); 124 } 125 126}