001: // Copyright 2006 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.internal.model;
016:
017: import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
018:
019: import java.util.Collections;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.apache.tapestry.ioc.BaseLocatable;
024: import org.apache.tapestry.ioc.Location;
025: import org.apache.tapestry.ioc.internal.util.CollectionFactory;
026: import org.apache.tapestry.ioc.internal.util.InternalUtils;
027: import org.apache.tapestry.model.MutableEmbeddedComponentModel;
028:
029: public class MutableEmbeddedComponentModelImpl extends BaseLocatable
030: implements MutableEmbeddedComponentModel {
031: private final String _id;
032:
033: private final String _componentType;
034:
035: private final String _componentClassName;
036:
037: private final String _declaredClass;
038:
039: private Map<String, String> _parameters;
040:
041: /** List of mixin class names. */
042: private List<String> _mixinClassNames;
043:
044: public MutableEmbeddedComponentModelImpl(String id,
045: String componentType, String componentClassName,
046: String declaredClass, Location location) {
047: super (location);
048:
049: _id = id;
050: _componentType = componentType;
051: _componentClassName = componentClassName;
052: _declaredClass = declaredClass;
053: }
054:
055: public String getComponentClassName() {
056: return _componentClassName;
057: }
058:
059: @Override
060: public String toString() {
061: return String.format(
062: "EmbeddedComponentModel[id=%s type=%s class=%s]", _id,
063: _componentType, _componentClassName);
064: }
065:
066: public void addParameter(String name, String value) {
067: if (_parameters == null)
068: _parameters = newMap();
069: else if (_parameters.containsKey(name))
070: throw new IllegalArgumentException(ModelMessages
071: .duplicateParameterValue(name, _id, _declaredClass));
072:
073: _parameters.put(name, value);
074: }
075:
076: public String getId() {
077: return _id;
078: }
079:
080: public String getComponentType() {
081: return _componentType;
082: }
083:
084: public List<String> getParameterNames() {
085: return InternalUtils.sortedKeys(_parameters);
086: }
087:
088: public String getParameterValue(String parameterName) {
089: return InternalUtils.get(_parameters, parameterName);
090: }
091:
092: public List<String> getMixinClassNames() {
093: if (_mixinClassNames == null)
094: return Collections.emptyList();
095:
096: return Collections.unmodifiableList(_mixinClassNames);
097: }
098:
099: public void addMixin(String mixinClassName) {
100: if (_mixinClassNames == null) {
101: _mixinClassNames = CollectionFactory.newList();
102: } else {
103: if (_mixinClassNames.contains(mixinClassName))
104: throw new IllegalArgumentException(ModelMessages
105: .duplicateMixin(mixinClassName, _id));
106: }
107:
108: _mixinClassNames.add(mixinClassName);
109: }
110: }
|