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.asn1.ASN1OctetString;
026    import com.unboundid.ldap.protocol.ExtendedResponseProtocolOp;
027    import com.unboundid.ldap.sdk.ExtendedRequest;
028    import com.unboundid.ldap.sdk.Entry;
029    import com.unboundid.ldap.sdk.LDAPException;
030    import com.unboundid.ldap.sdk.OperationType;
031    import com.unboundid.ldap.sdk.ResultCode;
032    import com.unboundid.util.NotMutable;
033    import com.unboundid.util.StaticUtils;
034    import com.unboundid.util.ThreadSafety;
035    import com.unboundid.util.ThreadSafetyLevel;
036    
037    import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*;
038    
039    
040    
041    /**
042     * This class represents an entry that holds information about an extended
043     * operation processed by an LDAP server, as per the specification described in
044     * draft-chu-ldap-logschema-00.
045     */
046    @NotMutable()
047    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
048    public final class DraftChuLDAPLogSchema00ExtendedEntry
049           extends DraftChuLDAPLogSchema00Entry
050    {
051      /**
052       * The name of the attribute used to hold the extended request value.
053       */
054      public static final String ATTR_REQUEST_VALUE = "reqData";
055    
056    
057    
058      /**
059       * The serial version UID for this serializable class.
060       */
061      private static final long serialVersionUID = 3767074068423424660L;
062    
063    
064    
065      // The request value, if available.
066      private final ASN1OctetString requestValue;
067    
068      // The request OID.
069      private final String requestOID;
070    
071    
072    
073      /**
074       * Creates a new instance of this extended operation access log entry from the
075       * provided entry.
076       *
077       * @param  entry  The entry used to create this extended operation access log
078       *                entry.
079       *
080       * @throws  LDAPException  If the provided entry cannot be decoded as a valid
081       *                         extended operation access log entry as per the
082       *                         specification contained in
083       *                         draft-chu-ldap-logschema-00.
084       */
085      public DraftChuLDAPLogSchema00ExtendedEntry(final Entry entry)
086             throws LDAPException
087      {
088        super(entry, OperationType.EXTENDED);
089    
090    
091        // The request OID is encoded in the request type.
092        final String requestType = entry.getAttributeValue(ATTR_OPERATION_TYPE);
093        final String lowerRequestType = StaticUtils.toLowerCase(requestType);
094        if (lowerRequestType.startsWith("extended") &&
095            (lowerRequestType.length() > 8))
096        {
097          requestOID = requestType.substring(8);
098        }
099        else
100        {
101          throw new LDAPException(ResultCode.DECODING_ERROR,
102               ERR_LOGSCHEMA_DECODE_EXTENDED_MALFORMED_REQ_TYPE.get(entry.getDN(),
103                    ATTR_OPERATION_TYPE, requestType));
104        }
105    
106    
107        // Get the request value, if present.
108        final byte[] requestValueBytes =
109             entry.getAttributeValueBytes(ATTR_REQUEST_VALUE);
110        if (requestValueBytes == null)
111        {
112          requestValue = null;
113        }
114        else
115        {
116          requestValue = new ASN1OctetString(
117               ExtendedResponseProtocolOp.TYPE_RESPONSE_VALUE, requestValueBytes);
118        }
119      }
120    
121    
122    
123      /**
124       * Retrieves the request OID for the extended request described by this
125       * extended operation access log entry.
126       *
127       * @return  The request OID for the extended request described by this
128       *          extended operation access log entry.
129       */
130      public String getRequestOID()
131      {
132        return requestOID;
133      }
134    
135    
136    
137      /**
138       * Retrieves the request value for the extended request described by this
139       * extended operation access log entry, if any.
140       *
141       * @return  The request value for the extended request described by this
142       *          extended operation access log entry, or {@code null} if no request
143       *          value was included in the access log entry.
144       */
145      public ASN1OctetString getRequestValue()
146      {
147        return requestValue;
148      }
149    
150    
151    
152      /**
153       * Retrieves an {@code ExtendedRequest} created from this extended operation
154       * access log entry.
155       *
156       * @return  The {@code ExtendedRequest} created from this extended operation
157       *          access log entry.
158       */
159      public ExtendedRequest toExtendedRequest()
160      {
161        return new ExtendedRequest(requestOID, requestValue,
162             getRequestControlArray());
163      }
164    }