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.exportimport.lar;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.model.ClassedModel;
020    import com.liferay.portal.model.ResourcedModel;
021    import com.liferay.portal.model.StagedModel;
022    
023    /**
024     * @author Mate Thurzo
025     */
026    @ProviderType
027    public class ExportImportClassedModelUtil {
028    
029            public static String getClassName(ClassedModel classedModel) {
030                    String modelClassName = classedModel.getModelClassName();
031    
032                    if (classedModel instanceof StagedModel) {
033                            StagedModel stagedModel = (StagedModel)classedModel;
034    
035                            StagedModelType stagedModelType = stagedModel.getStagedModelType();
036    
037                            modelClassName = stagedModelType.getClassName();
038                    }
039    
040                    return modelClassName;
041            }
042    
043            public static long getClassPK(ClassedModel classedModel) {
044                    if (classedModel instanceof ResourcedModel) {
045                            ResourcedModel resourcedModel = (ResourcedModel)classedModel;
046    
047                            return resourcedModel.getResourcePrimKey();
048                    }
049    
050                    return (Long)classedModel.getPrimaryKeyObj();
051            }
052    
053            public static String getClassSimpleName(ClassedModel classedModel) {
054                    Class<?> modelClass = classedModel.getModelClass();
055    
056                    String modelClassSimpleName = modelClass.getSimpleName();
057    
058                    if (classedModel instanceof StagedModel) {
059                            StagedModel stagedModel = (StagedModel)classedModel;
060    
061                            StagedModelType stagedModelType = stagedModel.getStagedModelType();
062    
063                            modelClassSimpleName = stagedModelType.getClassSimpleName();
064                    }
065    
066                    return modelClassSimpleName;
067            }
068    
069    }