1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.security.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(
39          int modificationOp, String id, String value) {
40  
41          BasicAttribute basicAttribute = new BasicAttribute(id);
42  
43          if (Validator.isNotNull(value)) {
44              basicAttribute.add(value);
45          }
46  
47          ModificationItem item = new ModificationItem(
48              modificationOp, basicAttribute);
49  
50          _items.add(item);
51  
52          return item;
53      }
54  
55      public ModificationItem addItem(String id, String value) {
56          return addItem(DirContext.REPLACE_ATTRIBUTE, id, value);
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  }