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.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 a search
045     * result reference returned to a client.
046     */
047    @NotMutable()
048    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
049    public final class SearchReferenceAccessLogMessage
050           extends SearchRequestAccessLogMessage
051    {
052      /**
053       * The serial version UID for this serializable class.
054       */
055      private static final long serialVersionUID = 4413555391780641502L;
056    
057    
058    
059      // The list of response control OIDs for the operation.
060      private final List<String> responseControlOIDs;
061    
062      // The set of referral URLs returned.
063      private final List<String> referralURLs;
064    
065    
066    
067      /**
068       * Creates a new search result reference access log message from the provided
069       * message string.
070       *
071       * @param  s  The string to be parsed as a search result reference access log
072       *            message.
073       *
074       * @throws  LogException  If the provided string cannot be parsed as a valid
075       *                        log message.
076       */
077      public SearchReferenceAccessLogMessage(final String s)
078             throws LogException
079      {
080        this(new LogMessage(s));
081      }
082    
083    
084    
085      /**
086       * Creates a new search result reference access log message from the provided
087       * log message.
088       *
089       * @param  m  The log message to be parsed as a search reference access log
090       *            message.
091       */
092      public SearchReferenceAccessLogMessage(final LogMessage m)
093      {
094        super(m);
095    
096        final String refStr = getNamedValue("referralURLs");
097        if ((refStr == null) || (refStr.length() == 0))
098        {
099          referralURLs = Collections.emptyList();
100        }
101        else
102        {
103          final LinkedList<String> refs = new LinkedList<String>();
104          int startPos = 0;
105          while (true)
106          {
107            final int commaPos = refStr.indexOf(",ldap", startPos);
108            if (commaPos < 0)
109            {
110              refs.add(refStr.substring(startPos));
111              break;
112            }
113            else
114            {
115              refs.add(refStr.substring(startPos, commaPos));
116              startPos = commaPos+1;
117            }
118          }
119          referralURLs = Collections.unmodifiableList(refs);
120        }
121    
122        final String controlStr = getNamedValue("responseControls");
123        if (controlStr == null)
124        {
125          responseControlOIDs = Collections.emptyList();
126        }
127        else
128        {
129          final LinkedList<String> controlList = new LinkedList<String>();
130          final StringTokenizer t = new StringTokenizer(controlStr, ",");
131          while (t.hasMoreTokens())
132          {
133            controlList.add(t.nextToken());
134          }
135          responseControlOIDs = Collections.unmodifiableList(controlList);
136        }
137      }
138    
139    
140    
141      /**
142       * Retrieves the list of referral URLs returned to the client.
143       *
144       * @return  The list of referral URLs returned to the client, or an empty list
145       *          if it is not included in the log message.
146       */
147      public List<String> getReferralURLs()
148      {
149        return referralURLs;
150      }
151    
152    
153    
154      /**
155       * Retrieves the OIDs of any response controls contained in the log message.
156       *
157       * @return  The OIDs of any response controls contained in the log message, or
158       *          an empty list if it is not included in the log message.
159       */
160      public List<String> getResponseControlOIDs()
161      {
162        return responseControlOIDs;
163      }
164    
165    
166    
167      /**
168       * {@inheritDoc}
169       */
170      @Override()
171      public AccessLogMessageType getMessageType()
172      {
173        return AccessLogMessageType.REFERENCE;
174      }
175    }