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