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 java.io.Serializable;
020    
021    import java.util.HashMap;
022    import java.util.Map;
023    
024    /**
025     * @author Julio Camarero
026     */
027    @ProviderType
028    public class MissingReferences implements Serializable {
029    
030            public void add(MissingReference missingReference) {
031                    String type = missingReference.getType();
032    
033                    if (type.equals(PortletDataContext.REFERENCE_TYPE_DEPENDENCY)) {
034                            add(_dependencyMissingReferences, missingReference);
035                    }
036                    else if (type.equals(PortletDataContext.REFERENCE_TYPE_WEAK)) {
037                            add(_weakMissingReferences, missingReference);
038                    }
039            }
040    
041            public Map<String, MissingReference> getDependencyMissingReferences() {
042                    return _dependencyMissingReferences;
043            }
044    
045            public Map<String, MissingReference> getWeakMissingReferences() {
046                    return _weakMissingReferences;
047            }
048    
049            protected void add(
050                    Map<String, MissingReference> missingReferences,
051                    MissingReference missingReference) {
052    
053                    String key = null;
054    
055                    String type = missingReference.getType();
056    
057                    if (type.equals(PortletDataContext.REFERENCE_TYPE_DEPENDENCY)) {
058                            key = missingReference.getDisplayName();
059                    }
060                    else if (type.equals(PortletDataContext.REFERENCE_TYPE_WEAK)) {
061                            key = missingReference.getReferrerClassName();
062                    }
063    
064                    MissingReference existingMissingReference = missingReferences.get(key);
065    
066                    if (existingMissingReference != null) {
067                            existingMissingReference.addReferrers(
068                                    missingReference.getReferrers());
069                    }
070                    else {
071                            missingReferences.put(key, missingReference);
072                    }
073            }
074    
075            private final Map<String, MissingReference> _dependencyMissingReferences =
076                    new HashMap<>();
077            private final Map<String, MissingReference> _weakMissingReferences =
078                    new HashMap<>();
079    
080    }