Coverage Report - javax.faces.internal.MessageResourceBundleChainFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageResourceBundleChainFactory
23%
6/26
33%
6/18
3
 
 1  
 /*
 2  
  * Copyright 2004-2011 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 javax.faces.internal;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 import java.util.Locale;
 21  
 
 22  
 import org.seasar.framework.container.hotdeploy.HotdeployUtil;
 23  
 import org.seasar.framework.message.MessageResourceBundle;
 24  
 import org.seasar.framework.message.MessageResourceBundleFactory;
 25  
 import org.seasar.teeda.core.util.DIContainerUtil;
 26  
 
 27  
 /**
 28  
  * @author shot
 29  
  */
 30  
 public class MessageResourceBundleChainFactory {
 31  
 
 32  1
     private static MessageResourceBundle[] userBundles = null;
 33  
 
 34  0
     private MessageResourceBundleChainFactory() {
 35  0
     }
 36  
 
 37  
     public static MessageResourceBundle createChain(String bundleName,
 38  
             Locale locale) {
 39  108
         if (!DIContainerUtil.hasContainer()
 40  1
                 || !DIContainerUtil.hasComponent(MessageResourceBundle.class)) {
 41  108
             return createSimpleMessageResourceBundle(bundleName, locale);
 42  
         }
 43  0
         MessageResourceBundleChain chain = new MessageResourceBundleChain();
 44  0
         if (userBundles == null) {
 45  0
             List list = new ArrayList();
 46  0
             Object[] components = DIContainerUtil
 47  
                     .findAllComponents(MessageResourceBundle.class);
 48  0
             for (int i = 0; i < components.length; i++) {
 49  0
                 MessageResourceBundle bundle = (MessageResourceBundle) components[i];
 50  0
                 chain.addMessageResourceBundle(bundle);
 51  0
                 list.add(bundle);
 52  
             }
 53  0
             userBundles = (MessageResourceBundle[]) list
 54  
                     .toArray(new MessageResourceBundle[components.length]);
 55  
         } else {
 56  0
             for (int i = 0; i < userBundles.length; i++) {
 57  0
                 chain.addMessageResourceBundle(userBundles[i]);
 58  
             }
 59  
         }
 60  0
         MessageResourceBundle defaultBundle = createSimpleMessageResourceBundle(
 61  
                 bundleName, locale);
 62  0
         if (defaultBundle != null) {
 63  0
             chain.addMessageResourceBundle(defaultBundle);
 64  
         }
 65  0
         return chain;
 66  
     }
 67  
 
 68  
     public static void clearUserBundles() {
 69  0
         userBundles = null;
 70  0
     }
 71  
 
 72  
     private static MessageResourceBundle createSimpleMessageResourceBundle(
 73  
             String bundleName, Locale locale) {
 74  108
         if (HotdeployUtil.isHotdeploy()) {
 75  0
             return MessageResourceBundleFactory.getNullableBundle(bundleName,
 76  
                     locale);
 77  
         } else {
 78  108
             return new JavaMessageResourceBundle(bundleName, locale);
 79  
         }
 80  
     }
 81  
 
 82  
 }