| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.services; |
| 16 | |
|
| 17 | |
import static org.apache.tapestry5.ioc.internal.util.Defense.notNull; |
| 18 | |
import org.apache.tapestry5.ioc.internal.util.InternalUtils; |
| 19 | |
|
| 20 | |
import java.util.Formatter; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
public final class AliasContribution<T> |
| 26 | |
{ |
| 27 | |
private final Class<T> contributionType; |
| 28 | |
|
| 29 | |
private final String mode; |
| 30 | |
|
| 31 | |
private final T object; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public static <X> AliasContribution<X> create(Class<X> contributionType, X object) |
| 37 | |
{ |
| 38 | 24 | return new AliasContribution<X>(contributionType, object); |
| 39 | |
} |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
public static <X> AliasContribution<X> create(Class<X> contributionType, String mode, X object) |
| 45 | |
{ |
| 46 | 188 | return new AliasContribution<X>(contributionType, mode, object); |
| 47 | |
} |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
public AliasContribution(Class<T> contributionType, T object) |
| 53 | |
{ |
| 54 | 24 | this(contributionType, "", object); |
| 55 | 24 | } |
| 56 | |
|
| 57 | |
public AliasContribution(Class<T> contributionType, String mode, T object) |
| 58 | 216 | { |
| 59 | 216 | this.contributionType = notNull(contributionType, "contributionClass"); |
| 60 | 216 | this.mode = notNull(mode, "mode"); |
| 61 | 216 | this.object = notNull(object, "object"); |
| 62 | 216 | } |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
public String getMode() |
| 70 | |
{ |
| 71 | 420 | return mode; |
| 72 | |
} |
| 73 | |
|
| 74 | |
public Class<T> getContributionType() |
| 75 | |
{ |
| 76 | 210 | return contributionType; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public T getObject() |
| 83 | |
{ |
| 84 | 210 | return object; |
| 85 | |
} |
| 86 | |
|
| 87 | |
@Override |
| 88 | |
public String toString() |
| 89 | |
{ |
| 90 | 4 | StringBuilder builder = new StringBuilder(); |
| 91 | 4 | Formatter formatter = new Formatter(builder); |
| 92 | |
|
| 93 | 4 | formatter.format("<AliasContribution: %s", contributionType.getName()); |
| 94 | |
|
| 95 | 4 | if (InternalUtils.isNonBlank(mode)) formatter.format(" mode:%s", mode); |
| 96 | |
|
| 97 | 4 | formatter.format(" %s>", object); |
| 98 | |
|
| 99 | 4 | return builder.toString(); |
| 100 | |
} |
| 101 | |
|
| 102 | |
} |