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