001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.security.ldap;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    
019    import java.util.ArrayList;
020    import java.util.List;
021    
022    import javax.naming.directory.BasicAttribute;
023    import javax.naming.directory.DirContext;
024    import javax.naming.directory.ModificationItem;
025    
026    /**
027     * @author Amos Fong
028     * @author Brian Wing Shun Chan
029     */
030    public class Modifications {
031    
032            public static Modifications getInstance() {
033                    return new Modifications();
034            }
035    
036            public ModificationItem addItem(
037                    int modificationOp, String id, String value) {
038    
039                    BasicAttribute basicAttribute = new BasicAttribute(id);
040    
041                    if (Validator.isNotNull(value)) {
042                            basicAttribute.add(value);
043                    }
044    
045                    ModificationItem item = new ModificationItem(
046                            modificationOp, basicAttribute);
047    
048                    _items.add(item);
049    
050                    return item;
051            }
052    
053            public ModificationItem addItem(String id, String value) {
054                    return addItem(DirContext.REPLACE_ATTRIBUTE, id, value);
055            }
056    
057            public ModificationItem[] getItems() {
058                    return _items.toArray(new ModificationItem[_items.size()]);
059            }
060    
061            private Modifications() {
062            }
063    
064            private List<ModificationItem> _items = new ArrayList<ModificationItem>();
065    
066    }