Coverage Report - org.apache.myfaces.flow.cdi.FlowBuilderFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
FlowBuilderFactoryBean
0%
0/14
0%
0/6
2
 
 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 java.util.ArrayList;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 
 25  
 import javax.enterprise.context.ApplicationScoped;
 26  
 import javax.enterprise.inject.Produces;
 27  
 import javax.enterprise.inject.spi.BeanManager;
 28  
 import javax.enterprise.inject.spi.Producer;
 29  
 import javax.faces.context.FacesContext;
 30  
 import javax.faces.flow.Flow;
 31  
 import javax.faces.flow.builder.FlowBuilder;
 32  
 import javax.faces.flow.builder.FlowBuilderParameter;
 33  
 import javax.inject.Inject;
 34  
 import javax.inject.Named;
 35  
 
 36  
 import org.apache.myfaces.cdi.util.CDIUtils;
 37  
 import org.apache.myfaces.flow.builder.FlowBuilderImpl;
 38  
 
 39  
 /**
 40  
  * This bean is used later by CDI to process flow definitions
 41  
  *
 42  
  * @author Leonardo Uribe
 43  
  */
 44  
 @Named(FlowBuilderFactoryBean.FLOW_BUILDER_FACTORY_BEAN_NAME)
 45  
 @ApplicationScoped
 46  
 public class FlowBuilderFactoryBean
 47  
 {
 48  
     public static final String FLOW_BUILDER_FACTORY_BEAN_NAME =
 49  
         "oam_FLOW_BUILDER_FACTORY_BEAN_NAME";
 50  
 
 51  0
     private List<Flow> flowDefinitions = null;
 52  
 
 53  
     @Inject
 54  
     private FlowBuilderCDIExtension flowBuilderExtension;
 55  
 
 56  
     public FlowBuilderFactoryBean()
 57  0
     {
 58  0
     }
 59  
 
 60  
     @Produces
 61  
     @FlowBuilderParameter
 62  
     public FlowBuilder createFlowBuilderInstance()
 63  
     {
 64  0
         return new FlowBuilderImpl();
 65  
     }
 66  
 
 67  
     /**
 68  
      * @return the flowDefinitions
 69  
      */
 70  
     public synchronized List<Flow> getFlowDefinitions()
 71  
     {
 72  0
         if (flowDefinitions == null)
 73  
         {
 74  0
             flowDefinitions = new ArrayList<Flow>();
 75  0
             BeanManager beanManager = CDIUtils.getBeanManager(FacesContext.getCurrentInstance().getExternalContext());
 76  0
             Iterator<Producer<Flow>> it = flowBuilderExtension.getFlowProducers().iterator();
 77  
 
 78  0
             if (it != null)
 79  
             {
 80  0
                 while (it.hasNext())
 81  
                 {
 82  0
                     Flow flow = it.next().produce(beanManager.<Flow>createCreationalContext(null));
 83  0
                     flowDefinitions.add(flow);
 84  0
                 }
 85  
             }
 86  
         }
 87  
 
 88  0
         return flowDefinitions;
 89  
     }
 90  
 }