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