| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.model; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.ioc.BaseLocatable; |
| 18 | |
import org.apache.tapestry5.ioc.Location; |
| 19 | |
import org.apache.tapestry5.ioc.internal.util.CollectionFactory; |
| 20 | |
import org.apache.tapestry5.ioc.internal.util.Defense; |
| 21 | |
import org.apache.tapestry5.ioc.internal.util.InternalUtils; |
| 22 | |
import org.apache.tapestry5.model.MutableEmbeddedComponentModel; |
| 23 | |
|
| 24 | |
import java.util.Collections; |
| 25 | |
import java.util.List; |
| 26 | |
import java.util.Map; |
| 27 | |
|
| 28 | |
public class MutableEmbeddedComponentModelImpl extends BaseLocatable implements MutableEmbeddedComponentModel |
| 29 | |
{ |
| 30 | |
private final String id; |
| 31 | |
|
| 32 | |
private final String componentType; |
| 33 | |
|
| 34 | |
private final String componentClassName; |
| 35 | |
|
| 36 | |
private final String declaredClass; |
| 37 | |
|
| 38 | |
private final boolean inheritInformalParameters; |
| 39 | |
|
| 40 | |
private Map<String, String> parameters; |
| 41 | |
|
| 42 | 186 | private List<String> publishedParameters = Collections.emptyList(); |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
private List<String> mixinClassNames; |
| 48 | |
|
| 49 | |
public MutableEmbeddedComponentModelImpl(String id, String componentType, String componentClassName, |
| 50 | |
String declaredClass, boolean inheritInformalParameters, Location location) |
| 51 | |
{ |
| 52 | 186 | super(location); |
| 53 | |
|
| 54 | 186 | this.id = id; |
| 55 | 186 | this.componentType = componentType; |
| 56 | 186 | this.componentClassName = componentClassName; |
| 57 | 186 | this.inheritInformalParameters = inheritInformalParameters; |
| 58 | 186 | this.declaredClass = declaredClass; |
| 59 | 186 | } |
| 60 | |
|
| 61 | |
public String getComponentClassName() |
| 62 | |
{ |
| 63 | 204 | return componentClassName; |
| 64 | |
} |
| 65 | |
|
| 66 | |
@Override |
| 67 | |
public String toString() |
| 68 | |
{ |
| 69 | 4 | return String.format("EmbeddedComponentModel[id=%s type=%s class=%s inheritInformals=%s]", id, componentType, |
| 70 | |
componentClassName, inheritInformalParameters); |
| 71 | |
} |
| 72 | |
|
| 73 | |
public void addParameter(String name, String value) |
| 74 | |
{ |
| 75 | 272 | if (parameters == null) parameters = CollectionFactory.newMap(); |
| 76 | 176 | else if (parameters.containsKey(name)) |
| 77 | 2 | throw new IllegalArgumentException(ModelMessages.duplicateParameterValue(name, id, declaredClass)); |
| 78 | |
|
| 79 | 270 | parameters.put(name, value); |
| 80 | 270 | } |
| 81 | |
|
| 82 | |
public String getId() |
| 83 | |
{ |
| 84 | 2 | return id; |
| 85 | |
} |
| 86 | |
|
| 87 | |
public String getComponentType() |
| 88 | |
{ |
| 89 | 208 | return componentType; |
| 90 | |
} |
| 91 | |
|
| 92 | |
public List<String> getParameterNames() |
| 93 | |
{ |
| 94 | 206 | return InternalUtils.sortedKeys(parameters); |
| 95 | |
} |
| 96 | |
|
| 97 | |
public String getParameterValue(String parameterName) |
| 98 | |
{ |
| 99 | 422 | return InternalUtils.get(parameters, parameterName); |
| 100 | |
} |
| 101 | |
|
| 102 | |
public List<String> getMixinClassNames() |
| 103 | |
{ |
| 104 | 210 | if (mixinClassNames == null) return Collections.emptyList(); |
| 105 | |
|
| 106 | 8 | return Collections.unmodifiableList(mixinClassNames); |
| 107 | |
} |
| 108 | |
|
| 109 | |
public void addMixin(String mixinClassName) |
| 110 | |
{ |
| 111 | 12 | if (mixinClassNames == null) |
| 112 | |
{ |
| 113 | 8 | mixinClassNames = CollectionFactory.newList(); |
| 114 | |
} |
| 115 | |
else |
| 116 | |
{ |
| 117 | 4 | if (mixinClassNames.contains(mixinClassName)) throw new IllegalArgumentException(ModelMessages |
| 118 | |
.duplicateMixin(mixinClassName, id)); |
| 119 | |
} |
| 120 | |
|
| 121 | 10 | mixinClassNames.add(mixinClassName); |
| 122 | 10 | } |
| 123 | |
|
| 124 | |
public boolean getInheritInformalParameters() |
| 125 | |
{ |
| 126 | 206 | return inheritInformalParameters; |
| 127 | |
} |
| 128 | |
|
| 129 | |
public void setPublishedParameters(List<String> parameterNames) |
| 130 | |
{ |
| 131 | 16 | Defense.notNull(parameterNames, "parameterNames"); |
| 132 | |
|
| 133 | 16 | publishedParameters = parameterNames; |
| 134 | 16 | } |
| 135 | |
|
| 136 | |
public List<String> getPublishedParameters() |
| 137 | |
{ |
| 138 | 204 | return publishedParameters; |
| 139 | |
} |
| 140 | |
} |