Coverage Report - org.seasar.cubby.plugins.spring.spi.SpringPathResolverProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringPathResolverProvider
92%
13/14
83%
5/6
2.333
 
 1  
 /*
 2  
  * Copyright 2004-2009 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.cubby.plugins.spring.spi;
 17  
 
 18  
 import org.seasar.cubby.routing.PathResolver;
 19  
 import org.seasar.cubby.spi.PathResolverProvider;
 20  
 import org.seasar.cubby.util.ActionUtils;
 21  
 import org.springframework.beans.factory.BeanFactoryUtils;
 22  
 import org.springframework.beans.factory.annotation.Autowired;
 23  
 import org.springframework.context.ApplicationContext;
 24  
 import org.springframework.context.ApplicationContextAware;
 25  
 
 26  
 /**
 27  
  * パスリゾルバプロバイダの実装クラスです。
 28  
  * 
 29  
  * @author suzuki-kei
 30  
  * @author someda
 31  
  * @since 2.0.0
 32  
  */
 33  6
 public class SpringPathResolverProvider implements PathResolverProvider,
 34  
                 ApplicationContextAware {
 35  
 
 36  
         @Autowired
 37  
         private PathResolver pathResolver;
 38  
 
 39  
         private ApplicationContext applicationContext;
 40  
 
 41  6
         private boolean initialized = false;
 42  
 
 43  
         /**
 44  
          * アプリケーションコンテキストを設定します。
 45  
          * 
 46  
          * @param applicationContext
 47  
          *            アプリケーションコンテキスト
 48  
          */
 49  
         public void setApplicationContext(
 50  
                         final ApplicationContext applicationContext) {
 51  6
                 this.applicationContext = applicationContext;
 52  6
         }
 53  
 
 54  
         /**
 55  
          * このオブジェクトを初期化します。
 56  
          */
 57  
         public void initialize() {
 58  6
                 if (initialized) {
 59  0
                         return;
 60  
                 }
 61  
 
 62  6
                 final String[] names = BeanFactoryUtils
 63  
                                 .beanNamesIncludingAncestors(applicationContext);
 64  131
                 for (final String beanDefinitionName : names) {
 65  125
                         final Class<?> type = applicationContext
 66  
                                         .getType(beanDefinitionName);
 67  125
                         if (ActionUtils.isActionClass(type)) {
 68  6
                                 pathResolver.add(type);
 69  
                         }
 70  
                 }
 71  
 
 72  6
                 initialized = true;
 73  6
         }
 74  
 
 75  
         /**
 76  
          * {@inheritDoc}
 77  
          */
 78  
         public PathResolver getPathResolver() {
 79  1
                 return pathResolver;
 80  
         }
 81  
 
 82  
 }