001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.expando.util;
016    
017    import com.liferay.portal.service.ServiceContext;
018    import com.liferay.portlet.expando.model.ExpandoBridge;
019    
020    import java.io.Serializable;
021    
022    import java.util.Map;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     * @author Zsigmond Rab
027     */
028    public class ExpandoBridgeUtil {
029    
030            public static void copyExpandoBridgeAttributes(
031                    ExpandoBridge oldExpandoBridge, ExpandoBridge newExpandoBridge) {
032    
033                    newExpandoBridge.setAttributes(
034                            oldExpandoBridge.getAttributes(false), false);
035            }
036    
037            public static void setExpandoBridgeAttributes(
038                    ExpandoBridge oldExpandoBridge, ExpandoBridge newExpandoBridge,
039                    ServiceContext serviceContext) {
040    
041                    Map<String, Serializable> expandoBridgeAttributes =
042                            oldExpandoBridge.getAttributes(false);
043    
044                    Map<String, Serializable> serviceContextAttributes =
045                            serviceContext.getExpandoBridgeAttributes();
046    
047                    for (String key : serviceContextAttributes.keySet()) {
048                            expandoBridgeAttributes.put(key, serviceContextAttributes.get(key));
049                    }
050    
051                    newExpandoBridge.setAttributes(expandoBridgeAttributes, false);
052            }
053    
054    }