001/* 002 * Copyright 2020-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2020-2024 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) 2020-2024 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.unboundidds.extensions; 037 038 039 040import java.io.Serializable; 041 042import com.unboundid.asn1.ASN1Element; 043import com.unboundid.ldap.sdk.LDAPException; 044import com.unboundid.ldap.sdk.ResultCode; 045import com.unboundid.util.NotExtensible; 046import com.unboundid.util.NotNull; 047import com.unboundid.util.StaticUtils; 048import com.unboundid.util.ThreadSafety; 049import com.unboundid.util.ThreadSafetyLevel; 050 051import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 052 053 054 055/** 056 * This class defines an API that may be used to indicate how the tool should 057 * determine which log content to include in the support data archive when 058 * processing a {@link CollectSupportDataExtendedRequest}. 059 * <BR> 060 * <BLOCKQUOTE> 061 * <B>NOTE:</B> This class, and other classes within the 062 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 063 * supported for use against Ping Identity, UnboundID, and 064 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 065 * for proprietary functionality or for external specifications that are not 066 * considered stable or mature enough to be guaranteed to work in an 067 * interoperable way with other types of LDAP servers. 068 * </BLOCKQUOTE> 069 * <BR> 070 * Available log capture window implementations include: 071 * <UL> 072 * <LI> 073 * {@link ToolDefaultCollectSupportDataLogCaptureWindow} -- Indicates that 074 * the tool should capture a default amount of log content to include in 075 * the support data archive. 076 * </LI> 077 * <LI> 078 * {@link DurationCollectSupportDataLogCaptureWindow} -- Indicates that the 079 * support data archive should include log messages for a specified duration 080 * leading up to the time that the 081 * {@link CollectSupportDataExtendedRequest} was received by the server. 082 * </LI> 083 * <LI> 084 * {@link TimeWindowCollectSupportDataLogCaptureWindow} -- Indicates that 085 * the support data archive should include log messages that fall between 086 * specified start and end times. 087 * </LI> 088 * <LI> 089 * {@link HeadAndTailSizeCollectSupportDataLogCaptureWindow} -- Indicates 090 * that the support data archive should include a specified amount of data 091 * from the beginning and end of each log file. 092 * </LI> 093 * </UL> 094 * 095 * @see CollectSupportDataExtendedRequest 096 */ 097@NotExtensible() 098@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 099public abstract class CollectSupportDataLogCaptureWindow 100 implements Serializable 101{ 102 /** 103 * The BER type that should be used for tool-default log capture window 104 * objects. 105 */ 106 protected static final byte TYPE_TOOL_DEFAULT = (byte) 0x80; 107 108 109 110 /** 111 * The BER type that should be used for duration log capture window objects. 112 */ 113 protected static final byte TYPE_DURATION = (byte) 0x81; 114 115 116 117 /** 118 * The BER type that should be used for time window log capture window 119 * objects. 120 */ 121 protected static final byte TYPE_TIME_WINDOW = (byte) 0xA2; 122 123 124 125 /** 126 * The BER type that should be used for head and tail size log capture window 127 * objects. 128 */ 129 protected static final byte TYPE_HEAD_AND_TAIL_SIZE = (byte) 0xA3; 130 131 132 133 /** 134 * The serial version UID for this serializable class. 135 */ 136 private static final long serialVersionUID = 6491461694423982840L; 137 138 139 140 /** 141 * Decodes the provided ASN.1 element as a collect support data log capture 142 * window object. 143 * 144 * @param e The ASN.1 element to be decoded as a log capture window object. 145 * It must not be {@code null}. 146 * 147 * @return The collect support data log capture window object that was 148 * decoded from the provided ASN.1 element. 149 * 150 * @throws LDAPException If the provided element cannot be decoded as a 151 * valid collect support data log capture window 152 * object. 153 */ 154 @NotNull() 155 public static CollectSupportDataLogCaptureWindow decode( 156 @NotNull final ASN1Element e) 157 throws LDAPException 158 { 159 switch (e.getType()) 160 { 161 case TYPE_TOOL_DEFAULT: 162 return ToolDefaultCollectSupportDataLogCaptureWindow.decodeInternal(e); 163 case TYPE_DURATION: 164 return DurationCollectSupportDataLogCaptureWindow.decodeInternal(e); 165 case TYPE_TIME_WINDOW: 166 return TimeWindowCollectSupportDataLogCaptureWindow.decodeInternal(e); 167 case TYPE_HEAD_AND_TAIL_SIZE: 168 return HeadAndTailSizeCollectSupportDataLogCaptureWindow.decodeInternal( 169 e); 170 default: 171 throw new LDAPException(ResultCode.DECODING_ERROR, 172 ERR_CSD_LOG_WINDOW_CANNOT_DECODE.get( 173 StaticUtils.toHex(e.getType()))); 174 } 175 } 176 177 178 179 /** 180 * Encodes this collect support data log capture window object to an ASN.1 181 * element. 182 * 183 * @return The ASN.1 element that contains an encoded representation of this 184 * collect support data log capture window object. 185 */ 186 @NotNull() 187 public abstract ASN1Element encode(); 188 189 190 191 /** 192 * Retrieves a string representation of this collect support data log capture 193 * window object. 194 * 195 * @return A string representation of this collect support data log capture 196 * window object. 197 */ 198 @Override() 199 @NotNull() 200 public final String toString() 201 { 202 final StringBuilder buffer = new StringBuilder(); 203 toString(buffer); 204 return buffer.toString(); 205 } 206 207 208 209 /** 210 * Appends a string representation of this collect support data log capture 211 * window object to the provided buffer. 212 * 213 * @param buffer The buffer to which the string representation will be 214 * appended. It must not be {@code null}. 215 */ 216 public abstract void toString(@NotNull final StringBuilder buffer); 217}