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.List;
028    import java.util.StringTokenizer;
029    
030    import com.unboundid.util.NotExtensible;
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 an add
046     * request received from a client.
047     */
048    @NotExtensible()
049    @NotMutable()
050    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
051    public class AddRequestAccessLogMessage
052           extends OperationRequestAccessLogMessage
053    {
054      /**
055       * The serial version UID for this serializable class.
056       */
057      private static final long serialVersionUID = -1234543653722421757L;
058    
059    
060    
061      // The list of attributes included in the entry.
062      private final List<String> attributeNames;
063    
064      // The DN of the entry to add.
065      private final String dn;
066    
067    
068    
069      /**
070       * Creates a new add request access log message from the provided message
071       * string.
072       *
073       * @param  s  The string to be parsed as an add request access log message.
074       *
075       * @throws  LogException  If the provided string cannot be parsed as a valid
076       *                        log message.
077       */
078      public AddRequestAccessLogMessage(final String s)
079             throws LogException
080      {
081        this(new LogMessage(s));
082      }
083    
084    
085    
086      /**
087       * Creates a new add request access log message from the provided message
088       * string.
089       *
090       * @param  m  The log message to be parsed as an add request access log
091       *            message.
092       */
093      public AddRequestAccessLogMessage(final LogMessage m)
094      {
095        super(m);
096    
097        dn = getNamedValue("dn");
098    
099        final String attrs = getNamedValue("attrs");
100        if (attrs == null)
101        {
102          attributeNames = null;
103        }
104        else
105        {
106          final ArrayList<String> l = new ArrayList<String>(10);
107          final StringTokenizer tokenizer = new StringTokenizer(attrs, ",");
108          while (tokenizer.hasMoreTokens())
109          {
110            l.add(tokenizer.nextToken());
111          }
112    
113          attributeNames = Collections.unmodifiableList(l);
114        }
115      }
116    
117    
118    
119      /**
120       * Retrieves the DN of the entry to add.
121       *
122       * @return  The DN of the entry to add, or {@code null} if it is not included
123       *          in the log message.
124       */
125      public final String getDN()
126      {
127        return dn;
128      }
129    
130    
131    
132      /**
133       * Retrieves the names of the attributes included in the add request.
134       *
135       * @return  The names of the attributes included in the add request, or
136       *          {@code null} if that is not included in the log message.
137       */
138      public final List<String> getAttributeNames()
139      {
140        return attributeNames;
141      }
142    
143    
144    
145      /**
146       * {@inheritDoc}
147       */
148      @Override()
149      public final AccessLogOperationType getOperationType()
150      {
151        return AccessLogOperationType.ADD;
152      }
153    }