Coverage Report - org.seasar.cubby.plugins.s2.detector.impl.ClassDetectorImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassDetectorImpl
0%
0/20
0%
0/6
0
 
 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.s2.detector.impl;
 17  
 
 18  
 import java.util.HashSet;
 19  
 import java.util.Set;
 20  
 
 21  
 import org.seasar.cubby.plugins.s2.detector.ClassDetector;
 22  
 import org.seasar.cubby.plugins.s2.detector.DetectClassProcessor;
 23  
 import org.seasar.framework.container.ComponentDef;
 24  
 import org.seasar.framework.container.cooldeploy.CoolComponentAutoRegister;
 25  
 import org.seasar.framework.util.ClassUtil;
 26  
 import org.seasar.framework.util.Disposable;
 27  
 import org.seasar.framework.util.DisposableUtil;
 28  
 
 29  
 /**
 30  
  * クラスパスを走査してクラスを検出するクラスの実装です。
 31  
  * <p>
 32  
  * Cool Deploy の挙動と合わせるため、{@link CoolComponentAutoRegister} を継承しています。
 33  
  * </p>
 34  
  * 
 35  
  * @author baba
 36  
  * @since 1.1.0
 37  
  */
 38  0
 public class ClassDetectorImpl extends CoolComponentAutoRegister implements
 39  
                 ClassDetector, Disposable {
 40  
 
 41  
         /** スーパークラスの初期化メソッドをクリアします。 */
 42  0
         public static final String INIT_METHOD = null;
 43  
 
 44  
         /** 初期化フラグ。 */
 45  
         private boolean initialized;
 46  
 
 47  
         /** 検出されたクラスを処理するクラスの配列です。 */
 48  
         private DetectClassProcessor[] processors;
 49  
 
 50  
         /** 処理済みのクラス。 */
 51  0
         private final Set<String> processedClasses = new HashSet<String>();
 52  
 
 53  
         /**
 54  
          * {@inheritDoc}
 55  
          */
 56  
         @Override
 57  
         public void processClass(final String packageName,
 58  
                         final String shortClassName) {
 59  0
                 final String fqcn = ClassUtil.concatName(packageName, shortClassName);
 60  0
                 if (!processedClasses.contains(fqcn)) {
 61  0
                         processedClasses.add(fqcn);
 62  0
                         for (final DetectClassProcessor processor : processors) {
 63  0
                                 processor.processClass(packageName, shortClassName);
 64  
                         }
 65  
                 }
 66  0
         }
 67  
 
 68  
         /**
 69  
          * {@inheritDoc}
 70  
          */
 71  
         public void detect() {
 72  0
                 if (!initialized) {
 73  0
                         processedClasses.clear();
 74  0
                         processors = (DetectClassProcessor[]) getContainer().getRoot()
 75  
                                         .findAllComponents(DetectClassProcessor.class);
 76  0
                         registerAll();
 77  0
                         processedClasses.clear();
 78  0
                         DisposableUtil.add(this);
 79  0
                         initialized = true;
 80  
                 }
 81  0
         }
 82  
 
 83  
         /**
 84  
          * {@inheritDoc}
 85  
          */
 86  
         public void dispose() {
 87  0
                 initialized = false;
 88  0
         }
 89  
 
 90  
         /**
 91  
          * {@inheritDoc}
 92  
          */
 93  
         @SuppressWarnings("unchecked")
 94  
         @Override
 95  
         protected ComponentDef createComponentDef(final Class componentClass) {
 96  0
                 throw new UnsupportedOperationException();
 97  
         }
 98  
 
 99  
 }