001/* 002 * Copyright 2010-2018 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2015-2018 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.extensions; 022 023 024 025import java.io.Serializable; 026import java.util.Date; 027 028import com.unboundid.asn1.ASN1Element; 029import com.unboundid.asn1.ASN1OctetString; 030import com.unboundid.ldap.sdk.LDAPException; 031import com.unboundid.ldap.sdk.ResultCode; 032import com.unboundid.util.Debug; 033import com.unboundid.util.NotExtensible; 034import com.unboundid.util.StaticUtils; 035import com.unboundid.util.ThreadSafety; 036import com.unboundid.util.ThreadSafetyLevel; 037import com.unboundid.util.Validator; 038 039import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 040 041 042 043/** 044 * This class defines the API that should be implemented by classes which may 045 * represent a way to identify the start of a batch of changes to retrieve using 046 * the {@link GetChangelogBatchExtendedRequest}. 047 * <BR> 048 * <BLOCKQUOTE> 049 * <B>NOTE:</B> This class, and other classes within the 050 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 051 * supported for use against Ping Identity, UnboundID, and 052 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 053 * for proprietary functionality or for external specifications that are not 054 * considered stable or mature enough to be guaranteed to work in an 055 * interoperable way with other types of LDAP servers. 056 * </BLOCKQUOTE> 057 */ 058@NotExtensible() 059@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 060public abstract class ChangelogBatchStartingPoint 061 implements Serializable 062{ 063 /** 064 * The serial version UID for this serializable class. 065 */ 066 private static final long serialVersionUID = -1580168275337643812L; 067 068 069 070 /** 071 * Encodes this starting point value to an ASN.1 element suitable for 072 * inclusion in a changelog batch extended request. 073 * 074 * @return The encoded representation of this starting point value. 075 */ 076 public abstract ASN1Element encode(); 077 078 079 080 /** 081 * Decodes the provided ASN.1 element as a changelog batch starting point. 082 * 083 * @param element The ASN.1 element to be decoded. It must not be 084 * {@code null}. 085 * 086 * @return The decoded changelog batch starting point. 087 * 088 * @throws LDAPException If the provided ASN.1 element cannot be decoded as 089 * a changelog batch starting point. 090 */ 091 public static ChangelogBatchStartingPoint decode(final ASN1Element element) 092 throws LDAPException 093 { 094 Validator.ensureNotNull(element); 095 096 switch (element.getType()) 097 { 098 case ResumeWithTokenStartingPoint.TYPE: 099 return new ResumeWithTokenStartingPoint( 100 ASN1OctetString.decodeAsOctetString(element)); 101 102 case ResumeWithCSNStartingPoint.TYPE: 103 return new ResumeWithCSNStartingPoint( 104 ASN1OctetString.decodeAsOctetString(element).stringValue()); 105 106 case BeginningOfChangelogStartingPoint.TYPE: 107 if (element.getValueLength() != 0) 108 { 109 throw new LDAPException(ResultCode.DECODING_ERROR, 110 ERR_BEGINNING_OF_CHANGELOG_STARTING_POINT_HAS_VALUE.get()); 111 } 112 return new BeginningOfChangelogStartingPoint(); 113 114 case EndOfChangelogStartingPoint.TYPE: 115 if (element.getValueLength() != 0) 116 { 117 throw new LDAPException(ResultCode.DECODING_ERROR, 118 ERR_END_OF_CHANGELOG_STARTING_POINT_HAS_VALUE.get()); 119 } 120 return new EndOfChangelogStartingPoint(); 121 122 case ChangeTimeStartingPoint.TYPE: 123 final Date time; 124 try 125 { 126 time = StaticUtils.decodeGeneralizedTime( 127 ASN1OctetString.decodeAsOctetString(element).stringValue()); 128 } 129 catch (final Exception e) 130 { 131 Debug.debugException(e); 132 throw new LDAPException(ResultCode.DECODING_ERROR, 133 ERR_CHANGE_TIME_STARTING_POINT_MALFORMED_VALUE.get( 134 StaticUtils.getExceptionMessage(e)), e); 135 } 136 return new ChangeTimeStartingPoint(time.getTime()); 137 138 default: 139 throw new LDAPException(ResultCode.DECODING_ERROR, 140 ERR_UNKNOWN_CHANGELOG_BATCH_STARTING_POINT_TYPE.get( 141 StaticUtils.toHex(element.getType()))); 142 } 143 } 144 145 146 147 /** 148 * Retrieves a string representation of this changelog batch starting point. 149 * 150 * @return A string representation of this changelog batch starting point. 151 */ 152 @Override() 153 public final String toString() 154 { 155 final StringBuilder buffer = new StringBuilder(); 156 toString(buffer); 157 return buffer.toString(); 158 } 159 160 161 162 /** 163 * Appends a string representation of this changelog batch starting point to 164 * the provided buffer. 165 * 166 * @param buffer The buffer to which the information should be appended. 167 */ 168 public abstract void toString(StringBuilder buffer); 169}