updated to java6-style. (still working..)
@@ -130,7 +130,7 @@ | ||
130 | 130 | * |
131 | 131 | */ |
132 | 132 | public void testIsEmpty() { |
133 | - assertTrue(ArrayUtil.isEmpty(null)); | |
133 | + assertTrue(ArrayUtil.isEmpty((Object[]) null)); | |
134 | 134 | assertTrue(ArrayUtil.isEmpty(new Object[] {})); |
135 | 135 | assertFalse(ArrayUtil.isEmpty(new Object[] { "" })); |
136 | 136 | assertFalse(ArrayUtil.isEmpty(new Object[] { "aaa" })); |
@@ -21,7 +21,8 @@ | ||
21 | 21 | * @author higa |
22 | 22 | * |
23 | 23 | */ |
24 | -public class BinaryConversionUtil { | |
24 | +public class BinaryConversionUtil extends | |
25 | + org.seasar.util.convert.BinaryConversionUtil { | |
25 | 26 | |
26 | 27 | /** |
27 | 28 | * インスタンスを構築します。 |
@@ -29,22 +30,4 @@ | ||
29 | 30 | protected BinaryConversionUtil() { |
30 | 31 | } |
31 | 32 | |
32 | - /** | |
33 | - * byteの配列に変換します。 | |
34 | - * | |
35 | - * @param o | |
36 | - * @return byteの配列 | |
37 | - */ | |
38 | - public static byte[] toBinary(Object o) { | |
39 | - if (o instanceof byte[]) { | |
40 | - return (byte[]) o; | |
41 | - } else if (o == null) { | |
42 | - return null; | |
43 | - } else { | |
44 | - if (o instanceof String) { | |
45 | - return ((String) o).getBytes(); | |
46 | - } | |
47 | - throw new IllegalArgumentException(o.getClass().toString()); | |
48 | - } | |
49 | - } | |
50 | 33 | } |
\ No newline at end of file |
@@ -16,10 +16,7 @@ | ||
16 | 16 | package org.seasar.framework.util; |
17 | 17 | |
18 | 18 | import java.io.Serializable; |
19 | -import java.util.AbstractSet; | |
20 | 19 | import java.util.Collection; |
21 | -import java.util.Iterator; | |
22 | -import java.util.Map; | |
23 | 20 | import java.util.Set; |
24 | 21 | |
25 | 22 | /** |
@@ -28,20 +25,17 @@ | ||
28 | 25 | * @author higa |
29 | 26 | * |
30 | 27 | */ |
31 | -public class CaseInsensitiveSet extends AbstractSet implements Set, | |
28 | +public class CaseInsensitiveSet extends | |
29 | + org.seasar.util.collection.CaseInsensitiveSet implements Set<String>, | |
32 | 30 | Serializable { |
33 | 31 | |
34 | - static final long serialVersionUID = 0L; | |
32 | + private static final long serialVersionUID = 1L; | |
35 | 33 | |
36 | - private transient Map map; | |
37 | - | |
38 | - private static final Object PRESENT = new Object(); | |
39 | - | |
40 | 34 | /** |
41 | 35 | * {@link CaseInsensitiveSet}を作成します。 |
42 | 36 | */ |
43 | 37 | public CaseInsensitiveSet() { |
44 | - map = new CaseInsensitiveMap(); | |
38 | + super(); | |
45 | 39 | } |
46 | 40 | |
47 | 41 | /** |
@@ -49,9 +43,8 @@ | ||
49 | 43 | * |
50 | 44 | * @param c |
51 | 45 | */ |
52 | - public CaseInsensitiveSet(Collection c) { | |
53 | - map = new CaseInsensitiveMap(Math.max((int) (c.size() / .75f) + 1, 16)); | |
54 | - addAll(c); | |
46 | + public CaseInsensitiveSet(Collection<String> c) { | |
47 | + super(c); | |
55 | 48 | } |
56 | 49 | |
57 | 50 | /** |
@@ -60,34 +53,6 @@ | ||
60 | 53 | * @param initialCapacity |
61 | 54 | */ |
62 | 55 | public CaseInsensitiveSet(int initialCapacity) { |
63 | - map = new CaseInsensitiveMap(initialCapacity); | |
56 | + super(initialCapacity); | |
64 | 57 | } |
65 | - | |
66 | - public Iterator iterator() { | |
67 | - return map.keySet().iterator(); | |
68 | - } | |
69 | - | |
70 | - public int size() { | |
71 | - return map.size(); | |
72 | - } | |
73 | - | |
74 | - public boolean isEmpty() { | |
75 | - return map.isEmpty(); | |
76 | - } | |
77 | - | |
78 | - public boolean contains(Object o) { | |
79 | - return map.containsKey(o); | |
80 | - } | |
81 | - | |
82 | - public boolean add(Object o) { | |
83 | - return map.put(o, PRESENT) == null; | |
84 | - } | |
85 | - | |
86 | - public boolean remove(Object o) { | |
87 | - return map.remove(o) == PRESENT; | |
88 | - } | |
89 | - | |
90 | - public void clear() { | |
91 | - map.clear(); | |
92 | - } | |
93 | 58 | } |
@@ -17,7 +17,6 @@ | ||
17 | 17 | |
18 | 18 | import java.lang.reflect.Array; |
19 | 19 | import java.util.Arrays; |
20 | -import java.util.List; | |
21 | 20 | |
22 | 21 | /** |
23 | 22 | * 配列に対するユーティリティクラスです。 |
@@ -25,7 +24,7 @@ | ||
25 | 24 | * @author higa |
26 | 25 | * |
27 | 26 | */ |
28 | -public class ArrayUtil { | |
27 | +public class ArrayUtil extends org.seasar.util.collection.ArrayUtil { | |
29 | 28 | |
30 | 29 | /** |
31 | 30 | * インスタンスを構築します。 |
@@ -34,116 +33,6 @@ | ||
34 | 33 | } |
35 | 34 | |
36 | 35 | /** |
37 | - * 配列にオブジェクトを追加します。 | |
38 | - * | |
39 | - * @param array | |
40 | - * @param obj | |
41 | - * @return オブジェクトが追加された結果の配列 | |
42 | - */ | |
43 | - public static Object[] add(Object[] array, Object obj) { | |
44 | - return org.seasar.util.collection.ArrayUtil.add(array, obj); | |
45 | - } | |
46 | - | |
47 | - /** | |
48 | - * intの配列にintを追加します。 | |
49 | - * | |
50 | - * @param array | |
51 | - * @param value | |
52 | - * @return オブジェクトが追加された結果の配列 | |
53 | - */ | |
54 | - public static int[] add(int[] array, int value) { | |
55 | - return org.seasar.util.collection.ArrayUtil.add(array, value); | |
56 | - } | |
57 | - | |
58 | - /** | |
59 | - * 配列に配列を追加します。 | |
60 | - * | |
61 | - * @param a | |
62 | - * @param b | |
63 | - * @return 配列が追加された結果の配列 | |
64 | - */ | |
65 | - public static Object[] add(final Object[] a, final Object[] b) { | |
66 | - return org.seasar.util.collection.ArrayUtil.addAll(a, b); | |
67 | - } | |
68 | - | |
69 | - /** | |
70 | - * 配列中のオブジェクトのindexを返します。 | |
71 | - * | |
72 | - * @param array | |
73 | - * @param obj | |
74 | - * @return 配列中のオブジェクトのindex | |
75 | - */ | |
76 | - public static int indexOf(Object[] array, Object obj) { | |
77 | - return org.seasar.util.collection.ArrayUtil.indexOf(array, obj); | |
78 | - } | |
79 | - | |
80 | - /** | |
81 | - * 配列中のcharのindexを返します。 | |
82 | - * | |
83 | - * @param array | |
84 | - * @param ch | |
85 | - * @return 配列中のcharのindex | |
86 | - */ | |
87 | - public static int indexOf(char[] array, char ch) { | |
88 | - return org.seasar.util.collection.ArrayUtil.indexOf(array, ch); | |
89 | - } | |
90 | - | |
91 | - /** | |
92 | - * 配列中から対象のオブジェクトを削除します。 | |
93 | - * | |
94 | - * @param array | |
95 | - * @param obj | |
96 | - * @return 削除後の配列 | |
97 | - */ | |
98 | - public static Object[] remove(Object[] array, Object obj) { | |
99 | - return org.seasar.util.collection.ArrayUtil.remove(array, obj); | |
100 | - } | |
101 | - | |
102 | - /** | |
103 | - * 配列が空かどうかを返します。 | |
104 | - * | |
105 | - * @param arrays | |
106 | - * @return 配列が空かどうか | |
107 | - */ | |
108 | - public static boolean isEmpty(Object[] arrays) { | |
109 | - return org.seasar.util.collection.ArrayUtil.isEmpty(arrays); | |
110 | - } | |
111 | - | |
112 | - /** | |
113 | - * 配列にオブジェクトが含まれているかどうかを返します。 | |
114 | - * | |
115 | - * @param array | |
116 | - * @param obj | |
117 | - * @return 配列にオブジェクトが含まれているかどうか | |
118 | - */ | |
119 | - public static boolean contains(Object[] array, Object obj) { | |
120 | - return org.seasar.util.collection.ArrayUtil.contains(array, obj); | |
121 | - } | |
122 | - | |
123 | - /** | |
124 | - * 配列にcharが含まれているかどうかを返します。 | |
125 | - * | |
126 | - * @param array | |
127 | - * @param ch | |
128 | - * @return 配列にcharが含まれているかどうか | |
129 | - */ | |
130 | - public static boolean contains(char[] array, char ch) { | |
131 | - return org.seasar.util.collection.ArrayUtil.contains(array, ch); | |
132 | - } | |
133 | - | |
134 | - /** | |
135 | - * 順番は無視して2つの配列が等しいかどうかを返します。 | |
136 | - * | |
137 | - * @param array1 | |
138 | - * @param array2 | |
139 | - * @return 順番は無視して2つの配列が等しいかどうか | |
140 | - */ | |
141 | - public static boolean equalsIgnoreSequence(Object[] array1, Object[] array2) { | |
142 | - return org.seasar.util.collection.ArrayUtil.equalsIgnoreSequence( | |
143 | - array1, array2); | |
144 | - } | |
145 | - | |
146 | - /** | |
147 | 36 | * 配列を文字列に変換します。 |
148 | 37 | * |
149 | 38 | * @param array |
@@ -191,26 +80,4 @@ | ||
191 | 80 | Array.set(array, index, value); |
192 | 81 | } |
193 | 82 | |
194 | - /** | |
195 | - * 配列をオブジェクトの配列に変換します。 | |
196 | - * | |
197 | - * @param obj | |
198 | - * @return オブジェクトの配列 | |
199 | - */ | |
200 | - public static Object[] toObjectArray(Object obj) { | |
201 | - return org.seasar.util.collection.ArrayUtil.toObjectArray(obj); | |
202 | - } | |
203 | - | |
204 | - /** | |
205 | - * 配列をリストに変換します。 | |
206 | - * | |
207 | - * @param <T> | |
208 | - * 型 | |
209 | - * @param obj | |
210 | - * 配列 | |
211 | - * @return リスト | |
212 | - */ | |
213 | - public static <T> List<T> toList(Object obj) { | |
214 | - return org.seasar.util.collection.ArrayUtil.toList(obj); | |
215 | - } | |
216 | 83 | } |
@@ -16,7 +16,6 @@ | ||
16 | 16 | package org.seasar.framework.util; |
17 | 17 | |
18 | 18 | import java.math.BigDecimal; |
19 | -import java.text.SimpleDateFormat; | |
20 | 19 | |
21 | 20 | /** |
22 | 21 | * {@link BigDecimal}用の変換ユーティリティです。 |
@@ -24,114 +23,13 @@ | ||
24 | 23 | * @author higa |
25 | 24 | * |
26 | 25 | */ |
27 | -public class BigDecimalConversionUtil { | |
26 | +public class BigDecimalConversionUtil extends | |
27 | + org.seasar.util.convert.BigDecimalConversionUtil { | |
28 | 28 | |
29 | 29 | /** |
30 | - * Tiger用のNormalizerのクラス名です。 | |
31 | - */ | |
32 | - protected static final String TIGER_NORMALIZER_CLASS_NAME = "org.seasar.framework.util.TigerBigDecimalConversion"; | |
33 | - | |
34 | - /** | |
35 | - * デフォルトのNormalizerです。 | |
36 | - */ | |
37 | - protected static BigDecimalNormalizer normalizer = new DefaultNormalizer(); | |
38 | - static { | |
39 | - try { | |
40 | - final Class clazz = Class.forName(TIGER_NORMALIZER_CLASS_NAME); | |
41 | - normalizer = (BigDecimalNormalizer) clazz.newInstance(); | |
42 | - } catch (Exception ignore) { | |
43 | - } | |
44 | - } | |
45 | - | |
46 | - /** | |
47 | 30 | * インスタンスを構築します。 |
48 | 31 | */ |
49 | 32 | protected BigDecimalConversionUtil() { |
50 | 33 | } |
51 | 34 | |
52 | - /** | |
53 | - * {@link BigDecimal}に変換します。 | |
54 | - * | |
55 | - * @param o | |
56 | - * @return {@link BigDecimal}に変換されたデータ | |
57 | - */ | |
58 | - public static BigDecimal toBigDecimal(Object o) { | |
59 | - return toBigDecimal(o, null); | |
60 | - } | |
61 | - | |
62 | - /** | |
63 | - * {@link BigDecimal}に変換します。 | |
64 | - * | |
65 | - * @param o | |
66 | - * @param pattern | |
67 | - * @return {@link BigDecimal}に変換されたデータ | |
68 | - */ | |
69 | - public static BigDecimal toBigDecimal(Object o, String pattern) { | |
70 | - if (o == null) { | |
71 | - return null; | |
72 | - } else if (o instanceof BigDecimal) { | |
73 | - return (BigDecimal) o; | |
74 | - } else if (o instanceof java.util.Date) { | |
75 | - if (pattern != null) { | |
76 | - return new BigDecimal(new SimpleDateFormat(pattern).format(o)); | |
77 | - } | |
78 | - return new BigDecimal(Long.toString(((java.util.Date) o).getTime())); | |
79 | - } else if (o instanceof String) { | |
80 | - String s = (String) o; | |
81 | - if (StringUtil.isEmpty(s)) { | |
82 | - return null; | |
83 | - } | |
84 | - return normalizer.normalize(new BigDecimal(s)); | |
85 | - } else { | |
86 | - return normalizer.normalize(new BigDecimal(o.toString())); | |
87 | - } | |
88 | - } | |
89 | - | |
90 | - /** | |
91 | - * {@link BigDecimal}を文字列に変換します。 | |
92 | - * | |
93 | - * @param dec | |
94 | - * @return 文字列に変換されたデータ | |
95 | - */ | |
96 | - public static String toString(BigDecimal dec) { | |
97 | - return normalizer.toString(dec); | |
98 | - } | |
99 | - | |
100 | - /** | |
101 | - * {@link BigDecimal}を正規化するためのインターフェースです。 | |
102 | - * これは、Java5からtoString()のロジックが変わったことに対応するためです。 | |
103 | - * | |
104 | - */ | |
105 | - public interface BigDecimalNormalizer { | |
106 | - | |
107 | - /** | |
108 | - * 正規化します。 | |
109 | - * | |
110 | - * @param dec | |
111 | - * @return 正規化された{@link BigDecimal} | |
112 | - */ | |
113 | - BigDecimal normalize(BigDecimal dec); | |
114 | - | |
115 | - /** | |
116 | - * {@link BigDecimal}を文字列に変換します。 | |
117 | - * | |
118 | - * @param dec | |
119 | - * @return | |
120 | - */ | |
121 | - String toString(BigDecimal dec); | |
122 | - } | |
123 | - | |
124 | - /** | |
125 | - * デフォルトの{@link BigDecimalConversionUtil.BigDecimalNormalizer}の実装クラスです。 | |
126 | - * | |
127 | - */ | |
128 | - public static class DefaultNormalizer implements BigDecimalNormalizer { | |
129 | - public BigDecimal normalize(final BigDecimal dec) { | |
130 | - return dec; | |
131 | - } | |
132 | - | |
133 | - public String toString(final BigDecimal dec) { | |
134 | - return dec.toString(); | |
135 | - } | |
136 | - } | |
137 | 35 | } |
@@ -16,12 +16,11 @@ | ||
16 | 16 | package org.seasar.framework.util; |
17 | 17 | |
18 | 18 | import java.io.File; |
19 | -import java.util.Enumeration; | |
20 | -import java.util.jar.JarEntry; | |
21 | 19 | import java.util.jar.JarFile; |
22 | -import java.util.zip.ZipEntry; | |
23 | 20 | import java.util.zip.ZipInputStream; |
24 | 21 | |
22 | +import org.seasar.util.io.ClassTraversalUtil; | |
23 | + | |
25 | 24 | /** |
26 | 25 | * クラスを横断して処理するためのハンドラです。 |
27 | 26 | * <p> |
@@ -31,7 +30,7 @@ | ||
31 | 30 | * @author koichik |
32 | 31 | * @see ResourcesUtil |
33 | 32 | */ |
34 | -public class ClassTraversal { | |
33 | +public class ClassTraversal extends ClassTraversalUtil { | |
35 | 34 | private static final String CLASS_SUFFIX = ".class"; |
36 | 35 | |
37 | 36 | private static final String WAR_FILE_EXTENSION = ".war"; |
@@ -42,7 +41,7 @@ | ||
42 | 41 | * クラスを横断して処理するためのハンドラです。 |
43 | 42 | * |
44 | 43 | */ |
45 | - public interface ClassHandler { | |
44 | + public interface ClassHandler extends org.seasar.util.io.ClassHandler { | |
46 | 45 | /** |
47 | 46 | * クラスを処理します。 |
48 | 47 | * |
@@ -59,7 +58,7 @@ | ||
59 | 58 | * @param handler |
60 | 59 | */ |
61 | 60 | public static void forEach(final File rootDir, final ClassHandler handler) { |
62 | - forEach(rootDir, null, handler); | |
61 | + ClassTraversalUtil.forEach(rootDir, handler); | |
63 | 62 | } |
64 | 63 | |
65 | 64 | /** |
@@ -74,10 +73,7 @@ | ||
74 | 73 | */ |
75 | 74 | public static void forEach(final File rootDir, final String rootPackage, |
76 | 75 | final ClassHandler handler) { |
77 | - final File packageDir = getPackageDir(rootDir, rootPackage); | |
78 | - if (packageDir.exists()) { | |
79 | - traverseFileSystem(packageDir, rootPackage, handler); | |
80 | - } | |
76 | + ClassTraversalUtil.forEach(rootDir, rootPackage, handler); | |
81 | 77 | } |
82 | 78 | |
83 | 79 | /** |
@@ -96,11 +92,7 @@ | ||
96 | 92 | * クラスを処理するハンドラ |
97 | 93 | */ |
98 | 94 | public static void forEach(final JarFile jarFile, final ClassHandler handler) { |
99 | - if (jarFile.getName().toLowerCase().endsWith(WAR_FILE_EXTENSION)) { | |
100 | - forEach(jarFile, WEB_INF_CLASSES_PATH, handler); | |
101 | - } else { | |
102 | - forEach(jarFile, "", handler); | |
103 | - } | |
95 | + ClassTraversalUtil.forEach(jarFile, handler); | |
104 | 96 | } |
105 | 97 | |
106 | 98 | /** |
@@ -121,24 +113,7 @@ | ||
121 | 113 | */ |
122 | 114 | public static void forEach(final JarFile jarFile, final String prefix, |
123 | 115 | final ClassHandler handler) { |
124 | - final int startPos = prefix.length(); | |
125 | - final Enumeration enumeration = jarFile.entries(); | |
126 | - while (enumeration.hasMoreElements()) { | |
127 | - final JarEntry entry = (JarEntry) enumeration.nextElement(); | |
128 | - final String entryName = entry.getName().replace('\\', '/'); | |
129 | - if (entryName.startsWith(prefix) | |
130 | - && entryName.endsWith(CLASS_SUFFIX)) { | |
131 | - final String className = entryName.substring(startPos, | |
132 | - entryName.length() - CLASS_SUFFIX.length()).replace( | |
133 | - '/', '.'); | |
134 | - final int pos = className.lastIndexOf('.'); | |
135 | - final String packageName = (pos == -1) ? null : className | |
136 | - .substring(0, pos); | |
137 | - final String shortClassName = (pos == -1) ? className | |
138 | - : className.substring(pos + 1); | |
139 | - handler.processClass(packageName, shortClassName); | |
140 | - } | |
141 | - } | |
116 | + ClassTraversalUtil.forEach(jarFile, prefix, handler); | |
142 | 117 | } |
143 | 118 | |
144 | 119 | /** |
@@ -153,7 +128,7 @@ | ||
153 | 128 | */ |
154 | 129 | public static void forEach(final ZipInputStream zipInputStream, |
155 | 130 | final ClassHandler handler) { |
156 | - forEach(zipInputStream, "", handler); | |
131 | + ClassTraversalUtil.forEach(zipInputStream, handler); | |
157 | 132 | } |
158 | 133 | |
159 | 134 | /** |
@@ -174,56 +149,7 @@ | ||
174 | 149 | */ |
175 | 150 | public static void forEach(final ZipInputStream zipInputStream, |
176 | 151 | final String prefix, final ClassHandler handler) { |
177 | - final int startPos = prefix.length(); | |
178 | - ZipEntry entry = null; | |
179 | - while ((entry = ZipInputStreamUtil.getNextEntry(zipInputStream)) != null) { | |
180 | - try { | |
181 | - final String entryName = entry.getName().replace('\\', '/'); | |
182 | - if (entryName.startsWith(prefix) | |
183 | - && entryName.endsWith(CLASS_SUFFIX)) { | |
184 | - final String className = entryName.substring(startPos, | |
185 | - entryName.length() - CLASS_SUFFIX.length()) | |
186 | - .replace('/', '.'); | |
187 | - final int pos = className.lastIndexOf('.'); | |
188 | - final String packageName = (pos == -1) ? null : className | |
189 | - .substring(0, pos); | |
190 | - final String shortClassName = (pos == -1) ? className | |
191 | - : className.substring(pos + 1); | |
192 | - handler.processClass(packageName, shortClassName); | |
193 | - } | |
194 | - } finally { | |
195 | - ZipInputStreamUtil.closeEntry(zipInputStream); | |
196 | - } | |
197 | - } | |
152 | + ClassTraversalUtil.forEach(zipInputStream, prefix, handler); | |
198 | 153 | } |
199 | 154 | |
200 | - private static void traverseFileSystem(final File dir, | |
201 | - final String packageName, final ClassHandler handler) { | |
202 | - final File[] files = dir.listFiles(); | |
203 | - for (int i = 0; i < files.length; ++i) { | |
204 | - final File file = files[i]; | |
205 | - final String fileName = file.getName(); | |
206 | - if (file.isDirectory()) { | |
207 | - traverseFileSystem(file, ClassUtil.concatName(packageName, | |
208 | - fileName), handler); | |
209 | - } else if (fileName.endsWith(".class")) { | |
210 | - final String shortClassName = fileName.substring(0, fileName | |
211 | - .length() | |
212 | - - CLASS_SUFFIX.length()); | |
213 | - handler.processClass(packageName, shortClassName); | |
214 | - } | |
215 | - } | |
216 | - } | |
217 | - | |
218 | - private static File getPackageDir(final File rootDir, | |
219 | - final String rootPackage) { | |
220 | - File packageDir = rootDir; | |
221 | - if (rootPackage != null) { | |
222 | - final String[] names = rootPackage.split("\\."); | |
223 | - for (int i = 0; i < names.length; i++) { | |
224 | - packageDir = new File(packageDir, names[i]); | |
225 | - } | |
226 | - } | |
227 | - return packageDir; | |
228 | - } | |
229 | 155 | } |
@@ -15,23 +15,12 @@ | ||
15 | 15 | */ |
16 | 16 | package org.seasar.framework.util; |
17 | 17 | |
18 | -import java.lang.reflect.Constructor; | |
19 | 18 | import java.lang.reflect.Field; |
20 | -import java.lang.reflect.Method; | |
21 | -import java.util.HashMap; | |
22 | -import java.util.Map; | |
23 | 19 | |
24 | 20 | import javassist.ClassPool; |
25 | 21 | import javassist.CtClass; |
26 | 22 | import javassist.CtField; |
27 | 23 | |
28 | -import org.seasar.framework.exception.ClassNotFoundRuntimeException; | |
29 | -import org.seasar.framework.exception.IllegalAccessRuntimeException; | |
30 | -import org.seasar.framework.exception.InstantiationRuntimeException; | |
31 | -import org.seasar.framework.exception.NoSuchConstructorRuntimeException; | |
32 | -import org.seasar.framework.exception.NoSuchFieldRuntimeException; | |
33 | -import org.seasar.framework.exception.NoSuchMethodRuntimeException; | |
34 | - | |
35 | 24 | /** |
36 | 25 | * {@link Class}用のユーティリティクラスです。 |
37 | 26 | * |
@@ -38,43 +27,8 @@ | ||
38 | 27 | * @author higa |
39 | 28 | * |
40 | 29 | */ |
41 | -public class ClassUtil { | |
30 | +public class ClassUtil extends org.seasar.util.lang.ClassUtil { | |
42 | 31 | |
43 | - private static Map wrapperToPrimitiveMap = new HashMap(); | |
44 | - | |
45 | - private static Map primitiveToWrapperMap = new HashMap(); | |
46 | - | |
47 | - private static Map primitiveClassNameMap = new HashMap(); | |
48 | - | |
49 | - static { | |
50 | - wrapperToPrimitiveMap.put(Character.class, Character.TYPE); | |
51 | - wrapperToPrimitiveMap.put(Byte.class, Byte.TYPE); | |
52 | - wrapperToPrimitiveMap.put(Short.class, Short.TYPE); | |
53 | - wrapperToPrimitiveMap.put(Integer.class, Integer.TYPE); | |
54 | - wrapperToPrimitiveMap.put(Long.class, Long.TYPE); | |
55 | - wrapperToPrimitiveMap.put(Double.class, Double.TYPE); | |
56 | - wrapperToPrimitiveMap.put(Float.class, Float.TYPE); | |
57 | - wrapperToPrimitiveMap.put(Boolean.class, Boolean.TYPE); | |
58 | - | |
59 | - primitiveToWrapperMap.put(Character.TYPE, Character.class); | |
60 | - primitiveToWrapperMap.put(Byte.TYPE, Byte.class); | |
61 | - primitiveToWrapperMap.put(Short.TYPE, Short.class); | |
62 | - primitiveToWrapperMap.put(Integer.TYPE, Integer.class); | |
63 | - primitiveToWrapperMap.put(Long.TYPE, Long.class); | |
64 | - primitiveToWrapperMap.put(Double.TYPE, Double.class); | |
65 | - primitiveToWrapperMap.put(Float.TYPE, Float.class); | |
66 | - primitiveToWrapperMap.put(Boolean.TYPE, Boolean.class); | |
67 | - | |
68 | - primitiveClassNameMap.put(Character.TYPE.getName(), Character.TYPE); | |
69 | - primitiveClassNameMap.put(Byte.TYPE.getName(), Byte.TYPE); | |
70 | - primitiveClassNameMap.put(Short.TYPE.getName(), Short.TYPE); | |
71 | - primitiveClassNameMap.put(Integer.TYPE.getName(), Integer.TYPE); | |
72 | - primitiveClassNameMap.put(Long.TYPE.getName(), Long.TYPE); | |
73 | - primitiveClassNameMap.put(Double.TYPE.getName(), Double.TYPE); | |
74 | - primitiveClassNameMap.put(Float.TYPE.getName(), Float.TYPE); | |
75 | - primitiveClassNameMap.put(Boolean.TYPE.getName(), Boolean.TYPE); | |
76 | - } | |
77 | - | |
78 | 32 | /** |
79 | 33 | * |
80 | 34 | */ |
@@ -82,273 +36,17 @@ | ||
82 | 36 | } |
83 | 37 | |
84 | 38 | /** |
85 | - * {@link Class}を返します。 | |
39 | + * FQCNからパッケージ名を除いた名前を返します。 | |
86 | 40 | * |
87 | - * @param className | |
88 | - * @return {@link Class} | |
89 | - * @throws ClassNotFoundRuntimeException | |
90 | - * {@link ClassNotFoundException}がおきた場合 | |
91 | - * @see Class#forName(String) | |
92 | - */ | |
93 | - public static Class forName(String className) | |
94 | - throws ClassNotFoundRuntimeException { | |
95 | - | |
96 | - ClassLoader loader = Thread.currentThread().getContextClassLoader(); | |
97 | - try { | |
98 | - return Class.forName(className, true, loader); | |
99 | - } catch (ClassNotFoundException ex) { | |
100 | - throw new ClassNotFoundRuntimeException(className, ex); | |
101 | - } | |
102 | - } | |
103 | - | |
104 | - /** | |
105 | - * プリミティブクラスの場合は、ラッパークラスに変換して返します。 | |
106 | - * | |
107 | - * @param className | |
108 | - * @return {@link Class} | |
109 | - * @throws ClassNotFoundRuntimeException | |
110 | - * {@link ClassNotFoundException}がおきた場合 | |
111 | - * @see #forName(String) | |
112 | - */ | |
113 | - public static Class convertClass(String className) | |
114 | - throws ClassNotFoundRuntimeException { | |
115 | - Class clazz = (Class) primitiveClassNameMap.get(className); | |
116 | - if (clazz != null) { | |
117 | - return clazz; | |
118 | - } | |
119 | - return forName(className); | |
120 | - } | |
121 | - | |
122 | - /** | |
123 | - * 新しいインスタンスを作成します。 | |
124 | - * | |
125 | 41 | * @param clazz |
126 | - * @return 新しいインスタンス | |
127 | - * @throws InstantiationRuntimeException | |
128 | - * {@link InstantiationException}がおきた場合 | |
129 | - * @throws IllegalAccessRuntimeException | |
130 | - * {@link IllegalAccessException}がおきた場合 | |
131 | - * @see Class#newInstance() | |
42 | + * @return FQCNからパッケージ名を除いた名前 | |
43 | + * @see #getShortClassName(String) | |
132 | 44 | */ |
133 | - public static Object newInstance(Class clazz) | |
134 | - throws InstantiationRuntimeException, IllegalAccessRuntimeException { | |
135 | - | |
136 | - try { | |
137 | - return clazz.newInstance(); | |
138 | - } catch (InstantiationException ex) { | |
139 | - throw new InstantiationRuntimeException(clazz, ex); | |
140 | - } catch (IllegalAccessException ex) { | |
141 | - throw new IllegalAccessRuntimeException(clazz, ex); | |
142 | - } | |
45 | + public static String getShortClassName(Class<?> clazz) { | |
46 | + return getShortClassName(clazz.getName()); | |
143 | 47 | } |
144 | 48 | |
145 | 49 | /** |
146 | - * 新しいインスタンスを作成します。 | |
147 | - * | |
148 | - * @param className | |
149 | - * @return 新しいインスタンス | |
150 | - * @throws ClassNotFoundRuntimeException | |
151 | - * {@link ClassNotFoundException}がおきた場合 | |
152 | - * @throws InstantiationRuntimeException | |
153 | - * {@link InstantiationException}がおきた場合 | |
154 | - * @throws IllegalAccessRuntimeException | |
155 | - * {@link IllegalAccessException}がおきた場合 | |
156 | - * @see #newInstance(Class) | |
157 | - */ | |
158 | - public static Object newInstance(String className) | |
159 | - throws ClassNotFoundRuntimeException, | |
160 | - InstantiationRuntimeException, IllegalAccessRuntimeException { | |
161 | - | |
162 | - return newInstance(forName(className)); | |
163 | - } | |
164 | - | |
165 | - /** | |
166 | - * 代入可能かどうかを返します。 | |
167 | - * | |
168 | - * @param toClass | |
169 | - * @param fromClass | |
170 | - * @return 代入可能かどうか | |
171 | - * @see Class#isAssignableFrom(Class) | |
172 | - */ | |
173 | - public static boolean isAssignableFrom(Class toClass, Class fromClass) { | |
174 | - if (toClass == Object.class && !fromClass.isPrimitive()) { | |
175 | - return true; | |
176 | - } | |
177 | - if (toClass.isPrimitive()) { | |
178 | - fromClass = getPrimitiveClassIfWrapper(fromClass); | |
179 | - } | |
180 | - return toClass.isAssignableFrom(fromClass); | |
181 | - } | |
182 | - | |
183 | - /** | |
184 | - * ラッパークラスをプリミティブクラスに変換します。 | |
185 | - * | |
186 | - * @param clazz | |
187 | - * @return プリミティブクラス | |
188 | - */ | |
189 | - public static Class getPrimitiveClass(Class clazz) { | |
190 | - return (Class) wrapperToPrimitiveMap.get(clazz); | |
191 | - } | |
192 | - | |
193 | - /** | |
194 | - * ラッパークラスならプリミティブクラスに、 そうでなければそのままクラスを返します。 | |
195 | - * | |
196 | - * @param clazz | |
197 | - * @return {@link Class} | |
198 | - */ | |
199 | - public static Class getPrimitiveClassIfWrapper(Class clazz) { | |
200 | - Class ret = getPrimitiveClass(clazz); | |
201 | - if (ret != null) { | |
202 | - return ret; | |
203 | - } | |
204 | - return clazz; | |
205 | - } | |
206 | - | |
207 | - /** | |
208 | - * プリミティブクラスをラッパークラスに変換します。 | |
209 | - * | |
210 | - * @param clazz | |
211 | - * @return {@link Class} | |
212 | - */ | |
213 | - public static Class getWrapperClass(Class clazz) { | |
214 | - return (Class) primitiveToWrapperMap.get(clazz); | |
215 | - } | |
216 | - | |
217 | - /** | |
218 | - * プリミティブの場合はラッパークラス、そうでない場合はもとのクラスを返します。 | |
219 | - * | |
220 | - * @param clazz | |
221 | - * @return {@link Class} | |
222 | - */ | |
223 | - public static Class getWrapperClassIfPrimitive(Class clazz) { | |
224 | - Class ret = getWrapperClass(clazz); | |
225 | - if (ret != null) { | |
226 | - return ret; | |
227 | - } | |
228 | - return clazz; | |
229 | - } | |
230 | - | |
231 | - /** | |
232 | - * {@link Constructor}を返します。 | |
233 | - * | |
234 | - * @param clazz | |
235 | - * @param argTypes | |
236 | - * @return {@link Constructor} | |
237 | - * @throws NoSuchConstructorRuntimeException | |
238 | - * {@link NoSuchMethodException}がおきた場合 | |
239 | - * @see Class#getConstructor(Class[]) | |
240 | - */ | |
241 | - public static Constructor getConstructor(Class clazz, Class[] argTypes) | |
242 | - throws NoSuchConstructorRuntimeException { | |
243 | - try { | |
244 | - return clazz.getConstructor(argTypes); | |
245 | - } catch (NoSuchMethodException ex) { | |
246 | - throw new NoSuchConstructorRuntimeException(clazz, argTypes, ex); | |
247 | - } | |
248 | - } | |
249 | - | |
250 | - /** | |
251 | - * そのクラスに宣言されている {@link Constructor}を返します。 | |
252 | - * | |
253 | - * @param clazz | |
254 | - * @param argTypes | |
255 | - * @return {@link Constructor} | |
256 | - * @throws NoSuchConstructorRuntimeException | |
257 | - * {@link NoSuchMethodException}がおきた場合 | |
258 | - * @see Class#getDeclaredConstructor(Class[]) | |
259 | - */ | |
260 | - public static Constructor getDeclaredConstructor(Class clazz, | |
261 | - Class[] argTypes) throws NoSuchConstructorRuntimeException { | |
262 | - try { | |
263 | - return clazz.getDeclaredConstructor(argTypes); | |
264 | - } catch (NoSuchMethodException ex) { | |
265 | - throw new NoSuchConstructorRuntimeException(clazz, argTypes, ex); | |
266 | - } | |
267 | - } | |
268 | - | |
269 | - /** | |
270 | - * {@link Method}を返します。 | |
271 | - * | |
272 | - * @param clazz | |
273 | - * @param methodName | |
274 | - * @param argTypes | |
275 | - * @return {@link Method} | |
276 | - * @throws NoSuchMethodRuntimeException | |
277 | - * {@link NoSuchMethodException}がおきた場合 | |
278 | - * @see Class#getMethod(String, Class[]) | |
279 | - */ | |
280 | - public static Method getMethod(Class clazz, String methodName, | |
281 | - Class[] argTypes) throws NoSuchMethodRuntimeException { | |
282 | - | |
283 | - try { | |
284 | - return clazz.getMethod(methodName, argTypes); | |
285 | - } catch (NoSuchMethodException ex) { | |
286 | - throw new NoSuchMethodRuntimeException(clazz, methodName, argTypes, | |
287 | - ex); | |
288 | - } | |
289 | - } | |
290 | - | |
291 | - /** | |
292 | - * そのクラスに宣言されている {@link Method}を返します。 | |
293 | - * | |
294 | - * @param clazz | |
295 | - * @param methodName | |
296 | - * @param argTypes | |
297 | - * @return {@link Method} | |
298 | - * @throws NoSuchMethodRuntimeException | |
299 | - * {@link NoSuchMethodException}がおきた場合 | |
300 | - * @see Class#getDeclaredMethod(String, Class[]) | |
301 | - */ | |
302 | - public static Method getDeclaredMethod(Class clazz, String methodName, | |
303 | - Class[] argTypes) throws NoSuchMethodRuntimeException { | |
304 | - | |
305 | - try { | |
306 | - return clazz.getDeclaredMethod(methodName, argTypes); | |
307 | - } catch (NoSuchMethodException ex) { | |
308 | - throw new NoSuchMethodRuntimeException(clazz, methodName, argTypes, | |
309 | - ex); | |
310 | - } | |
311 | - } | |
312 | - | |
313 | - /** | |
314 | - * {@link Field}を返します。 | |
315 | - * | |
316 | - * @param clazz | |
317 | - * @param fieldName | |
318 | - * @return {@link Field} | |
319 | - * @throws NoSuchFieldRuntimeException | |
320 | - * {@link NoSuchFieldException}がおきた場合 | |
321 | - * @see Class#getField(String) | |
322 | - */ | |
323 | - public static Field getField(Class clazz, String fieldName) | |
324 | - throws NoSuchFieldRuntimeException { | |
325 | - try { | |
326 | - return clazz.getField(fieldName); | |
327 | - } catch (NoSuchFieldException ex) { | |
328 | - throw new NoSuchFieldRuntimeException(clazz, fieldName, ex); | |
329 | - } | |
330 | - } | |
331 | - | |
332 | - /** | |
333 | - * そのクラスに宣言されている {@link Field}を返します。 | |
334 | - * | |
335 | - * @param clazz | |
336 | - * @param fieldName | |
337 | - * @return {@link Field} | |
338 | - * @throws NoSuchFieldRuntimeException | |
339 | - * {@link NoSuchFieldException}がおきた場合 | |
340 | - * @see Class#getDeclaredField(String) | |
341 | - */ | |
342 | - public static Field getDeclaredField(Class clazz, String fieldName) | |
343 | - throws NoSuchFieldRuntimeException { | |
344 | - try { | |
345 | - return clazz.getDeclaredField(fieldName); | |
346 | - } catch (NoSuchFieldException ex) { | |
347 | - throw new NoSuchFieldRuntimeException(clazz, fieldName, ex); | |
348 | - } | |
349 | - } | |
350 | - | |
351 | - /** | |
352 | 50 | * このクラスに定義された{@link Field フィールド}をクラスファイルに定義された順番で返します。 |
353 | 51 | * |
354 | 52 | * @param clazz |
@@ -355,7 +53,7 @@ | ||
355 | 53 | * 対象のクラス |
356 | 54 | * @return このクラスに定義されたフィールドの配列 |
357 | 55 | */ |
358 | - public static Field[] getDeclaredFields(final Class clazz) { | |
56 | + public static Field[] getDeclaredFields(final Class<?> clazz) { | |
359 | 57 | final ClassPool pool = ClassPoolUtil.getClassPool(clazz); |
360 | 58 | final CtClass ctClass = ClassPoolUtil.toCtClass(pool, clazz); |
361 | 59 | final CtField[] ctFields = ctClass.getDeclaredFields(); |
@@ -362,121 +60,9 @@ | ||
362 | 60 | final int size = ctFields.length; |
363 | 61 | final Field[] fields = new Field[size]; |
364 | 62 | for (int i = 0; i < size; ++i) { |
365 | - fields[i] = ClassUtil | |
366 | - .getDeclaredField(clazz, ctFields[i].getName()); | |
63 | + fields[i] = getDeclaredField(clazz, ctFields[i].getName()); | |
367 | 64 | } |
368 | 65 | return fields; |
369 | 66 | } |
370 | 67 | |
371 | - /** | |
372 | - * パッケージ名を返します。 | |
373 | - * | |
374 | - * @param clazz | |
375 | - * @return パッケージ名 | |
376 | - */ | |
377 | - public static String getPackageName(Class clazz) { | |
378 | - String fqcn = clazz.getName(); | |
379 | - int pos = fqcn.lastIndexOf('.'); | |
380 | - if (pos > 0) { | |
381 | - return fqcn.substring(0, pos); | |
382 | - } | |
383 | - return null; | |
384 | - } | |
385 | - | |
386 | - /** | |
387 | - * FQCNからパッケージ名を除いた名前を返します。 | |
388 | - * | |
389 | - * @param clazz | |
390 | - * @return FQCNからパッケージ名を除いた名前 | |
391 | - * @see #getShortClassName(String) | |
392 | - */ | |
393 | - public static String getShortClassName(Class clazz) { | |
394 | - return getShortClassName(clazz.getName()); | |
395 | - } | |
396 | - | |
397 | - /** | |
398 | - * FQCNからパッケージ名を除いた名前を返します。 | |
399 | - * | |
400 | - * @param className | |
401 | - * @return FQCNからパッケージ名を除いた名前 | |
402 | - */ | |
403 | - public static String getShortClassName(String className) { | |
404 | - int i = className.lastIndexOf('.'); | |
405 | - if (i > 0) { | |
406 | - return className.substring(i + 1); | |
407 | - } | |
408 | - return className; | |
409 | - } | |
410 | - | |
411 | - /** | |
412 | - * FQCNをパッケージ名とFQCNからパッケージ名を除いた名前に分けます。 | |
413 | - * | |
414 | - * @param className | |
415 | - * @return パッケージ名とFQCNからパッケージ名を除いた名前 | |
416 | - */ | |
417 | - public static String[] splitPackageAndShortClassName(String className) { | |
418 | - String[] ret = new String[2]; | |
419 | - int i = className.lastIndexOf('.'); | |
420 | - if (i > 0) { | |
421 | - ret[0] = className.substring(0, i); | |
422 | - ret[1] = className.substring(i + 1); | |
423 | - } else { | |
424 | - ret[1] = className; | |
425 | - } | |
426 | - return ret; | |
427 | - } | |
428 | - | |
429 | - /** | |
430 | - * 配列の場合は要素のクラス名、それ以外はクラス名そのものを返します。 | |
431 | - * | |
432 | - * @param clazz | |
433 | - * @return クラス名 | |
434 | - */ | |
435 | - public static String getSimpleClassName(final Class clazz) { | |
436 | - if (clazz.isArray()) { | |
437 | - return getSimpleClassName(clazz.getComponentType()) + "[]"; | |
438 | - } | |
439 | - return clazz.getName(); | |
440 | - } | |
441 | - | |
442 | - /** | |
443 | - * クラス名をリソースパスとして表現します。 | |
444 | - * | |
445 | - * @param clazz | |
446 | - * @return リソースパス | |
447 | - * @see #getResourcePath(String) | |
448 | - */ | |
449 | - public static String getResourcePath(Class clazz) { | |
450 | - return getResourcePath(clazz.getName()); | |
451 | - } | |
452 | - | |
453 | - /** | |
454 | - * クラス名をリソースパスとして表現します。 | |
455 | - * | |
456 | - * @param className | |
457 | - * @return リソースパス | |
458 | - */ | |
459 | - public static String getResourcePath(String className) { | |
460 | - return StringUtil.replace(className, ".", "/") + ".class"; | |
461 | - } | |
462 | - | |
463 | - /** | |
464 | - * クラス名の要素を結合します。 | |
465 | - * | |
466 | - * @param s1 | |
467 | - * @param s2 | |
468 | - * @return 結合された名前 | |
469 | - */ | |
470 | - public static String concatName(String s1, String s2) { | |
471 | - if (StringUtil.isEmpty(s1) && StringUtil.isEmpty(s2)) { | |
472 | - return null; | |
473 | - } | |
474 | - if (!StringUtil.isEmpty(s1) && StringUtil.isEmpty(s2)) { | |
475 | - return s1; | |
476 | - } | |
477 | - if (StringUtil.isEmpty(s1) && !StringUtil.isEmpty(s2)) { | |
478 | - return s2; | |
479 | - } | |
480 | - return s1 + '.' + s2; | |
481 | - } | |
482 | 68 | } |
@@ -22,7 +22,7 @@ | ||
22 | 22 | * |
23 | 23 | * @author shot |
24 | 24 | */ |
25 | -public class AssertionUtil { | |
25 | +public class AssertionUtil extends org.seasar.util.misc.AssertionUtil { | |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * インスタンスを構築します。 |
@@ -40,9 +40,7 @@ | ||
40 | 40 | */ |
41 | 41 | public static void assertNotNull(String message, Object obj) |
42 | 42 | throws NullPointerException { |
43 | - if (obj == null) { | |
44 | - throw new NullPointerException(message); | |
45 | - } | |
43 | + org.seasar.util.misc.AssertionUtil.assertArgumentNotNull(message, obj); | |
46 | 44 | } |
47 | 45 | |
48 | 46 | /** |
@@ -55,9 +53,7 @@ | ||
55 | 53 | */ |
56 | 54 | public static void assertNotEmpty(String message, String s) |
57 | 55 | throws EmptyRuntimeException { |
58 | - if (StringUtil.isEmpty(s)) { | |
59 | - throw new EmptyRuntimeException(message); | |
60 | - } | |
56 | + org.seasar.util.misc.AssertionUtil.assertArgumentNotEmpty(message, s); | |
61 | 57 | } |
62 | 58 | |
63 | 59 | /** |
@@ -70,6 +66,7 @@ | ||
70 | 66 | */ |
71 | 67 | public static void assertIntegerNotNegative(String message, int num) |
72 | 68 | throws IllegalArgumentException { |
69 | + // TODO not found | |
73 | 70 | if (num < 0) { |
74 | 71 | throw new IllegalArgumentException(message); |
75 | 72 | } |
@@ -21,155 +21,6 @@ | ||
21 | 21 | * @author higa |
22 | 22 | * |
23 | 23 | */ |
24 | -public class Base64Util { | |
24 | +public class Base64Util extends org.seasar.util.misc.Base64Util { | |
25 | 25 | |
26 | - private static final char[] ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', | |
27 | - 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', | |
28 | - 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', | |
29 | - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', | |
30 | - 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', | |
31 | - '6', '7', '8', '9', '+', '/' }; | |
32 | - | |
33 | - private static final char PAD = '='; | |
34 | - | |
35 | - private static final byte[] DECODE_TABLE = new byte[128]; | |
36 | - static { | |
37 | - for (int i = 0; i < DECODE_TABLE.length; i++) { | |
38 | - DECODE_TABLE[i] = Byte.MAX_VALUE; | |
39 | - } | |
40 | - for (int i = 0; i < ENCODE_TABLE.length; i++) { | |
41 | - DECODE_TABLE[ENCODE_TABLE[i]] = (byte) i; | |
42 | - } | |
43 | - } | |
44 | - | |
45 | - /** | |
46 | - * Base64でエンコードします。 | |
47 | - * | |
48 | - * @param inData | |
49 | - * @return エンコードされたデータ | |
50 | - */ | |
51 | - public static String encode(final byte[] inData) { | |
52 | - if (inData == null || inData.length == 0) { | |
53 | - return ""; | |
54 | - } | |
55 | - int mod = inData.length % 3; | |
56 | - int num = inData.length / 3; | |
57 | - char[] outData = null; | |
58 | - if (mod != 0) { | |
59 | - outData = new char[(num + 1) * 4]; | |
60 | - } else { | |
61 | - outData = new char[num * 4]; | |
62 | - } | |
63 | - for (int i = 0; i < num; i++) { | |
64 | - encode(inData, i * 3, outData, i * 4); | |
65 | - } | |
66 | - switch (mod) { | |
67 | - case 1: | |
68 | - encode2pad(inData, num * 3, outData, num * 4); | |
69 | - break; | |
70 | - case 2: | |
71 | - encode1pad(inData, num * 3, outData, num * 4); | |
72 | - break; | |
73 | - } | |
74 | - return new String(outData); | |
75 | - } | |
76 | - | |
77 | - /** | |
78 | - * Base64でエンコードされたデータをデコードします。 | |
79 | - * | |
80 | - * @param inData | |
81 | - * @return デコードされたデータ | |
82 | - */ | |
83 | - public static byte[] decode(final String inData) { | |
84 | - int num = (inData.length() / 4) - 1; | |
85 | - int lastBytes = getLastBytes(inData); | |
86 | - byte[] outData = new byte[num * 3 + lastBytes]; | |
87 | - for (int i = 0; i < num; i++) { | |
88 | - decode(inData, i * 4, outData, i * 3); | |
89 | - } | |
90 | - switch (lastBytes) { | |
91 | - case 1: | |
92 | - decode1byte(inData, num * 4, outData, num * 3); | |
93 | - break; | |
94 | - case 2: | |
95 | - decode2byte(inData, num * 4, outData, num * 3); | |
96 | - break; | |
97 | - default: | |
98 | - decode(inData, num * 4, outData, num * 3); | |
99 | - } | |
100 | - return outData; | |
101 | - } | |
102 | - | |
103 | - private static void encode(final byte[] inData, final int inIndex, | |
104 | - final char[] outData, final int outIndex) { | |
105 | - | |
106 | - int i = ((inData[inIndex] & 0xff) << 16) | |
107 | - + ((inData[inIndex + 1] & 0xff) << 8) | |
108 | - + (inData[inIndex + 2] & 0xff); | |
109 | - outData[outIndex] = ENCODE_TABLE[i >> 18]; | |
110 | - outData[outIndex + 1] = ENCODE_TABLE[(i >> 12) & 0x3f]; | |
111 | - outData[outIndex + 2] = ENCODE_TABLE[(i >> 6) & 0x3f]; | |
112 | - outData[outIndex + 3] = ENCODE_TABLE[i & 0x3f]; | |
113 | - } | |
114 | - | |
115 | - private static void encode2pad(final byte[] inData, final int inIndex, | |
116 | - final char[] outData, final int outIndex) { | |
117 | - | |
118 | - int i = inData[inIndex] & 0xff; | |
119 | - outData[outIndex] = ENCODE_TABLE[i >> 2]; | |
120 | - outData[outIndex + 1] = ENCODE_TABLE[(i << 4) & 0x3f]; | |
121 | - outData[outIndex + 2] = PAD; | |
122 | - outData[outIndex + 3] = PAD; | |
123 | - } | |
124 | - | |
125 | - private static void encode1pad(final byte[] inData, final int inIndex, | |
126 | - final char[] outData, final int outIndex) { | |
127 | - | |
128 | - int i = ((inData[inIndex] & 0xff) << 8) + (inData[inIndex + 1] & 0xff); | |
129 | - outData[outIndex] = ENCODE_TABLE[i >> 10]; | |
130 | - outData[outIndex + 1] = ENCODE_TABLE[(i >> 4) & 0x3f]; | |
131 | - outData[outIndex + 2] = ENCODE_TABLE[(i << 2) & 0x3f]; | |
132 | - outData[outIndex + 3] = PAD; | |
133 | - } | |
134 | - | |
135 | - private static void decode(final String inData, final int inIndex, | |
136 | - final byte[] outData, final int outIndex) { | |
137 | - | |
138 | - byte b0 = DECODE_TABLE[inData.charAt(inIndex)]; | |
139 | - byte b1 = DECODE_TABLE[inData.charAt(inIndex + 1)]; | |
140 | - byte b2 = DECODE_TABLE[inData.charAt(inIndex + 2)]; | |
141 | - byte b3 = DECODE_TABLE[inData.charAt(inIndex + 3)]; | |
142 | - outData[outIndex] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); | |
143 | - outData[outIndex + 1] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf); | |
144 | - outData[outIndex + 2] = (byte) (b2 << 6 & 0xc0 | b3 & 0x3f); | |
145 | - } | |
146 | - | |
147 | - private static void decode1byte(final String inData, final int inIndex, | |
148 | - final byte[] outData, final int outIndex) { | |
149 | - | |
150 | - byte b0 = DECODE_TABLE[inData.charAt(inIndex)]; | |
151 | - byte b1 = DECODE_TABLE[inData.charAt(inIndex + 1)]; | |
152 | - outData[outIndex] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); | |
153 | - } | |
154 | - | |
155 | - private static void decode2byte(final String inData, final int inIndex, | |
156 | - final byte[] outData, final int outIndex) { | |
157 | - | |
158 | - byte b0 = DECODE_TABLE[inData.charAt(inIndex)]; | |
159 | - byte b1 = DECODE_TABLE[inData.charAt(inIndex + 1)]; | |
160 | - byte b2 = DECODE_TABLE[inData.charAt(inIndex + 2)]; | |
161 | - outData[outIndex] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); | |
162 | - outData[outIndex + 1] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf); | |
163 | - } | |
164 | - | |
165 | - private static int getLastBytes(final String inData) { | |
166 | - int len = inData.length(); | |
167 | - if (inData.charAt(len - 2) == PAD) { | |
168 | - return 1; | |
169 | - } else if (inData.charAt(len - 1) == PAD) { | |
170 | - return 2; | |
171 | - } else { | |
172 | - return 3; | |
173 | - } | |
174 | - } | |
175 | 26 | } |
\ No newline at end of file |
@@ -23,7 +23,8 @@ | ||
23 | 23 | * @author higa |
24 | 24 | * |
25 | 25 | */ |
26 | -public class BigIntegerConversionUtil { | |
26 | +public class BigIntegerConversionUtil extends | |
27 | + org.seasar.util.convert.BigIntegerConversionUtil { | |
27 | 28 | |
28 | 29 | /** |
29 | 30 | * インスタンスを構築します。 |
@@ -31,34 +32,4 @@ | ||
31 | 32 | protected BigIntegerConversionUtil() { |
32 | 33 | } |
33 | 34 | |
34 | - /** | |
35 | - * {@link BigInteger}に変換します。 | |
36 | - * | |
37 | - * @param o | |
38 | - * @return {@link BigInteger} | |
39 | - */ | |
40 | - public static BigInteger toBigInteger(Object o) { | |
41 | - return toBigInteger(o, null); | |
42 | - } | |
43 | - | |
44 | - /** | |
45 | - * {@link BigInteger}に変換します。 | |
46 | - * | |
47 | - * @param o | |
48 | - * @param pattern | |
49 | - * @return {@link BigInteger} | |
50 | - */ | |
51 | - public static BigInteger toBigInteger(Object o, String pattern) { | |
52 | - if (o == null) { | |
53 | - return null; | |
54 | - } else if (o instanceof BigInteger) { | |
55 | - return (BigInteger) o; | |
56 | - } else { | |
57 | - Long l = LongConversionUtil.toLong(o, pattern); | |
58 | - if (l == null) { | |
59 | - return null; | |
60 | - } | |
61 | - return BigInteger.valueOf(l.longValue()); | |
62 | - } | |
63 | - } | |
64 | 35 | } |
@@ -21,7 +21,8 @@ | ||
21 | 21 | * @author higa |
22 | 22 | * |
23 | 23 | */ |
24 | -public class BooleanConversionUtil { | |
24 | +public class BooleanConversionUtil extends | |
25 | + org.seasar.util.convert.BooleanConversionUtil { | |
25 | 26 | |
26 | 27 | /** |
27 | 28 | * インスタンスを構築します。 |
@@ -29,47 +30,4 @@ | ||
29 | 30 | protected BooleanConversionUtil() { |
30 | 31 | } |
31 | 32 | |
32 | - /** | |
33 | - * {@link Boolean}に変換します。 | |
34 | - * | |
35 | - * @param o | |
36 | - * @return {@link Boolean} | |
37 | - */ | |
38 | - public static Boolean toBoolean(Object o) { | |
39 | - if (o == null) { | |
40 | - return null; | |
41 | - } else if (o instanceof Boolean) { | |
42 | - return (Boolean) o; | |
43 | - } else if (o instanceof Number) { | |
44 | - int num = ((Number) o).intValue(); | |
45 | - return Boolean.valueOf(num != 0); | |
46 | - } else if (o instanceof String) { | |
47 | - String s = (String) o; | |
48 | - if ("true".equalsIgnoreCase(s)) { | |
49 | - return Boolean.TRUE; | |
50 | - } else if ("false".equalsIgnoreCase(s)) { | |
51 | - return Boolean.FALSE; | |
52 | - } else if (s.equals("0")) { | |
53 | - return Boolean.FALSE; | |
54 | - } else { | |
55 | - return Boolean.TRUE; | |
56 | - } | |
57 | - } else { | |
58 | - return Boolean.TRUE; | |
59 | - } | |
60 | - } | |
61 | - | |
62 | - /** | |
63 | - * booleanに変換します。 | |
64 | - * | |
65 | - * @param o | |
66 | - * @return boolean | |
67 | - */ | |
68 | - public static boolean toPrimitiveBoolean(Object o) { | |
69 | - Boolean b = toBoolean(o); | |
70 | - if (b != null) { | |
71 | - return b.booleanValue(); | |
72 | - } | |
73 | - return false; | |
74 | - } | |
75 | 33 | } |
\ No newline at end of file |
@@ -15,7 +15,6 @@ | ||
15 | 15 | */ |
16 | 16 | package org.seasar.framework.util; |
17 | 17 | |
18 | -import java.util.Map; | |
19 | 18 | |
20 | 19 | /** |
21 | 20 | * キーで大文字小文字を気にしない {@link ArrayMap}です。 |
@@ -27,7 +26,8 @@ | ||
27 | 26 | * |
28 | 27 | * @author higa |
29 | 28 | */ |
30 | -public class CaseInsensitiveMap<K, V> extends ArrayMap<K, V> { | |
29 | +public class CaseInsensitiveMap<V> extends | |
30 | + org.seasar.util.collection.CaseInsensitiveMap<V> { | |
31 | 31 | |
32 | 32 | private static final long serialVersionUID = 1L; |
33 | 33 |
@@ -47,41 +47,4 @@ | ||
47 | 47 | super(capacity); |
48 | 48 | } |
49 | 49 | |
50 | - /** | |
51 | - * キーが含まれているかどうかを返します。 | |
52 | - * | |
53 | - * @param key | |
54 | - * @return キーが含まれているかどうか | |
55 | - */ | |
56 | - public final boolean containsKey(String key) { | |
57 | - return super.containsKey(convertKey(key)); | |
58 | - } | |
59 | - | |
60 | - public final V get(Object key) { | |
61 | - return super.get(convertKey(key)); | |
62 | - } | |
63 | - | |
64 | - public final V put(K key, V value) { | |
65 | - return super.put(convertKey(key), value); | |
66 | - } | |
67 | - | |
68 | - public final void putAll(Map<? extends K, ? extends V> map) { | |
69 | - for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) { | |
70 | - put(convertKey(entry.getKey()), entry.getValue()); | |
71 | - } | |
72 | - } | |
73 | - | |
74 | - public final V remove(Object key) { | |
75 | - return super.remove(convertKey(key)); | |
76 | - } | |
77 | - | |
78 | - public boolean containsKey(Object key) { | |
79 | - return super.containsKey(convertKey(key)); | |
80 | - } | |
81 | - | |
82 | - @SuppressWarnings("unchecked") | |
83 | - private static <K> K convertKey(K key) { | |
84 | - return (K) key.toString().toLowerCase(); | |
85 | - } | |
86 | - | |
87 | 50 | } |
@@ -15,8 +15,6 @@ | ||
15 | 15 | */ |
16 | 16 | package org.seasar.framework.util; |
17 | 17 | |
18 | -import java.text.SimpleDateFormat; | |
19 | - | |
20 | 18 | /** |
21 | 19 | * {@link Byte}用の変換ユーティリティです。 |
22 | 20 | * |
@@ -23,7 +21,8 @@ | ||
23 | 21 | * @author higa |
24 | 22 | * |
25 | 23 | */ |
26 | -public class ByteConversionUtil { | |
24 | +public class ByteConversionUtil extends | |
25 | + org.seasar.util.convert.ByteConversionUtil { | |
27 | 26 | |
28 | 27 | /** |
29 | 28 | * インスタンスを構築します。 |
@@ -31,92 +30,4 @@ | ||
31 | 30 | protected ByteConversionUtil() { |
32 | 31 | } |
33 | 32 | |
34 | - /** | |
35 | - * {@link Byte}に変換します。 | |
36 | - * | |
37 | - * @param o | |
38 | - * @return {@link Byte} | |
39 | - */ | |
40 | - public static Byte toByte(Object o) { | |
41 | - return toByte(o, null); | |
42 | - } | |
43 | - | |
44 | - /** | |
45 | - * {@link Byte}に変換します。 | |
46 | - * | |
47 | - * @param o | |
48 | - * @param pattern | |
49 | - * @return {@link Byte} | |
50 | - */ | |
51 | - public static Byte toByte(Object o, String pattern) { | |
52 | - if (o == null) { | |
53 | - return null; | |
54 | - } else if (o instanceof Byte) { | |
55 | - return (Byte) o; | |
56 | - } else if (o instanceof Number) { | |
57 | - return new Byte(((Number) o).byteValue()); | |
58 | - } else if (o instanceof String) { | |
59 | - return toByte((String) o); | |
60 | - } else if (o instanceof java.util.Date) { | |
61 | - if (pattern != null) { | |
62 | - return new Byte(new SimpleDateFormat(pattern).format(o)); | |
63 | - } | |
64 | - return new Byte((byte) ((java.util.Date) o).getTime()); | |
65 | - } else if (o instanceof Boolean) { | |
66 | - return ((Boolean) o).booleanValue() ? new Byte((byte) 1) | |
67 | - : new Byte((byte) 0); | |
68 | - } else { | |
69 | - return toByte(o.toString()); | |
70 | - } | |
71 | - } | |
72 | - | |
73 | - private static Byte toByte(String s) { | |
74 | - if (StringUtil.isEmpty(s)) { | |
75 | - return null; | |
76 | - } | |
77 | - return new Byte(DecimalFormatUtil.normalize(s)); | |
78 | - } | |
79 | - | |
80 | - /** | |
81 | - * byteに変換します。 | |
82 | - * | |
83 | - * @param o | |
84 | - * @return byte | |
85 | - */ | |
86 | - public static byte toPrimitiveByte(Object o) { | |
87 | - return toPrimitiveByte(o, null); | |
88 | - } | |
89 | - | |
90 | - /** | |
91 | - * byteに変換します。 | |
92 | - * | |
93 | - * @param o | |
94 | - * @param pattern | |
95 | - * @return byte | |
96 | - */ | |
97 | - public static byte toPrimitiveByte(Object o, String pattern) { | |
98 | - if (o == null) { | |
99 | - return 0; | |
100 | - } else if (o instanceof Number) { | |
101 | - return ((Number) o).byteValue(); | |
102 | - } else if (o instanceof String) { | |
103 | - return toPrimitiveByte((String) o); | |
104 | - } else if (o instanceof java.util.Date) { | |
105 | - if (pattern != null) { | |
106 | - return Byte.parseByte(new SimpleDateFormat(pattern).format(o)); | |
107 | - } | |
108 | - return (byte) ((java.util.Date) o).getTime(); | |
109 | - } else if (o instanceof Boolean) { | |
110 | - return ((Boolean) o).booleanValue() ? (byte) 1 : (byte) 0; | |
111 | - } else { | |
112 | - return toPrimitiveByte(o.toString()); | |
113 | - } | |
114 | - } | |
115 | - | |
116 | - private static byte toPrimitiveByte(String s) { | |
117 | - if (StringUtil.isEmpty(s)) { | |
118 | - return 0; | |
119 | - } | |
120 | - return Byte.parseByte(DecimalFormatUtil.normalize(s)); | |
121 | - } | |
122 | 33 | } |
@@ -16,8 +16,6 @@ | ||
16 | 16 | package org.seasar.framework.util; |
17 | 17 | |
18 | 18 | import java.util.Calendar; |
19 | -import java.util.Locale; | |
20 | -import java.util.TimeZone; | |
21 | 19 | |
22 | 20 | /** |
23 | 21 | * {@link Calendar}用の変換ユーティリティです。 |
@@ -25,7 +23,8 @@ | ||
25 | 23 | * @author higa |
26 | 24 | * |
27 | 25 | */ |
28 | -public class CalendarConversionUtil { | |
26 | +public class CalendarConversionUtil extends | |
27 | + org.seasar.util.convert.CalendarConversionUtil { | |
29 | 28 | |
30 | 29 | /** |
31 | 30 | * インスタンスを構築します。 |
@@ -33,49 +32,4 @@ | ||
33 | 32 | protected CalendarConversionUtil() { |
34 | 33 | } |
35 | 34 | |
36 | - /** | |
37 | - * {@link Calendar}に変換します。 | |
38 | - * | |
39 | - * @param o | |
40 | - * @return {@link Calendar} | |
41 | - */ | |
42 | - public static Calendar toCalendar(Object o) { | |
43 | - return toCalendar(o, null); | |
44 | - } | |
45 | - | |
46 | - /** | |
47 | - * {@link Calendar}に変換します。 | |
48 | - * | |
49 | - * @param o | |
50 | - * @param pattern | |
51 | - * @return {@link Calendar} | |
52 | - */ | |
53 | - public static Calendar toCalendar(Object o, String pattern) { | |
54 | - if (o instanceof Calendar) { | |
55 | - return (Calendar) o; | |
56 | - } | |
57 | - java.util.Date date = DateConversionUtil.toDate(o, pattern); | |
58 | - if (date != null) { | |
59 | - Calendar cal = Calendar.getInstance(); | |
60 | - cal.setTime(date); | |
61 | - return cal; | |
62 | - } | |
63 | - return null; | |
64 | - } | |
65 | - | |
66 | - /** | |
67 | - * ローカルの{@link TimeZone}と{@link Locale}をもつ{@link Calendar}に変換します。 | |
68 | - * | |
69 | - * @param calendar | |
70 | - * {@link Calendar} | |
71 | - * @return | |
72 | - */ | |
73 | - public static Calendar localize(Calendar calendar) { | |
74 | - if (calendar == null) { | |
75 | - throw new NullPointerException("calendar"); | |
76 | - } | |
77 | - Calendar localCalendar = Calendar.getInstance(); | |
78 | - localCalendar.setTimeInMillis(calendar.getTimeInMillis()); | |
79 | - return localCalendar; | |
80 | - } | |
81 | 35 | } |
\ No newline at end of file |
@@ -15,29 +15,15 @@ | ||
15 | 15 | */ |
16 | 16 | package org.seasar.framework.util; |
17 | 17 | |
18 | -import java.io.IOException; | |
19 | -import java.lang.reflect.Method; | |
20 | -import java.net.URL; | |
21 | -import java.util.Enumeration; | |
22 | -import java.util.Iterator; | |
23 | 18 | |
24 | -import org.seasar.framework.exception.ClassNotFoundRuntimeException; | |
25 | -import org.seasar.framework.exception.IORuntimeException; | |
26 | -import org.seasar.framework.message.MessageFormatter; | |
27 | - | |
28 | 19 | /** |
29 | 20 | * {@link ClassLoader}を扱うためのユーティリティ・クラスです。 |
30 | 21 | * |
31 | 22 | * @author koichik |
32 | 23 | */ |
33 | -public abstract class ClassLoaderUtil { | |
24 | +public abstract class ClassLoaderUtil extends | |
25 | + org.seasar.util.lang.ClassLoaderUtil { | |
34 | 26 | |
35 | - private static final Method findLoadedClassMethod = getFindLoadedClassMethod(); | |
36 | - | |
37 | - private static final Method defineClassMethod = getDefineClassMethod(); | |
38 | - | |
39 | - private static final Method definePackageMethod = getDefinePackageMethod(); | |
40 | - | |
41 | 27 | /** |
42 | 28 | * インスタンスを構築します。 |
43 | 29 | */ |
@@ -44,258 +30,4 @@ | ||
44 | 30 | protected ClassLoaderUtil() { |
45 | 31 | } |
46 | 32 | |
47 | - private static Method getFindLoadedClassMethod() { | |
48 | - final Method method = ClassUtil.getDeclaredMethod(ClassLoader.class, | |
49 | - "findLoadedClass", new Class[] { String.class }); | |
50 | - method.setAccessible(true); | |
51 | - return method; | |
52 | - } | |
53 | - | |
54 | - private static Method getDefineClassMethod() { | |
55 | - final Method method = ClassUtil.getDeclaredMethod(ClassLoader.class, | |
56 | - "defineClass", new Class[] { String.class, byte[].class, | |
57 | - int.class, int.class }); | |
58 | - method.setAccessible(true); | |
59 | - return method; | |
60 | - } | |
61 | - | |
62 | - private static Method getDefinePackageMethod() { | |
63 | - final Method method = ClassUtil.getDeclaredMethod(ClassLoader.class, | |
64 | - "definePackage", new Class[] { String.class, String.class, | |
65 | - String.class, String.class, String.class, String.class, | |
66 | - String.class, URL.class }); | |
67 | - method.setAccessible(true); | |
68 | - return method; | |
69 | - } | |
70 | - | |
71 | - /** | |
72 | - * クラスローダを返します。 | |
73 | - * <p> | |
74 | - * クラスローダは以下の順で検索します。 | |
75 | - * </p> | |
76 | - * <ol> | |
77 | - * <li>呼び出されたスレッドにコンテキスト・クラスローダが設定されている場合はそのコンテキスト・クラスローダ</li> | |
78 | - * <li>ターゲット・クラスをロードしたクラスローダを取得できればそのクラスローダ</li> | |
79 | - * <li>このクラスをロードしたクラスローダを取得できればそのクラスローダ</li> | |
80 | - * <li>システムを取得できればそのクラスローダ</li> | |
81 | - * </ol> | |
82 | - * <p> | |
83 | - * ただし、ターゲット・クラスをロードしたクラスローダとこのクラスをロードしたクラスローダの両方が取得できた場合で、 | |
84 | - * ターゲット・クラスをロードしたクラスローダがこのクラスをロードしたクラスローダの祖先であった場合は、 | |
85 | - * このクラスをロードしたクラスローダを返します。 | |
86 | - * </p> | |
87 | - * | |
88 | - * @param targetClass | |
89 | - * ターゲット・クラス | |
90 | - * @return クラスローダ | |
91 | - * @throws IllegalStateException | |
92 | - * クラスローダを取得できなかった場合 | |
93 | - */ | |
94 | - public static ClassLoader getClassLoader(final Class targetClass) { | |
95 | - final ClassLoader contextClassLoader = Thread.currentThread() | |
96 | - .getContextClassLoader(); | |
97 | - if (contextClassLoader != null) { | |
98 | - return contextClassLoader; | |
99 | - } | |
100 | - | |
101 | - final ClassLoader targetClassLoader = targetClass.getClassLoader(); | |
102 | - final ClassLoader thisClassLoader = ClassLoaderUtil.class | |
103 | - .getClassLoader(); | |
104 | - if (targetClassLoader != null && thisClassLoader != null) { | |
105 | - if (isAncestor(thisClassLoader, targetClassLoader)) { | |
106 | - return thisClassLoader; | |
107 | - } | |
108 | - return targetClassLoader; | |
109 | - } | |
110 | - if (targetClassLoader != null) { | |
111 | - return targetClassLoader; | |
112 | - } | |
113 | - if (thisClassLoader != null) { | |
114 | - return thisClassLoader; | |
115 | - } | |
116 | - | |
117 | - final ClassLoader systemClassLoader = ClassLoader | |
118 | - .getSystemClassLoader(); | |
119 | - if (systemClassLoader != null) { | |
120 | - return systemClassLoader; | |
121 | - } | |
122 | - | |
123 | - throw new IllegalStateException(MessageFormatter.getMessage("ESSR0001", | |
124 | - new Object[] { "ClassLoader" })); | |
125 | - } | |
126 | - | |
127 | - /** | |
128 | - * コンテキストクラスローダから指定された名前を持つすべてのリソースを探します。 | |
129 | - * | |
130 | - * @param name | |
131 | - * リソース名 | |
132 | - * @return リソースに対する URL | |
133 | - * オブジェクトの列挙。リソースが見つからなかった場合、列挙は空になる。クラスローダがアクセスを持たないリソースは列挙に入らない | |
134 | - * @see java.lang.ClassLoader#getResources(String) | |
135 | - */ | |
136 | - public static Iterator getResources(final String name) { | |
137 | - return getResources(Thread.currentThread().getContextClassLoader(), | |
138 | - name); | |
139 | - } | |
140 | - | |
141 | - /** | |
142 | - * {@link #getClassLoader(Class)}が返すクラスローダから指定された名前を持つすべてのリソースを探します。 | |
143 | - * | |
144 | - * @param targetClass | |
145 | - * ターゲット・クラス | |
146 | - * @param name | |
147 | - * リソース名 | |
148 | - * @return リソースに対する URL | |
149 | - * オブジェクトの列挙。リソースが見つからなかった場合、列挙は空になる。クラスローダがアクセスを持たないリソースは列挙に入らない | |
150 | - * @see java.lang.ClassLoader#getResources(String) | |
151 | - */ | |
152 | - public static Iterator getResources(final Class targetClass, | |
153 | - final String name) { | |
154 | - return getResources(getClassLoader(targetClass), name); | |
155 | - } | |
156 | - | |
157 | - /** | |
158 | - * 指定のクラスローダから指定された名前を持つすべてのリソースを探します。 | |
159 | - * | |
160 | - * @param loader | |
161 | - * クラスローダ | |
162 | - * @param name | |
163 | - * リソース名 | |
164 | - * @return リソースに対する URL | |
165 | - * オブジェクトの列挙。リソースが見つからなかった場合、列挙は空になる。クラスローダがアクセスを持たないリソースは列挙に入らない | |
166 | - * @see java.lang.ClassLoader#getResources(String) | |
167 | - */ | |
168 | - public static Iterator getResources(final ClassLoader loader, | |
169 | - final String name) { | |
170 | - try { | |
171 | - final Enumeration e = loader.getResources(name); | |
172 | - return new EnumerationIterator(e); | |
173 | - } catch (final IOException e) { | |
174 | - throw new IORuntimeException(e); | |
175 | - } | |
176 | - } | |
177 | - | |
178 | - /** | |
179 | - * クラスローダ<code>other</code>がクラスローダ<code>cl</code>の祖先なら<code>true</code>を返します。 | |
180 | - * | |
181 | - * @param cl | |
182 | - * クラスローダ | |
183 | - * @param other | |
184 | - * クラスローダ | |
185 | - * @return クラスローダ<code>other</code>がクラスローダ<code>cl</code>の祖先なら<code>true</code> | |
186 | - */ | |
187 | - protected static boolean isAncestor(ClassLoader cl, final ClassLoader other) { | |
188 | - while (cl != null) { | |
189 | - if (cl == other) { | |
190 | - return true; | |
191 | - } | |
192 | - cl = cl.getParent(); | |
193 | - } | |
194 | - return false; | |
195 | - } | |
196 | - | |
197 | - /** | |
198 | - * 指定のクラスローダまたはその祖先の暮らすローダが、 このバイナリ名を持つクラスの起動ローダとしてJava仮想マシンにより記録されていた場合は、 | |
199 | - * 指定されたバイナリ名を持つクラスを返します。 記録されていなかった場合は<code>null</code>を返します。 | |
200 | - * | |
201 | - * @param classLoader | |
202 | - * クラスローダ | |
203 | - * @param className | |
204 | - * クラスのバイナリ名 | |
205 | - * @return <code>Class</code>オブジェクト。クラスがロードされていない場合は<code>null</code> | |
206 | - * @see java.lang.ClassLoader#findLoadedClass(String) | |
207 | - */ | |
208 | - public static Class findLoadedClass(final ClassLoader classLoader, | |
209 | - final String className) { | |
210 | - for (ClassLoader loader = classLoader; loader != null; loader = loader | |
211 | - .getParent()) { | |
212 | - final Class clazz = (Class) MethodUtil.invoke( | |
213 | - findLoadedClassMethod, loader, new Object[] { className }); | |
214 | - if (clazz != null) { | |
215 | - return clazz; | |
216 | - } | |
217 | - } | |
218 | - return null; | |
219 | - } | |
220 | - | |
221 | - /** | |
222 | - * バイトの配列を<code>Class</code>クラスのインスタンスに変換します。 | |
223 | - * | |
224 | - * @param classLoader | |
225 | - * バイナリデータから<code>Class</code>クラスのインスタンスに変換するクラスローダ | |
226 | - * @param className | |
227 | - * クラスのバイナリ名 | |
228 | - * @param bytes | |
229 | - * クラスデータを構成するバイト列 | |
230 | - * @param offset | |
231 | - * クラスデータ<code>bytes</code>の開始オフセット | |
232 | - * @param length | |
233 | - * クラスデータの長さ | |
234 | - * @return 指定されたクラスデータから作成された<code>Class</code>オブジェクト | |
235 | - * @see java.lang.ClassLoader#defineClass(String, byte[], int, int) | |
236 | - */ | |
237 | - public static Class defineClass(final ClassLoader classLoader, | |
238 | - final String className, final byte[] bytes, final int offset, | |
239 | - final int length) { | |
240 | - return (Class) MethodUtil.invoke(defineClassMethod, classLoader, | |
241 | - new Object[] { className, bytes, new Integer(offset), | |
242 | - new Integer(length) }); | |
243 | - } | |
244 | - | |
245 | - /** | |
246 | - * 指定の<code>ClassLoader</code>で名前を使ってパッケージを定義します。 | |
247 | - * | |
248 | - * @param classLoader | |
249 | - * パッケージを定義するクラスローダ | |
250 | - * @param name | |
251 | - * パッケージ名 | |
252 | - * @param specTitle | |
253 | - * 仕様のタイトル | |
254 | - * @param specVersion | |
255 | - * 仕様のバージョン | |
256 | - * @param specVendor | |
257 | - * 仕様のベンダー | |
258 | - * @param implTitle | |
259 | - * 実装のタイトル | |
260 | - * @param implVersion | |
261 | - * 実装のバージョン | |
262 | - * @param implVendor | |
263 | - * 実装のベンダー | |
264 | - * @param sealBase | |
265 | - * <code>null</code>でない場合、このパッケージは指定されたコードソース<code>URL</code>オブジェクトを考慮してシールされる。そうでない場合、パッケージはシールされない | |
266 | - * @return 新しく定義された<code>Package</code>オブジェクト | |
267 | - * @see java.lang.ClassLoader#definePackage(String, String, String, String, | |
268 | - * String, String, String, URL) | |
269 | - */ | |
270 | - public static Package definePackage(final ClassLoader classLoader, | |
271 | - final String name, final String specTitle, | |
272 | - final String specVersion, final String specVendor, | |
273 | - final String implTitle, final String implVersion, | |
274 | - final String implVendor, final URL sealBase) { | |
275 | - return (Package) MethodUtil.invoke(definePackageMethod, classLoader, | |
276 | - new Object[] { name, specTitle, specVersion, specVendor, | |
277 | - implTitle, implVersion, implVendor, sealBase }); | |
278 | - } | |
279 | - | |
280 | - /** | |
281 | - * 指定されたバイナリ名を持つクラスをロードします。 | |
282 | - * | |
283 | - * @param loader | |
284 | - * クラスローダ | |
285 | - * @param className | |
286 | - * クラスのバイナリ名 | |
287 | - * @return 結果の<code>Class</code>オブジェクト | |
288 | - * @throws ClassNotFoundRuntimeException | |
289 | - * クラスが見つからなかった場合 | |
290 | - * @see java.lang.ClassLoader#loadClass(String) | |
291 | - */ | |
292 | - public static Class loadClass(final ClassLoader loader, | |
293 | - final String className) { | |
294 | - try { | |
295 | - return loader.loadClass(className); | |
296 | - } catch (final ClassNotFoundException e) { | |
297 | - throw new ClassNotFoundRuntimeException(e); | |
298 | - } | |
299 | - } | |
300 | - | |
301 | 33 | } |
@@ -21,12 +21,13 @@ | ||
21 | 21 | * @author higa |
22 | 22 | * |
23 | 23 | */ |
24 | -public class ClassNotFoundRuntimeException extends SRuntimeException { | |
24 | +// TODO 不要な可能性あり | |
25 | +@Deprecated | |
26 | +public class ClassNotFoundRuntimeException extends | |
27 | + org.seasar.util.exception.ClassNotFoundRuntimeException { | |
25 | 28 | |
26 | 29 | private static final long serialVersionUID = -9022468864937761059L; |
27 | 30 | |
28 | - private String className; | |
29 | - | |
30 | 31 | /** |
31 | 32 | * {@link ClassNotFoundRuntimeException}を作成します。 |
32 | 33 | * |
@@ -33,7 +34,7 @@ | ||
33 | 34 | * @param cause |
34 | 35 | */ |
35 | 36 | public ClassNotFoundRuntimeException(ClassNotFoundException cause) { |
36 | - this(null, cause); | |
37 | + super(cause); | |
37 | 38 | } |
38 | 39 | |
39 | 40 | /** |
@@ -44,26 +45,7 @@ | ||
44 | 45 | */ |
45 | 46 | public ClassNotFoundRuntimeException(String className, |
46 | 47 | ClassNotFoundException cause) { |
47 | - super("ESSR0044", new Object[] { cause }, cause); | |
48 | - setClassName(className); | |
48 | + super(className, cause); | |
49 | 49 | } |
50 | 50 | |
51 | - /** | |
52 | - * クラス名を返します。 | |
53 | - * | |
54 | - * @return | |
55 | - */ | |
56 | - public String getClassName() { | |
57 | - return className; | |
58 | - } | |
59 | - | |
60 | - /** | |
61 | - * クラス名を設定します。 | |
62 | - * | |
63 | - * @param className | |
64 | - * クラス名 | |
65 | - */ | |
66 | - protected void setClassName(String className) { | |
67 | - this.className = className; | |
68 | - } | |
69 | 51 | } |
@@ -113,9 +113,9 @@ | ||
113 | 113 | </dependency> |
114 | 114 | <dependency> |
115 | 115 | <groupId>org.slf4j</groupId> |
116 | - <artifactId>slf4j-jcl</artifactId> | |
116 | + <artifactId>jcl-over-slf4j</artifactId> | |
117 | 117 | <version>1.6.1</version> |
118 | - <type>jar</type> | |
118 | + <optional>true</optional> | |
119 | 119 | </dependency> |
120 | 120 | <dependency> |
121 | 121 | <groupId>org.slf4j</groupId> |
@@ -125,13 +125,6 @@ | ||
125 | 125 | <optional>true</optional> |
126 | 126 | </dependency> |
127 | 127 | <dependency> |
128 | - <groupId>org.slf4j</groupId> | |
129 | - <artifactId>slf4j-log4j12</artifactId> | |
130 | - <version>1.6.1</version> | |
131 | - <scope>runtime</scope> | |
132 | - <optional>true</optional> | |
133 | - </dependency> | |
134 | - <dependency> | |
135 | 128 | <groupId>junit</groupId> |
136 | 129 | <artifactId>junit</artifactId> |
137 | 130 | <version>4.8.1</version> |
@@ -18,7 +18,7 @@ | ||
18 | 18 | import org.seasar.extension.jdbc.ColumnNotFoundRuntimeException; |
19 | 19 | |
20 | 20 | /** |
21 | - * DataSetの業をあらわすインターフェースです。 | |
21 | + * DataSetの行をあらわすインターフェースです。 | |
22 | 22 | * |
23 | 23 | * @author higa |
24 | 24 | * |
@@ -33,9 +33,9 @@ | ||
33 | 33 | import org.seasar.framework.beans.BeanDesc; |
34 | 34 | import org.seasar.framework.beans.PropertyDesc; |
35 | 35 | import org.seasar.framework.beans.factory.BeanDescFactory; |
36 | -import org.seasar.framework.util.ArrayMap; | |
37 | 36 | import org.seasar.framework.util.CaseInsensitiveMap; |
38 | 37 | import org.seasar.framework.util.StringUtil; |
38 | +import org.seasar.util.collection.ArrayMap; | |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * {@link DataTable}の実装クラスです。 |
@@ -47,11 +47,11 @@ | ||
47 | 47 | |
48 | 48 | private String tableName; |
49 | 49 | |
50 | - private List rows = new ArrayList(); | |
50 | + private List<DataRow> rows = new ArrayList<DataRow>(); | |
51 | 51 | |
52 | - private List removedRows = new ArrayList(); | |
52 | + private List<DataRow> removedRows = new ArrayList<DataRow>(); | |
53 | 53 | |
54 | - private ArrayMap columns = new CaseInsensitiveMap(); | |
54 | + private ArrayMap<String, DataColumn> columns = new CaseInsensitiveMap<DataColumn>(); | |
55 | 55 | |
56 | 56 | private boolean hasMetaData = false; |
57 | 57 |
@@ -164,7 +164,7 @@ | ||
164 | 164 | column = (DataColumn) columns.get(name); |
165 | 165 | if (column == null) { |
166 | 166 | for (int i = 0; i < columns.size(); ++i) { |
167 | - String key = (String) columns.getKey(i); | |
167 | + String key = (String) columns.getKeyAt(i); | |
168 | 168 | String key2 = StringUtil.replace(key, "_", ""); |
169 | 169 | if (key2.equalsIgnoreCase(name)) { |
170 | 170 | column = (DataColumn) columns.get(i); |
@@ -216,8 +216,8 @@ | ||
216 | 216 | * org.seasar.extension.dataset.ColumnType) |
217 | 217 | */ |
218 | 218 | public DataColumn addColumn(String columnName, ColumnType columnType) { |
219 | - DataColumn column = new DataColumnImpl(columnName, columnType, columns | |
220 | - .size()); | |
219 | + DataColumn column = new DataColumnImpl(columnName, columnType, | |
220 | + columns.size()); | |
221 | 221 | columns.put(columnName, column); |
222 | 222 | return column; |
223 | 223 | } |
@@ -248,9 +248,7 @@ | ||
248 | 248 | column.setWritable(true); |
249 | 249 | ColumnDesc cd = (ColumnDesc) columnMap.get(column |
250 | 250 | .getColumnName()); |
251 | - column | |
252 | - .setColumnType(ColumnTypes.getColumnType(cd | |
253 | - .getSqlType())); | |
251 | + column.setColumnType(ColumnTypes.getColumnType(cd.getSqlType())); | |
254 | 252 | } else { |
255 | 253 | column.setWritable(false); |
256 | 254 | } |
@@ -265,8 +263,8 @@ | ||
265 | 263 | BeanDesc beanDesc = BeanDescFactory.getBeanDesc(beanClass); |
266 | 264 | for (int i = 0; i < beanDesc.getPropertyDescSize(); ++i) { |
267 | 265 | PropertyDesc pd = beanDesc.getPropertyDesc(i); |
268 | - addColumn(pd.getPropertyName(), ColumnTypes.getColumnType(pd | |
269 | - .getPropertyType())); | |
266 | + addColumn(pd.getPropertyName(), | |
267 | + ColumnTypes.getColumnType(pd.getPropertyType())); | |
270 | 268 | } |
271 | 269 | } |
272 | 270 |
@@ -18,8 +18,8 @@ | ||
18 | 18 | import org.seasar.extension.dataset.DataSet; |
19 | 19 | import org.seasar.extension.dataset.DataTable; |
20 | 20 | import org.seasar.extension.dataset.TableNotFoundRuntimeException; |
21 | -import org.seasar.framework.util.ArrayMap; | |
22 | 21 | import org.seasar.framework.util.CaseInsensitiveMap; |
22 | +import org.seasar.util.collection.ArrayMap; | |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * {@link DataSet}の実装です。 |
@@ -29,7 +29,7 @@ | ||
29 | 29 | */ |
30 | 30 | public class DataSetImpl implements DataSet { |
31 | 31 | |
32 | - private ArrayMap<String, DataTable> tables = new CaseInsensitiveMap<String, DataTable>(); | |
32 | + private ArrayMap<String, DataTable> tables = new CaseInsensitiveMap<DataTable>(); | |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * {@link DataSetImpl}を作成します。 |
@@ -15,7 +15,6 @@ | ||
15 | 15 | */ |
16 | 16 | package org.seasar.extension.dataset.impl; |
17 | 17 | |
18 | -import java.util.Iterator; | |
19 | 18 | import java.util.Map; |
20 | 19 | |
21 | 20 | import org.seasar.extension.dataset.ColumnType; |
@@ -29,9 +28,9 @@ | ||
29 | 28 | import org.seasar.framework.beans.BeanDesc; |
30 | 29 | import org.seasar.framework.beans.PropertyDesc; |
31 | 30 | import org.seasar.framework.beans.factory.BeanDescFactory; |
32 | -import org.seasar.framework.util.ArrayMap; | |
33 | -import org.seasar.framework.util.CaseInsensitiveMap; | |
34 | 31 | import org.seasar.framework.util.StringUtil; |
32 | +import org.seasar.util.collection.ArrayMap; | |
33 | +import org.seasar.util.collection.CaseInsensitiveMap; | |
35 | 34 | |
36 | 35 | /** |
37 | 36 | * {@link DataRow}の実装クラスです。 |
@@ -43,7 +42,7 @@ | ||
43 | 42 | |
44 | 43 | private DataTable table_; |
45 | 44 | |
46 | - private ArrayMap values_ = new CaseInsensitiveMap(); | |
45 | + private ArrayMap<String, Object> values_ = new CaseInsensitiveMap<Object>(); | |
47 | 46 | |
48 | 47 | private RowState state_ = RowStates.UNCHANGED; |
49 | 48 |
@@ -97,7 +96,7 @@ | ||
97 | 96 | */ |
98 | 97 | public void setValue(int index, Object value) { |
99 | 98 | DataColumn column = table_.getColumn(index); |
100 | - values_.set(index, column.convert(value)); | |
99 | + values_.setAt(index, column.convert(value)); | |
101 | 100 | modify(); |
102 | 101 | } |
103 | 102 |
@@ -173,7 +172,7 @@ | ||
173 | 172 | */ |
174 | 173 | public void copyFrom(Object source) { |
175 | 174 | if (source instanceof Map) { |
176 | - copyFromMap((Map) source); | |
175 | + copyFromMap((Map<String, Object>) source); | |
177 | 176 | } else if (source instanceof DataRow) { |
178 | 177 | copyFromRow((DataRow) source); |
179 | 178 | } else { |
@@ -182,11 +181,11 @@ | ||
182 | 181 | |
183 | 182 | } |
184 | 183 | |
185 | - private void copyFromMap(Map source) { | |
186 | - for (Iterator i = source.keySet().iterator(); i.hasNext();) { | |
187 | - String columnName = (String) i.next(); | |
184 | + private void copyFromMap(Map<String, Object> source) { | |
185 | + for (Map.Entry<String, Object> entry : source.entrySet()) { | |
186 | + String columnName = entry.getKey(); | |
188 | 187 | if (table_.hasColumn(columnName)) { |
189 | - Object value = source.get(columnName); | |
188 | + Object value = entry.getValue(); | |
190 | 189 | setValue(columnName, convertValue(value)); |
191 | 190 | } |
192 | 191 | } |