001    /*
002     * Copyright 2009-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.ArrayList;
026    import java.util.Collections;
027    import java.util.LinkedList;
028    import java.util.List;
029    import java.util.StringTokenizer;
030    
031    import com.unboundid.util.NotMutable;
032    import com.unboundid.util.ThreadSafety;
033    import com.unboundid.util.ThreadSafetyLevel;
034    
035    
036    
037    /**
038     * <BLOCKQUOTE>
039     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
040     *   LDAP SDK for Java.  It is not available for use in applications that
041     *   include only the Standard Edition of the LDAP SDK, and is not supported for
042     *   use in conjunction with non-UnboundID products.
043     * </BLOCKQUOTE>
044     * This class provides a data structure that holds information about a log
045     * message that may appear in the Directory Server access log about a search
046     * result entry returned to a client.
047     */
048    @NotMutable()
049    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
050    public final class SearchEntryAccessLogMessage
051           extends SearchRequestAccessLogMessage
052    {
053      /**
054       * The serial version UID for this serializable class.
055       */
056      private static final long serialVersionUID = 6423635071693560277L;
057    
058    
059    
060      // The names of the attributes included in the entry that was returned.
061      private final List<String> attributesReturned;
062    
063      // The list of response control OIDs for the operation.
064      private final List<String> responseControlOIDs;
065    
066      // The DN of the entry returned.
067      private final String dn;
068    
069    
070    
071      /**
072       * Creates a new search result entry access log message from the provided
073       * message string.
074       *
075       * @param  s  The string to be parsed as a search result entry access log
076       *            message.
077       *
078       * @throws  LogException  If the provided string cannot be parsed as a valid
079       *                        log message.
080       */
081      public SearchEntryAccessLogMessage(final String s)
082             throws LogException
083      {
084        this(new LogMessage(s));
085      }
086    
087    
088    
089      /**
090       * Creates a new search result entry access log message from the provided log
091       * message.
092       *
093       * @param  m  The log message to be parsed as a search entry access log
094       *            message.
095       */
096      public SearchEntryAccessLogMessage(final LogMessage m)
097      {
098        super(m);
099    
100        dn = getNamedValue("dn");
101    
102        final String controlStr = getNamedValue("responseControls");
103        if (controlStr == null)
104        {
105          responseControlOIDs = Collections.emptyList();
106        }
107        else
108        {
109          final LinkedList<String> controlList = new LinkedList<String>();
110          final StringTokenizer t = new StringTokenizer(controlStr, ",");
111          while (t.hasMoreTokens())
112          {
113            controlList.add(t.nextToken());
114          }
115          responseControlOIDs = Collections.unmodifiableList(controlList);
116        }
117    
118        final String attrs = getNamedValue("attrsReturned");
119        if (attrs == null)
120        {
121          attributesReturned = null;
122        }
123        else
124        {
125          final ArrayList<String> l = new ArrayList<String>(10);
126          final StringTokenizer tokenizer = new StringTokenizer(attrs, ",");
127          while (tokenizer.hasMoreTokens())
128          {
129            l.add(tokenizer.nextToken());
130          }
131    
132          attributesReturned = Collections.unmodifiableList(l);
133        }
134      }
135    
136    
137    
138      /**
139       * Retrieves the DN of the entry returned to the client.
140       *
141       * @return  The DN of the entry returned to the client, or {@code null} if it
142       *          is not included in the log message.
143       */
144      public String getDN()
145      {
146        return dn;
147      }
148    
149    
150    
151      /**
152       * Retrieves the names of the attributes included in the entry that was
153       * returned.
154       *
155       * @return  The names of the attributes included in the entry that was
156       *          returned, or {@code null} if it is not included in the log
157       *          message.
158       */
159      public List<String> getAttributesReturned()
160      {
161        return attributesReturned;
162      }
163    
164    
165    
166      /**
167       * Retrieves the OIDs of any response controls contained in the log message.
168       *
169       * @return  The OIDs of any response controls contained in the log message, or
170       *          an empty list if it is not included in the log message.
171       */
172      public List<String> getResponseControlOIDs()
173      {
174        return responseControlOIDs;
175      }
176    
177    
178    
179      /**
180       * {@inheritDoc}
181       */
182      @Override()
183      public AccessLogMessageType getMessageType()
184      {
185        return AccessLogMessageType.ENTRY;
186      }
187    }