Coverage Report - org.seasar.uruma.container.convention.UrumaNamingConventionImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UrumaNamingConventionImpl
0%
0/23
0%
0/14
0
UrumaNamingConventionImpl$BundleExistChecker
0%
0/12
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 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.uruma.container.convention;
 17  
 
 18  
 import java.io.File;
 19  
 import java.io.IOException;
 20  
 import java.net.URL;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 
 25  
 import org.eclipse.core.runtime.FileLocator;
 26  
 import org.seasar.framework.convention.NamingConvention;
 27  
 import org.seasar.framework.convention.impl.NamingConventionImpl;
 28  
 import org.seasar.framework.exception.IORuntimeException;
 29  
 import org.seasar.framework.util.ClassLoaderUtil;
 30  
 import org.seasar.framework.util.Disposable;
 31  
 import org.seasar.framework.util.StringUtil;
 32  
 import org.seasar.framework.util.URLUtil;
 33  
 
 34  
 /**
 35  
  * {@link NamingConvention}の実装クラスです。
 36  
  * 
 37  
  * @author y.sugigami
 38  
  */
 39  0
 public class UrumaNamingConventionImpl extends NamingConventionImpl implements
 40  
         NamingConvention, Disposable {
 41  
 
 42  
     /**
 43  
      * {@link NamingConventionImpl}を作成します。
 44  
      */
 45  
     public UrumaNamingConventionImpl() {
 46  0
         super();
 47  0
     }
 48  
 
 49  
     /**
 50  
      * 存在チェッカの配列を作成します。
 51  
      * 
 52  
      * @param rootPackageName
 53  
      *            ルートパッケージ名
 54  
      * @return 存在チェッカの配列
 55  
      */
 56  
     @Override
 57  
     @SuppressWarnings("unchecked")
 58  
     protected ExistChecker[] createExistCheckerArray(
 59  
             final String rootPackageName) {
 60  0
         if (StringUtil.isEmpty(rootPackageName)) {
 61  0
             return new ExistChecker[0];
 62  
         }
 63  0
         final String s = rootPackageName.replace('.', '/');
 64  0
         final List<ExistChecker> list = new ArrayList<ExistChecker>();
 65  0
         for (final Iterator<URL> it = ClassLoaderUtil.getResources(this
 66  0
                 .getClass(), s); it.hasNext();) {
 67  0
             final URL url = it.next();
 68  0
             final String protocol = URLUtil.toCanonicalProtocol(url
 69  
                     .getProtocol());
 70  0
             if ("file".equals(protocol)) {
 71  0
                 list.add(new FileExistChecker(url));
 72  0
             } else if ("jar".equals(protocol)) {
 73  0
                 list.add(new JarExistChecker(url, rootPackageName));
 74  0
             } else if ("zip".equals(protocol)) {
 75  0
                 list.add(new ZipExistChecker(url, rootPackageName));
 76  0
             } else if ("code-source".equals(protocol)) {
 77  0
                 list.add(new CodeSourceExistChecker(url, rootPackageName));
 78  0
             } else if ("bundleresource".equals(protocol)) {
 79  0
                 list.add(new BundleExistChecker(url));
 80  
             }
 81  0
         }
 82  0
         return list.toArray(new ExistChecker[list.size()]);
 83  
     }
 84  
 
 85  
     /**
 86  
      * バンドル用の存在チェッカです。
 87  
      * 
 88  
      */
 89  
     protected static class BundleExistChecker implements ExistChecker {
 90  
         private File rootFile;
 91  
 
 92  
         /**
 93  
          * インスタンスを作成します。
 94  
          * 
 95  
          * @param rootUrl
 96  
          *            ルートURL
 97  
          */
 98  0
         protected BundleExistChecker(final URL rootUrl) {
 99  0
             URL fileLocatorUrl = null;
 100  
             try {
 101  0
                 fileLocatorUrl = FileLocator.toFileURL(rootUrl);
 102  0
             } catch (IOException ex) {
 103  0
                 throw new IORuntimeException(ex);
 104  0
             }
 105  0
             if (fileLocatorUrl != null) {
 106  0
                 rootFile = new File(fileLocatorUrl.getPath());
 107  
             }
 108  
 
 109  0
         }
 110  
 
 111  
         public boolean isExist(final String lastClassName) {
 112  0
             final File file = new File(rootFile, getPathName(lastClassName));
 113  0
             return file.exists();
 114  
         }
 115  
 
 116  
         public void close() {
 117  0
         }
 118  
     }
 119  
 
 120  
 }