Coverage Report - org.seasar.uruma.context.impl.AbstractWidgetHolder
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractWidgetHolder
59%
10/17
17%
1/6
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.uruma.context.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.Collections;
 21  
 import java.util.HashMap;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.seasar.uruma.context.WidgetHandle;
 26  
 import org.seasar.uruma.context.WidgetHolder;
 27  
 import org.seasar.uruma.core.UrumaMessageCodes;
 28  
 import org.seasar.uruma.exception.DuplicateWidgetIdException;
 29  
 import org.seasar.uruma.log.UrumaLogger;
 30  
 import org.seasar.uruma.util.AssertionUtil;
 31  
 
 32  
 /**
 33  
  * {@link WidgetHolder} の実装クラスです。<br />
 34  
  * 
 35  
  * @author y-komori
 36  
  */
 37  224
 public abstract class AbstractWidgetHolder implements WidgetHolder {
 38  4
     private static final UrumaLogger logger = UrumaLogger
 39  
             .getLogger(AbstractWidgetHolder.class);
 40  
 
 41  224
     private Map<String, WidgetHandle> handleMap = new HashMap<String, WidgetHandle>();
 42  
 
 43  
     /*
 44  
      * @see
 45  
      * org.seasar.uruma.context.WidgetHolder#getWidgetHandle(java.lang.String)
 46  
      */
 47  
     public WidgetHandle getWidgetHandle(final String handleId) {
 48  5500
         return handleMap.get(handleId);
 49  
     }
 50  
 
 51  
     /*
 52  
      * @see org.seasar.uruma.context.WidgetHolder#getWidgetHandles()
 53  
      */
 54  
     public Collection<WidgetHandle> getWidgetHandles() {
 55  0
         return Collections.unmodifiableCollection(handleMap.values());
 56  
     }
 57  
 
 58  
     /*
 59  
      * @see
 60  
      * org.seasar.uruma.context.WidgetHolder#hasWidgetHandle(java.lang.String)
 61  
      */
 62  
     public boolean hasWidgetHandle(final String handleId) {
 63  3872
         return handleMap.containsKey(handleId);
 64  
     }
 65  
 
 66  
     /*
 67  
      * @see
 68  
      * org.seasar.uruma.context.WidgetHolder#putWidgetHandle(org.seasar.uruma
 69  
      * .context.WidgetHandle)
 70  
      */
 71  
     public void putWidgetHandle(final WidgetHandle handle) {
 72  2020
         AssertionUtil.assertNotNull("handle", handle);
 73  
 
 74  2020
         if (hasWidgetHandle(handle.getId())) {
 75  0
             throw new DuplicateWidgetIdException(handle.getId(), handle
 76  
                     .getWidgetClass().getName());
 77  
         }
 78  2020
         logger.log(UrumaMessageCodes.WIDGET_REGISTERED, handle.getId(), handle
 79  
                 .getWidgetClass().getName());
 80  2020
         handleMap.put(handle.getId(), handle);
 81  2020
     }
 82  
 
 83  
     /*
 84  
      * @see
 85  
      * org.seasar.uruma.context.WidgetHolder#getWidgetHandles(java.lang.Class)
 86  
      */
 87  
     public List<WidgetHandle> getWidgetHandles(final Class<?> clazz) {
 88  0
         List<WidgetHandle> handles = new ArrayList<WidgetHandle>();
 89  0
         for (WidgetHandle handle : handleMap.values()) {
 90  0
             if (handle.instanceOf(clazz)) {
 91  0
                 handles.add(handle);
 92  
             }
 93  
         }
 94  0
         return handles;
 95  
     }
 96  
 }