Coverage Report - org.apache.tapestry5.internal.model.MutableEmbeddedComponentModelImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MutableEmbeddedComponentModelImpl
100%
31/31
100%
10/10
0
 
 1  
 // Copyright 2006, 2008, 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 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  
      * List of mixin class names.
 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  
 }