1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.ldap;
16  
17  import com.liferay.portal.kernel.util.Validator;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import javax.naming.directory.BasicAttribute;
23  import javax.naming.directory.DirContext;
24  import javax.naming.directory.ModificationItem;
25  
26  /**
27   * <a href="Modifications.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Amos Fong
30   * @author Brian Wing Shun Chan
31   */
32  public class Modifications {
33  
34      public static Modifications getInstance() {
35          return new Modifications();
36      }
37  
38      public ModificationItem addItem(String id, String value) {
39          return addItem(DirContext.REPLACE_ATTRIBUTE, id, value);
40      }
41  
42      public ModificationItem addItem(
43          int modificationOp, String id, String value) {
44  
45          BasicAttribute basicAttribute = new BasicAttribute(id);
46  
47          if (Validator.isNotNull(value)) {
48              basicAttribute.add(value);
49          }
50  
51          ModificationItem item = new ModificationItem(
52              modificationOp, basicAttribute);
53  
54          _items.add(item);
55  
56          return item;
57      }
58  
59      public ModificationItem[] getItems() {
60          return _items.toArray(new ModificationItem[_items.size()]);
61      }
62  
63      private Modifications() {
64      }
65  
66      private List<ModificationItem> _items = new ArrayList<ModificationItem>();
67  
68  }