001    /**
002     * Copyright (c) 2000-2013 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.portal.lar;
016    
017    import com.liferay.portal.kernel.lar.StagedModelDataHandler;
018    import com.liferay.portal.kernel.lar.StagedModelDataHandlerRegistry;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
022    import com.liferay.portal.kernel.util.ListUtil;
023    
024    import java.util.HashMap;
025    import java.util.List;
026    import java.util.Map;
027    
028    /**
029     * The implementation of the staged model data handler registry framework.
030     *
031     * @author Mate Thurzo
032     * @see    com.liferay.portal.kernel.lar.StagedModelDataHandlerRegistryUtil
033     * @since  6.2
034     */
035    @DoPrivileged
036    public class StagedModelDataHandlerRegistryImpl
037            implements StagedModelDataHandlerRegistry {
038    
039            @Override
040            public StagedModelDataHandler<?> getStagedModelDataHandler(
041                    String className) {
042    
043                    return _stagedModelDataHandlers.get(className);
044            }
045    
046            @Override
047            public List<StagedModelDataHandler<?>> getStagedModelDataHandlers() {
048                    return ListUtil.fromMapValues(_stagedModelDataHandlers);
049            }
050    
051            @Override
052            public void register(StagedModelDataHandler<?> stagedModelDataHandler) {
053                    for (String className : stagedModelDataHandler.getClassNames()) {
054                            if (_stagedModelDataHandlers.containsKey(className)) {
055                                    if (_log.isWarnEnabled()) {
056                                            _log.warn("Duplicate class " + className);
057                                    }
058    
059                                    continue;
060                            }
061    
062                            _stagedModelDataHandlers.put(className, stagedModelDataHandler);
063                    }
064            }
065    
066            @Override
067            public void unregister(StagedModelDataHandler<?> stagedModelDataHandler) {
068                    for (String className : stagedModelDataHandler.getClassNames()) {
069                            _stagedModelDataHandlers.remove(className);
070                    }
071            }
072    
073            private static Log _log = LogFactoryUtil.getLog(
074                    StagedModelDataHandlerRegistryImpl.class);
075    
076            private Map<String, StagedModelDataHandler<?>> _stagedModelDataHandlers =
077                    new HashMap<String, StagedModelDataHandler<?>>();
078    
079    }