| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | public class UrumaNamingConventionImpl extends NamingConventionImpl implements |
| 40 | |
NamingConvention, Disposable { |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public UrumaNamingConventionImpl() { |
| 46 | 0 | super(); |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 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 | |
|
| 96 | |
|
| 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 | |
} |