Coverage Report - org.apache.myfaces.flow.cdi.FlowScopeMap
 
Classes in this File Line Coverage Branch Coverage Complexity
FlowScopeMap
0%
0/78
0%
0/34
3.214
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.flow.cdi;
 20  
 
 21  
 import org.apache.myfaces.cdi.util.CDIUtils;
 22  
 import java.util.Collection;
 23  
 import java.util.Map;
 24  
 import java.util.Set;
 25  
 import javax.enterprise.inject.spi.BeanManager;
 26  
 import org.apache.myfaces.cdi.util.BeanProvider;
 27  
 
 28  
 /**
 29  
  * 
 30  
  *
 31  
  * @author Leonardo Uribe
 32  
  */
 33  
 public class FlowScopeMap implements Map
 34  
 {
 35  
     private BeanManager _beanManager;
 36  
     private String _currentClientWindowFlowId;
 37  
     private FlowScopeBeanHolder _flowScopeBeanHolder;
 38  0
     private boolean _initOptional = false;
 39  
     
 40  
     public FlowScopeMap(BeanManager beanManager, String currentFlowMapKey)
 41  0
     {
 42  0
         this._beanManager = beanManager;
 43  0
         this._currentClientWindowFlowId = currentFlowMapKey;
 44  0
     }
 45  
     
 46  
     private FlowScopeBeanHolder getFlowScopeBeanHolder(boolean create)
 47  
     {
 48  0
         if (_flowScopeBeanHolder == null)
 49  
         {
 50  0
             if (create)
 51  
             {
 52  0
                 _flowScopeBeanHolder = CDIUtils.lookup(_beanManager,
 53  
                     FlowScopeBeanHolder.class);
 54  
             }
 55  0
             else if (!_initOptional)
 56  
             {
 57  0
                 _flowScopeBeanHolder = BeanProvider.getContextualReference(
 58  
                     _beanManager, FlowScopeBeanHolder.class, true);
 59  0
                 _initOptional = true;
 60  
             }
 61  
         }
 62  0
         return _flowScopeBeanHolder;
 63  
     }
 64  
     
 65  
     public int size()
 66  
     {
 67  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
 68  0
         if (flowScopeBeanHolder == null)
 69  
         {
 70  0
             return 0;
 71  
         }
 72  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
 73  
             _currentClientWindowFlowId, false);
 74  0
         if (map == null)
 75  
         {
 76  0
             return 0;
 77  
         }
 78  0
         return map.size();
 79  
     }
 80  
     
 81  
     public boolean isEmpty()
 82  
     {
 83  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
 84  0
         if (flowScopeBeanHolder == null)
 85  
         {
 86  0
             return true;
 87  
         }
 88  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
 89  
             _currentClientWindowFlowId, false);
 90  0
         if (map == null)
 91  
         {
 92  0
             return true;
 93  
         }
 94  0
         return map.isEmpty();
 95  
     }
 96  
 
 97  
     public boolean containsKey(Object key)
 98  
     {
 99  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
 100  0
         if (flowScopeBeanHolder == null)
 101  
         {
 102  0
             return false;
 103  
         }
 104  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
 105  
             _currentClientWindowFlowId, false);
 106  0
         if (map == null)
 107  
         {
 108  0
             return false;
 109  
         }
 110  0
         return map.containsKey(key);
 111  
     }
 112  
 
 113  
     public boolean containsValue(Object value)
 114  
     {
 115  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
 116  0
         if (flowScopeBeanHolder == null)
 117  
         {
 118  0
             return false;
 119  
         }
 120  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
 121  
             _currentClientWindowFlowId, false);
 122  0
         if (map == null)
 123  
         {
 124  0
             return false;
 125  
         }
 126  0
         return map.containsValue(value);
 127  
     }
 128  
 
 129  
     public Object get(Object key)
 130  
     {
 131  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
 132  0
         if (flowScopeBeanHolder == null)
 133  
         {
 134  0
             return null;
 135  
         }
 136  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
 137  
             _currentClientWindowFlowId, false);
 138  0
         if (map == null)
 139  
         {
 140  0
             return null;
 141  
         }
 142  0
         return map.get(key);
 143  
     }
 144  
 
 145  
     public Object put(Object key, Object value)
 146  
     {
 147  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
 148  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
 149  
             _beanManager, _currentClientWindowFlowId, true);
 150  0
         return map.put(key, value);
 151  
     }
 152  
 
 153  
     public Object remove(Object key)
 154  
     {
 155  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
 156  0
         if (flowScopeBeanHolder == null)
 157  
         {
 158  0
             return null;
 159  
         }
 160  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
 161  
             _currentClientWindowFlowId, false);
 162  0
         if (map == null)
 163  
         {
 164  0
             return null;
 165  
         }
 166  0
         return map.remove(key);
 167  
     }
 168  
 
 169  
     public void putAll(Map m)
 170  
     {
 171  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
 172  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
 173  
             _beanManager, _currentClientWindowFlowId, true);
 174  0
         map.putAll(m);
 175  0
     }
 176  
 
 177  
     public void clear()
 178  
     {
 179  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
 180  0
         if (flowScopeBeanHolder == null)
 181  
         {
 182  0
             return;
 183  
         }
 184  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
 185  
             _currentClientWindowFlowId, false);
 186  0
         if (map == null)
 187  
         {
 188  0
             return;
 189  
         }
 190  0
         map.clear();
 191  0
     }
 192  
 
 193  
     public Set keySet()
 194  
     {
 195  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
 196  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
 197  
             _beanManager, _currentClientWindowFlowId, true);
 198  0
         return map.keySet();
 199  
     }
 200  
 
 201  
     public Collection values()
 202  
     {
 203  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
 204  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
 205  
             _beanManager, _currentClientWindowFlowId, true);
 206  0
         return map.values();
 207  
     }
 208  
 
 209  
     public Set entrySet()
 210  
     {
 211  0
         FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
 212  0
         Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
 213  
             _beanManager, _currentClientWindowFlowId, true);
 214  0
         return map.entrySet();
 215  
     }
 216  
 }