001    /*
002     * Copyright 2016 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2016 UnboundID Corp.
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     */
021    package com.unboundid.ldap.sdk.experimental;
022    
023    
024    
025    import com.unboundid.ldap.sdk.Entry;
026    import com.unboundid.ldap.sdk.LDAPException;
027    import com.unboundid.ldap.sdk.OperationType;
028    import com.unboundid.ldap.sdk.ResultCode;
029    import com.unboundid.util.Debug;
030    import com.unboundid.util.NotMutable;
031    import com.unboundid.util.ThreadSafety;
032    import com.unboundid.util.ThreadSafetyLevel;
033    
034    import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*;
035    
036    
037    
038    /**
039     * This class represents an entry that holds information about an abandon
040     * operation processed by an LDAP server, as per the specification described in
041     * draft-chu-ldap-logschema-00.
042     */
043    @NotMutable()
044    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
045    public final class DraftChuLDAPLogSchema00AbandonEntry
046           extends DraftChuLDAPLogSchema00Entry
047    {
048      /**
049       * The name of the attribute used to hold the message ID of the operation to
050       * abandon.
051       */
052      public static final String ATTR_ID_TO_ABANDON = "reqId";
053    
054    
055    
056      /**
057       * The serial version UID for this serializable class.
058       */
059      private static final long serialVersionUID = -5205545654036097510L;
060    
061    
062    
063      // The message ID of the operation to abandon.
064      private final int idToAbandon;
065    
066    
067    
068      /**
069       * Creates a new instance of this abandon access log entry from the provided
070       * entry.
071       *
072       * @param  entry  The entry used to create this abandon access log entry.
073       *
074       * @throws  LDAPException  If the provided entry cannot be decoded as a valid
075       *                         abandon access log entry as per the specification
076       *                         contained in draft-chu-ldap-logschema-00.
077       */
078      public DraftChuLDAPLogSchema00AbandonEntry(final Entry entry)
079             throws LDAPException
080      {
081        super(entry, OperationType.ABANDON);
082    
083        final String idString = entry.getAttributeValue(ATTR_ID_TO_ABANDON);
084        if (idString == null)
085        {
086          throw new LDAPException(ResultCode.DECODING_ERROR,
087               ERR_LOGSCHEMA_DECODE_MISSING_REQUIRED_ATTR.get(entry.getDN(),
088                    ATTR_ID_TO_ABANDON));
089        }
090        else
091        {
092          try
093          {
094            idToAbandon = Integer.parseInt(idString);
095          }
096          catch (final Exception e)
097          {
098            Debug.debugException(e);
099            throw new LDAPException(ResultCode.DECODING_ERROR,
100                 ERR_LOGSCHEMA_DECODE_ABANDON_ID_ERROR.get(entry.getDN(),
101                      ATTR_ID_TO_ABANDON, idString),
102                 e);
103          }
104        }
105      }
106    
107    
108    
109      /**
110       * Retrieves the target message ID (i.e., the message ID of the operation to
111       * abandon) for the abandon request described by this abandon access log
112       * entry.
113       *
114       * @return  The target message ID for the abandon request described by this
115       *          abandon access log entry.
116       */
117      public int getIDToAbandon()
118      {
119        return idToAbandon;
120      }
121    }