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 public class UrumaNamingConventionImpl extends NamingConventionImpl implements
40 NamingConvention, Disposable {
41
42
43
44
45 public UrumaNamingConventionImpl() {
46 super();
47 }
48
49
50
51
52
53
54
55
56 @Override
57 @SuppressWarnings("unchecked")
58 protected ExistChecker[] createExistCheckerArray(
59 final String rootPackageName) {
60 if (StringUtil.isEmpty(rootPackageName)) {
61 return new ExistChecker[0];
62 }
63 final String s = rootPackageName.replace('.', '/');
64 final List<ExistChecker> list = new ArrayList<ExistChecker>();
65 for (final Iterator<URL> it = ClassLoaderUtil.getResources(this
66 .getClass(), s); it.hasNext();) {
67 final URL url = it.next();
68 final String protocol = URLUtil.toCanonicalProtocol(url
69 .getProtocol());
70 if ("file".equals(protocol)) {
71 list.add(new FileExistChecker(url));
72 } else if ("jar".equals(protocol)) {
73 list.add(new JarExistChecker(url, rootPackageName));
74 } else if ("zip".equals(protocol)) {
75 list.add(new ZipExistChecker(url, rootPackageName));
76 } else if ("code-source".equals(protocol)) {
77 list.add(new CodeSourceExistChecker(url, rootPackageName));
78 } else if ("bundleresource".equals(protocol)) {
79 list.add(new BundleExistChecker(url));
80 }
81 }
82 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 protected BundleExistChecker(final URL rootUrl) {
99 URL fileLocatorUrl = null;
100 try {
101 fileLocatorUrl = FileLocator.toFileURL(rootUrl);
102 } catch (IOException ex) {
103 throw new IORuntimeException(ex);
104 }
105 if (fileLocatorUrl != null) {
106 rootFile = new File(fileLocatorUrl.getPath());
107 }
108
109 }
110
111 public boolean isExist(final String lastClassName) {
112 final File file = new File(rootFile, getPathName(lastClassName));
113 return file.exists();
114 }
115
116 public void close() {
117 }
118 }
119
120 }