001    /*
002     * Copyright 2010-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 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.unboundidds.logs;
022    
023    
024    
025    import java.util.Collections;
026    import java.util.LinkedList;
027    import java.util.List;
028    import java.util.StringTokenizer;
029    
030    import com.unboundid.util.NotMutable;
031    import com.unboundid.util.ThreadSafety;
032    import com.unboundid.util.ThreadSafetyLevel;
033    
034    
035    
036    /**
037     * <BLOCKQUOTE>
038     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
039     *   LDAP SDK for Java.  It is not available for use in applications that
040     *   include only the Standard Edition of the LDAP SDK, and is not supported for
041     *   use in conjunction with non-UnboundID products.
042     * </BLOCKQUOTE>
043     * This class provides a data structure that holds information about a log
044     * message that may appear in the Directory Server access log about an
045     * intermediate response returned to a client.
046     */
047    @NotMutable()
048    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
049    public final class IntermediateResponseAccessLogMessage
050           extends OperationRequestAccessLogMessage
051    {
052      /**
053       * The serial version UID for this serializable class.
054       */
055      private static final long serialVersionUID = 4480365381503945078L;
056    
057    
058    
059      // The operation type for this access log message.
060      private final AccessLogOperationType operationType;
061    
062      // The list of response control OIDs for the operation.
063      private final List<String> responseControlOIDs;
064    
065      // A human-readable version of the intermediate response name.
066      private final String name;
067    
068      // The OID of the intermediate response.
069      private final String oid;
070    
071      // A human-readable version of the intermediate response value.
072      private final String value;
073    
074    
075    
076      /**
077       * Creates a new intermediate response access log message from the provided
078       * message string.
079       *
080       * @param  s  The string to be parsed as an intermediate response access log
081       *            message.
082       *
083       * @throws  LogException  If the provided string cannot be parsed as a valid
084       *                        log message.
085       */
086      public IntermediateResponseAccessLogMessage(final String s)
087             throws LogException
088      {
089        this(new LogMessage(s));
090      }
091    
092    
093    
094      /**
095       * Creates a new intermediate response access log message from the provided
096       * log message.
097       *
098       * @param  m  The log message to be parsed as an intermediate response access
099       *            log message.
100       */
101      public IntermediateResponseAccessLogMessage(final LogMessage m)
102      {
103        super(m);
104    
105        oid   = getNamedValue("oid");
106        name  = getNamedValue("name");
107        value = getNamedValue("value");
108    
109        final String controlStr = getNamedValue("responseControls");
110        if (controlStr == null)
111        {
112          responseControlOIDs = Collections.emptyList();
113        }
114        else
115        {
116          final LinkedList<String> controlList = new LinkedList<String>();
117          final StringTokenizer t = new StringTokenizer(controlStr, ",");
118          while (t.hasMoreTokens())
119          {
120            controlList.add(t.nextToken());
121          }
122          responseControlOIDs = Collections.unmodifiableList(controlList);
123        }
124    
125        if (m.hasUnnamedValue(AccessLogOperationType.ADD.getLogIdentifier()))
126        {
127          operationType = AccessLogOperationType.ADD;
128        }
129        else if (m.hasUnnamedValue(AccessLogOperationType.BIND.getLogIdentifier()))
130        {
131          operationType = AccessLogOperationType.BIND;
132        }
133        else if (m.hasUnnamedValue(AccessLogOperationType.
134             COMPARE.getLogIdentifier()))
135        {
136          operationType = AccessLogOperationType.COMPARE;
137        }
138        else if (m.hasUnnamedValue(AccessLogOperationType.
139             DELETE.getLogIdentifier()))
140        {
141          operationType = AccessLogOperationType.DELETE;
142        }
143        else if (m.hasUnnamedValue(AccessLogOperationType.
144             EXTENDED.getLogIdentifier()))
145        {
146          operationType = AccessLogOperationType.EXTENDED;
147        }
148        else if (m.hasUnnamedValue(AccessLogOperationType.
149             MODIFY.getLogIdentifier()))
150        {
151          operationType = AccessLogOperationType.MODIFY;
152        }
153        else if (m.hasUnnamedValue(AccessLogOperationType.MODDN.getLogIdentifier()))
154        {
155          operationType = AccessLogOperationType.MODDN;
156        }
157        else if (m.hasUnnamedValue(
158             AccessLogOperationType.SEARCH.getLogIdentifier()))
159        {
160          operationType = AccessLogOperationType.SEARCH;
161        }
162        else
163        {
164          // This shouldn't happen, but we'll assume it's extended.
165          operationType = AccessLogOperationType.EXTENDED;
166        }
167      }
168    
169    
170    
171      /**
172       * Retrieves the OID of the intermediate response.
173       *
174       * @return  The OID of the intermediate response, or {@code null} if it is
175       *          not included in the log message.
176       */
177      public String getOID()
178      {
179        return oid;
180      }
181    
182    
183    
184      /**
185       * Retrieves a human-readable name for the intermediate response.
186       *
187       * @return  A human-readable name for the intermediate response, or
188       *          {@code null} if it is not included in the log message.
189       */
190      public String getIntermediateResponseName()
191      {
192        return name;
193      }
194    
195    
196    
197      /**
198       * Retrieves a human-readable representation of the intermediate response
199       * value.
200       *
201       * @return  A human-readable representation of the intermediate response
202       *          value, or {@code null} if it is not included in the log message.
203       */
204      public String getValueString()
205      {
206        return value;
207      }
208    
209    
210    
211      /**
212       * Retrieves the OIDs of any response controls contained in the log message.
213       *
214       * @return  The OIDs of any response controls contained in the log message, or
215       *          an empty list if it is not included in the log message.
216       */
217      public List<String> getResponseControlOIDs()
218      {
219        return responseControlOIDs;
220      }
221    
222    
223    
224      /**
225       * {@inheritDoc}
226       */
227      @Override()
228      public AccessLogMessageType getMessageType()
229      {
230        return AccessLogMessageType.INTERMEDIATE_RESPONSE;
231      }
232    
233    
234    
235      /**
236       * {@inheritDoc}
237       */
238      @Override()
239      public AccessLogOperationType getOperationType()
240      {
241        return operationType;
242      }
243    }