001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.types;
028    import org.opends.messages.Message;
029    
030    
031    
032    
033    
034    import java.util.ArrayList;
035    import java.util.Iterator;
036    import java.util.List;
037    
038    
039    
040    
041    /**
042     * This class defines a data structure that can be used to hold
043     * information about the result of processing a configuration change.
044     */
045    @org.opends.server.types.PublicAPI(
046         stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
047         mayInstantiate=true,
048         mayExtend=false,
049         mayInvoke=true)
050    public final class ConfigChangeResult
051    {
052      // A set of messages describing the changes that were made, any
053      // action that may be required, or any problems that were
054      // encountered.
055      private List<Message> messages;
056    
057      // Indicates whether one or more of the changes requires
058      // administrative action in order to take effect.
059      private boolean adminActionRequired;
060    
061      // The result code to return to the client from this configuration
062      // change.
063      private ResultCode resultCode;
064    
065    
066    
067      /**
068       * Creates a new config change result object with the provided
069       * information.
070       *
071       * @param  resultCode           The result code for this config
072       *                              change result.
073       * @param  adminActionRequired  Indicates whether administrative
074       *                              action is required for one or more
075       *                              of the changes to take effect.
076       */
077      public ConfigChangeResult(ResultCode resultCode,
078                                boolean adminActionRequired)
079      {
080        this.resultCode          = resultCode;
081        this.adminActionRequired = adminActionRequired;
082        this.messages            = new ArrayList<Message>();
083      }
084    
085    
086    
087      /**
088       * Creates a new config change result object with the provided
089       * information.
090       *
091       * @param  resultCode           The result code for this config
092       *                              change result.
093       * @param  adminActionRequired  Indicates whether administrative
094       *                              action is required for one or more
095       *                              of the changes to take effect.
096       * @param  messages             A set of messages that provide
097       *                              additional information about the
098       *                              change processing.
099       */
100      public ConfigChangeResult(ResultCode resultCode,
101                                boolean adminActionRequired,
102                                List<Message> messages)
103      {
104        this.resultCode          = resultCode;
105        this.adminActionRequired = adminActionRequired;
106        this.messages            = messages;
107      }
108    
109    
110    
111      /**
112       * Retrieves the result code for this config change result.
113       *
114       * @return  The result code for this config change result.
115       */
116      public ResultCode getResultCode()
117      {
118        return resultCode;
119      }
120    
121    
122    
123      /**
124       * Specifies the result code for this config change result.
125       *
126       * @param  resultCode  The result code for this config change
127       *                     result.
128       */
129      public void setResultCode(ResultCode resultCode)
130      {
131        this.resultCode = resultCode;
132      }
133    
134    
135    
136      /**
137       * Indicates whether administrative action is required before one or
138       * more of the changes will take effect.
139       *
140       * @return  <CODE>true</CODE> if one or more of the configuration
141       *          changes require administrative action to take effect, or
142       *          <CODE>false</CODE> if not.
143       */
144      public boolean adminActionRequired()
145      {
146        return adminActionRequired;
147      }
148    
149    
150    
151      /**
152       * Specifies whether administrative action is required before one or
153       * more of the changes will take effect.
154       *
155       * @param  adminActionRequired  Specifies whether administrative
156       *                              action is required before one or
157       *                              more of the changes will take
158       *                              effect.
159       */
160      public void setAdminActionRequired(boolean adminActionRequired)
161      {
162        this.adminActionRequired = adminActionRequired;
163      }
164    
165    
166    
167      /**
168       * Retrieves the set of messages that provide explanation for the
169       * processing of the configuration changes.  This list may be
170       * modified by the caller.
171       *
172       * @return  The set of messages that provide explanation for the
173       *          processing of the configuration changes.
174       */
175      public List<Message> getMessages()
176      {
177        return messages;
178      }
179    
180    
181    
182      /**
183       * Adds the provided message to the set of messages for this config
184       * change result.
185       *
186       * @param  message  The message to add to the set of messages for
187       *                  this config change result.
188       */
189      public void addMessage(Message message)
190      {
191        messages.add(message);
192      }
193    
194    
195    
196      /**
197       * Retrieves a string representation of this config change result.
198       *
199       * @return  A string representation of this config change result.
200       */
201      public String toString()
202      {
203        StringBuilder buffer = new StringBuilder();
204        toString(buffer);
205        return buffer.toString();
206      }
207    
208    
209    
210      /**
211       * Appends a string representation of this config change result to
212       * the provided buffer.
213       *
214       * @param  buffer  The buffer to which the information should be
215       *                 appended.
216       */
217      public void toString(StringBuilder buffer)
218      {
219        buffer.append("ConfigChangeResult(result=");
220        buffer.append(resultCode.toString());
221        buffer.append(", adminActionRequired=");
222        buffer.append(adminActionRequired);
223        buffer.append(", messages={");
224    
225        if (! messages.isEmpty())
226        {
227          Iterator<Message> iterator = messages.iterator();
228    
229          Message firstMessage = iterator.next();
230          buffer.append(firstMessage);
231    
232          while (iterator.hasNext())
233          {
234            buffer.append(",");
235            buffer.append(iterator.next());
236          }
237        }
238    
239    
240        buffer.append("})");
241      }
242    }
243