| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.services; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.ioc.internal.util.CollectionFactory; |
| 18 | |
import org.apache.tapestry5.services.AliasContribution; |
| 19 | |
import org.apache.tapestry5.services.AliasManager; |
| 20 | |
import org.slf4j.Logger; |
| 21 | |
|
| 22 | |
import java.util.Collection; |
| 23 | |
import java.util.Map; |
| 24 | |
|
| 25 | |
public class AliasManagerImpl implements AliasManager |
| 26 | |
{ |
| 27 | |
private final Logger logger; |
| 28 | |
|
| 29 | |
private final Collection<AliasContribution> contributions; |
| 30 | |
|
| 31 | |
public AliasManagerImpl(Logger logger, Collection<AliasContribution> contributions) |
| 32 | 128 | { |
| 33 | 128 | this.logger = logger; |
| 34 | 128 | this.contributions = contributions; |
| 35 | 128 | } |
| 36 | |
|
| 37 | |
public Map<Class, Object> getAliasesForMode(String mode) |
| 38 | |
{ |
| 39 | 128 | Map<Class, Object> general = buildMapForMode(""); |
| 40 | 128 | Map<Class, Object> specific = buildMapForMode(mode); |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | 128 | general.putAll(specific); |
| 45 | |
|
| 46 | 128 | return general; |
| 47 | |
} |
| 48 | |
|
| 49 | |
private Map<Class, Object> buildMapForMode(String mode) |
| 50 | |
{ |
| 51 | 256 | Map<Class, Object> result = CollectionFactory.newMap(); |
| 52 | |
|
| 53 | 256 | for (AliasContribution ic : contributions) |
| 54 | |
{ |
| 55 | 416 | if (!ic.getMode().equalsIgnoreCase(mode)) continue; |
| 56 | |
|
| 57 | 206 | Class contributionType = ic.getContributionType(); |
| 58 | |
|
| 59 | 206 | Object existing = result.get(contributionType); |
| 60 | |
|
| 61 | 206 | if (existing != null) |
| 62 | |
{ |
| 63 | 2 | logger.error(ServicesMessages.duplicateContribution( |
| 64 | |
ic.getObject(), |
| 65 | |
contributionType, |
| 66 | |
existing)); |
| 67 | 2 | continue; |
| 68 | |
} |
| 69 | |
|
| 70 | 204 | result.put(contributionType, ic.getObject()); |
| 71 | 204 | } |
| 72 | |
|
| 73 | 256 | return result; |
| 74 | |
} |
| 75 | |
|
| 76 | |
} |