001    /**
002     * Copyright (c) 2000-2012 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.kernel.lar;
016    
017    import com.liferay.portal.kernel.xml.Element;
018    import com.liferay.portal.model.StagedModel;
019    
020    /**
021     * @author Mate Thurzo
022     * @author Daniel Kocsis
023     */
024    public abstract class BaseStagedModelDataHandler<T extends StagedModel>
025            implements StagedModelDataHandler<T> {
026    
027            public void exportStagedModel(
028                            PortletDataContext portletDataContext, Element element,
029                            T stagedModel)
030                    throws PortletDataException {
031    
032                    exportStagedModel(
033                            portletDataContext, new Element[] {element}, stagedModel);
034            }
035    
036            public void exportStagedModel(
037                            PortletDataContext portletDataContext, Element[] elements,
038                            T stagedModel)
039                    throws PortletDataException {
040    
041                    String path = StagedModelPathUtil.getPath(stagedModel);
042    
043                    if (portletDataContext.isPathProcessed(path)) {
044                            return;
045                    }
046    
047                    try {
048                            doExportStagedModel(
049                                    portletDataContext, elements, (T)stagedModel.clone());
050                    }
051                    catch (Exception e) {
052                            throw new PortletDataException(e);
053                    }
054            }
055    
056            public abstract String getClassName();
057    
058            public void importStagedModel(
059                            PortletDataContext portletDataContext, Element element, String path,
060                            T stagedModel)
061                    throws PortletDataException {
062    
063                    if (portletDataContext.isPathProcessed(path)) {
064                            return;
065                    }
066    
067                    try {
068                            doImportStagedModel(portletDataContext, element, path, stagedModel);
069                    }
070                    catch (Exception e) {
071                            throw new PortletDataException(e);
072                    }
073            }
074    
075            protected abstract void doExportStagedModel(
076                            PortletDataContext portletDataContext, Element[] elements,
077                            T stagedModel)
078                    throws Exception;
079    
080            protected abstract void doImportStagedModel(
081                            PortletDataContext portletDataContext, Element element, String path,
082                            T stagedModel)
083                    throws Exception;
084    
085    }