OSDN Git Service

s2jdbc-genのAntランチャーを移植
authortaktos9 <taktos9@136db618-7844-41ca-8ac1-fb3fd040db1d>
Fri, 17 Oct 2008 01:50:10 +0000 (01:50 +0000)
committertaktos9 <taktos9@136db618-7844-41ca-8ac1-fb3fd040db1d>
Fri, 17 Oct 2008 01:50:10 +0000 (01:50 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/ea2ddl/trunk/ea2ddl@27 136db618-7844-41ca-8ac1-fb3fd040db1d

27 files changed:
ea2ddl-common/pom.xml
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/Command.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandAdapter.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandInvoker.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/exception/CommandFailedRuntimeException.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsBuilder.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsParser.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentTypeRegistry.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/BooleanType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/CharacterType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ClassType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/EnumType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/FileType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ListType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/NumberType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/StringType.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/AbstractCommand.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/CommandInvokerImpl.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/ClassUnmatchRuntimeException.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/SystemPropertyNotFoundRuntimeException.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ArgumentUtil.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/EnvUtil.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/FileUtil.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ReflectUtil.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/SingletonS2ContainerFactorySupport.java [new file with mode: 0644]
ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/task/AbstractTask.java [new file with mode: 0644]

index e4a4ab1..8858574 100644 (file)
                        <groupId>org.apache.geronimo.specs</groupId>\r
                        <artifactId>geronimo-jta_1.1_spec</artifactId>\r
                </dependency>\r
+               \r
+               <dependency>\r
+                       <groupId>org.apache.ant</groupId>\r
+                       <artifactId>ant</artifactId>\r
+               </dependency>\r
        </dependencies>\r
 </project>
\ No newline at end of file
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/Command.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/Command.java
new file mode 100644 (file)
index 0000000..6a404d1
--- /dev/null
@@ -0,0 +1,35 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.command;\r
+\r
+import org.seasar.extension.jdbc.gen.exception.CommandFailedRuntimeException;\r
+\r
+/**\r
+ * 繧ウ繝槭Φ繝峨r陦ィ縺吶う繝ウ繧ソ繝輔ぉ繝シ繧ケ縺ァ縺吶�\r
+ * \r
+ * @author taedium\r
+ */\r
+public interface Command {\r
+\r
+    /**\r
+     * 螳溯。後@縺セ縺吶�\r
+     * \r
+     * @throws CommandFailedRuntimeException\r
+     *             繧ウ繝槭Φ繝峨�螳溯。後↓螟ア謨励@縺溷�蜷�\r
+     */\r
+    void execute() throws CommandFailedRuntimeException;\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandAdapter.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandAdapter.java
new file mode 100644 (file)
index 0000000..dc05317
--- /dev/null
@@ -0,0 +1,63 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.command;\r
+\r
+import org.seasar.extension.jdbc.gen.internal.arg.ArgumentsParser;\r
+import org.seasar.extension.jdbc.gen.internal.exception.SystemPropertyNotFoundRuntimeException;\r
+import org.seasar.extension.jdbc.gen.internal.util.ReflectUtil;\r
+\r
+/**\r
+ * {@link Command}のアダプタとなるクラスです。\r
+ * <p>\r
+ * コマンドラインの情報を元に{@link Command}を組み立て実行します。\r
+ * </p>\r
+ * \r
+ * @author taedium\r
+ */\r
+public class CommandAdapter {\r
+\r
+    /** コマンドクラスのキー */\r
+    public static String COMMAND_KEY = Command.class.getName();\r
+\r
+    /** コマンド呼び出しクラスのキー */\r
+    public static String COMMAND_INVOKER_KEY = CommandInvoker.class.getName();\r
+\r
+    /**\r
+     * システムプロパティに登録された{@link Command}をシステムプロパティに登録された{@link CommandInvoker}\r
+     * で実行します。\r
+     * \r
+     * @param args\r
+     *            引数の配列\r
+     */\r
+    public static void main(String[] args) {\r
+        String commandName = System.getProperty(COMMAND_KEY);\r
+        if (commandName == null) {\r
+            throw new SystemPropertyNotFoundRuntimeException(COMMAND_KEY);\r
+        }\r
+        String invokerName = System.getProperty(COMMAND_INVOKER_KEY);\r
+        if (invokerName == null) {\r
+            throw new SystemPropertyNotFoundRuntimeException(\r
+                    COMMAND_INVOKER_KEY);\r
+        }\r
+        Command command = ReflectUtil.newInstance(Command.class, commandName);\r
+        ArgumentsParser parser = new ArgumentsParser(command);\r
+        parser.parse(args);\r
+\r
+        CommandInvoker invoker = ReflectUtil.newInstance(CommandInvoker.class,\r
+                invokerName);\r
+        invoker.invoke(command);\r
+    }\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandInvoker.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandInvoker.java
new file mode 100644 (file)
index 0000000..4e17e89
--- /dev/null
@@ -0,0 +1,32 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.command;\r
+\r
+/**\r
+ * コマンドを呼び出すインタフェースです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public interface CommandInvoker {\r
+\r
+    /**\r
+     * コマンドを呼び出します。\r
+     * \r
+     * @param command\r
+     *            コマンド\r
+     */\r
+    void invoke(Command command);\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/exception/CommandFailedRuntimeException.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/exception/CommandFailedRuntimeException.java
new file mode 100644 (file)
index 0000000..73400c7
--- /dev/null
@@ -0,0 +1,55 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.exception;\r
+\r
+import org.seasar.framework.exception.SRuntimeException;\r
+\r
+/**\r
+ * コマンドの実行が失敗した場合にスローされる例外です。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class CommandFailedRuntimeException extends SRuntimeException {\r
+\r
+    private static final long serialVersionUID = 1L;\r
+\r
+    /** コマンドのクラス名 */\r
+    protected String commandClassName;\r
+\r
+    /**\r
+     * インスタンスを構築します。\r
+     * \r
+     * @param cause\r
+     *            原因\r
+     * @param commandClassName\r
+     *            コマンドのクラス名\r
+     */\r
+    public CommandFailedRuntimeException(Throwable cause,\r
+            String commandClassName) {\r
+        super("ES2JDBCGen0005", new Object[] { commandClassName, cause }, cause);\r
+        this.commandClassName = commandClassName;\r
+    }\r
+\r
+    /**\r
+     * コマンドのクラス名を返します。\r
+     * \r
+     * @return コマンドのクラス名\r
+     */\r
+    public String getCommandClassName() {\r
+        return commandClassName;\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsBuilder.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsBuilder.java
new file mode 100644 (file)
index 0000000..a42501e
--- /dev/null
@@ -0,0 +1,87 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.arg;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.seasar.extension.jdbc.gen.internal.argtype.ArgumentType;\r
+import org.seasar.extension.jdbc.gen.internal.argtype.ArgumentTypeRegistry;\r
+import org.seasar.framework.beans.BeanDesc;\r
+import org.seasar.framework.beans.PropertyDesc;\r
+import org.seasar.framework.beans.factory.BeanDescFactory;\r
+import org.seasar.framework.log.Logger;\r
+\r
+/**\r
+ * コマンドライン用の引数を組み立てるクラスです。\r
+ * <p>\r
+ * JavaBeanのプロパティと値の組を「=」で連結し1つの引数とします。\r
+ * </p>\r
+ * \r
+ * @author taedium\r
+ */\r
+public class ArgumentsBuilder {\r
+\r
+    /** ロガー */\r
+    protected static Logger logger = Logger.getLogger(ArgumentsBuilder.class);\r
+\r
+    /** JavaBeanのインスタンス */\r
+    protected Object bean;\r
+\r
+    /** Bean記述 */\r
+    protected BeanDesc beanDesc;\r
+\r
+    /**\r
+     * インスタンスを構築します。\r
+     * \r
+     * @param bean\r
+     *            JavaBeanのインスタンス\r
+     */\r
+    public ArgumentsBuilder(Object bean) {\r
+        if (bean == null) {\r
+            throw new NullPointerException("bean");\r
+        }\r
+        this.bean = bean;\r
+        beanDesc = BeanDescFactory.getBeanDesc(bean.getClass());\r
+    }\r
+\r
+    /**\r
+     * 引数を組み立てます。\r
+     * \r
+     * @return 引数のリスト\r
+     */\r
+    public List<String> build() {\r
+        ArrayList<String> args = new ArrayList<String>();\r
+        for (int i = 0; i < beanDesc.getPropertyDescSize(); i++) {\r
+            PropertyDesc propertyDesc = beanDesc.getPropertyDesc(i);\r
+            if (!propertyDesc.hasReadMethod()) {\r
+                continue;\r
+            }\r
+            ArgumentType<Object> argumentType = ArgumentTypeRegistry\r
+                    .getArgumentType(propertyDesc);\r
+            if (argumentType == null) {\r
+                logger.log("WS2JDBCGEN0001", new Object[] {\r
+                        bean.getClass().getName(),\r
+                        propertyDesc.getPropertyName() });\r
+                continue;\r
+            }\r
+            String name = propertyDesc.getPropertyName();\r
+            Object value = propertyDesc.getValue(bean);\r
+            args.add(name + "=" + argumentType.toText(value));\r
+        }\r
+        return args;\r
+    }\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsParser.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsParser.java
new file mode 100644 (file)
index 0000000..ebd5049
--- /dev/null
@@ -0,0 +1,91 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.arg;\r
+\r
+import org.seasar.extension.jdbc.gen.internal.argtype.ArgumentType;\r
+import org.seasar.extension.jdbc.gen.internal.argtype.ArgumentTypeRegistry;\r
+import org.seasar.framework.beans.BeanDesc;\r
+import org.seasar.framework.beans.PropertyDesc;\r
+import org.seasar.framework.beans.factory.BeanDescFactory;\r
+import org.seasar.framework.log.Logger;\r
+\r
+/**\r
+ * コマンドラインの引数を解析するクラスです。\r
+ * <p>\r
+ * それぞれの引数は「=」で連結されたキーと値の組である必要があります。 このクラスは、キーに対応するJavaBeanのプロパティに値を設定します。\r
+ * </p>\r
+ * \r
+ * @author taedium\r
+ */\r
+public class ArgumentsParser {\r
+\r
+    /** ロガー */\r
+    protected static Logger logger = Logger.getLogger(ArgumentsParser.class);\r
+\r
+    /** JavaBeanのインスタンス */\r
+    protected Object bean;\r
+\r
+    /** Bean記述 */\r
+    protected BeanDesc beanDesc;\r
+\r
+    /**\r
+     * インスタンスを構築します。\r
+     * \r
+     * @param bean\r
+     *            JavaBeanのインスタンス\r
+     */\r
+    public ArgumentsParser(Object bean) {\r
+        if (bean == null) {\r
+            throw new NullPointerException("bean");\r
+        }\r
+        this.bean = bean;\r
+        beanDesc = BeanDescFactory.getBeanDesc(bean.getClass());\r
+    }\r
+\r
+    /**\r
+     * 解析します。\r
+     * \r
+     * @param args\r
+     */\r
+    public void parse(String[] args) {\r
+        for (String arg : args) {\r
+            int pos = arg.indexOf("=");\r
+            if (pos < 0) {\r
+                throw new IllegalArgumentException(arg);\r
+            }\r
+            String key = arg.substring(0, pos);\r
+            String value = arg.substring(pos + 1, arg.length());\r
+            if (!beanDesc.hasPropertyDesc(key)) {\r
+                continue;\r
+            }\r
+            PropertyDesc propertyDesc = beanDesc.getPropertyDesc(key);\r
+            if (!propertyDesc.hasWriteMethod()) {\r
+                continue;\r
+            }\r
+            ArgumentType<?> argumentType = ArgumentTypeRegistry\r
+                    .getArgumentType(propertyDesc);\r
+            if (argumentType == null) {\r
+                logger.log("WS2JDBCGEN0001", new Object[] {\r
+                        bean.getClass().getName(),\r
+                        propertyDesc.getPropertyName() });\r
+                continue;\r
+            }\r
+            Object propertyValue = argumentType.toObject(value);\r
+            propertyDesc.setValue(bean, propertyValue);\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentType.java
new file mode 100644 (file)
index 0000000..fc0389f
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+/**\r
+ * コマンドラインの引数の値の型を表すインタフェースです。\r
+ * \r
+ * @author taedium\r
+ * @param <T>\r
+ *            引数の値の型\r
+ */\r
+public interface ArgumentType<T> {\r
+\r
+    /**\r
+     * 引数の値の文字列を適切な型のオブジェクトに変換します。\r
+     * \r
+     * @param value\r
+     *            引数の文字列\r
+     * @return オブジェクト\r
+     */\r
+    T toObject(String value);\r
+\r
+    /**\r
+     * 引数の値のオブジェクトを文字列に変換します。\r
+     * \r
+     * @param value\r
+     *            引数のオブジェクト\r
+     * @return 文字列\r
+     */\r
+    String toText(T value);\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentTypeRegistry.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentTypeRegistry.java
new file mode 100644 (file)
index 0000000..7e16bf6
--- /dev/null
@@ -0,0 +1,145 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import java.io.File;\r
+import java.lang.reflect.Constructor;\r
+import java.util.Collection;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.concurrent.ConcurrentHashMap;\r
+\r
+import org.seasar.framework.beans.PropertyDesc;\r
+import org.seasar.framework.util.ClassUtil;\r
+import org.seasar.framework.util.tiger.ReflectionUtil;\r
+\r
+/**\r
+ * {@link ArgumentType}を管理するクラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class ArgumentTypeRegistry {\r
+\r
+    /** 引数の値のクラスをキー、 {@link ArgumentType}のコンストラクタを値とするマップ */\r
+    protected static Map<Class<?>, Constructor<? extends ArgumentType<?>>> argTypeMap = new ConcurrentHashMap<Class<?>, Constructor<? extends ArgumentType<?>>>();\r
+    static {\r
+        argTypeMap.put(Boolean.class, ReflectionUtil.getConstructor(\r
+                BooleanType.class, null));\r
+        argTypeMap.put(Character.class, ReflectionUtil.getConstructor(\r
+                CharacterType.class, null));\r
+        argTypeMap.put(String.class, ReflectionUtil.getConstructor(\r
+                StringType.class, null));\r
+        argTypeMap.put(File.class, ReflectionUtil.getConstructor(\r
+                FileType.class, null));\r
+        argTypeMap.put(Class.class, ReflectionUtil.getConstructor(\r
+                ClassType.class, null));\r
+    }\r
+\r
+    /**\r
+     * {@link ArgumentType}を返します。\r
+     * \r
+     * @param <T>\r
+     *            引数の値の型\r
+     * @param propertyDesc\r
+     *            プロパティ記述\r
+     * @return {@link ArgumentType}\r
+     */\r
+    public static <T> ArgumentType<T> getArgumentType(PropertyDesc propertyDesc) {\r
+        Class<?> propertyType = propertyDesc.getPropertyType();\r
+        if (propertyDesc.isParameterized()\r
+                && Collection.class.isAssignableFrom(propertyType)) {\r
+            Class<?> elementClass = propertyDesc.getElementClassOfCollection();\r
+            return getCollectionArgumentType(propertyType, elementClass);\r
+        }\r
+        return getArgumentType(propertyType);\r
+    }\r
+\r
+    /**\r
+     * {@link ArgumentType}を返します。\r
+     * \r
+     * @param <T>\r
+     *            引数の値の型\r
+     * @param clazz\r
+     *            引数の値のクラス\r
+     * @return {@link ArgumentType}\r
+     */\r
+    @SuppressWarnings("unchecked")\r
+    protected static <T> ArgumentType<T> getArgumentType(Class<?> clazz) {\r
+        clazz = ClassUtil.getWrapperClassIfPrimitive(clazz);\r
+        if (argTypeMap.containsKey(clazz)) {\r
+            Constructor<? extends ArgumentType<?>> constructor = argTypeMap\r
+                    .get(clazz);\r
+            return (ArgumentType<T>) ReflectionUtil.newInstance(constructor,\r
+                    null);\r
+        }\r
+        if (Number.class.isAssignableFrom(clazz)) {\r
+            return new NumberType(clazz);\r
+        }\r
+        if (Enum.class.isAssignableFrom(clazz)) {\r
+            return new EnumType(clazz);\r
+        }\r
+        return null;\r
+    }\r
+\r
+    /**\r
+     * {@link ArgumentType}を返します。\r
+     * \r
+     * @param <T>\r
+     *            引数の値の型\r
+     * @param collectioinClass\r
+     *            コレクションのクラス\r
+     * @param elementClass\r
+     *            コレクションの要素のクラス\r
+     * @return {@link ArgumentType}を返します。\r
+     */\r
+    @SuppressWarnings("unchecked")\r
+    protected static <T> ArgumentType<T> getCollectionArgumentType(\r
+            Class<?> collectioinClass, Class<?> elementClass) {\r
+        ArgumentType<?> argumentType = getArgumentType(elementClass);\r
+        if (List.class.isAssignableFrom(collectioinClass)) {\r
+            return new ListType(argumentType);\r
+        }\r
+        return null;\r
+    }\r
+\r
+    /**\r
+     * {@link ArgumentType}を登録します。\r
+     * \r
+     * @param clazz\r
+     *            引数の値のクラス\r
+     */\r
+    protected static void register(Class<? extends ArgumentType<?>> clazz) {\r
+        if (clazz == null) {\r
+            throw new NullPointerException("clazz");\r
+        }\r
+        Constructor<? extends ArgumentType<?>> constructor = ReflectionUtil\r
+                .getConstructor(clazz, null);\r
+        argTypeMap.put(clazz, constructor);\r
+    }\r
+\r
+    /**\r
+     * {@link ArgumentType}を削除します。\r
+     * \r
+     * @param clazz\r
+     *            引数の値のクラス\r
+     */\r
+    protected static void deregister(Class<? extends ArgumentType<?>> clazz) {\r
+        if (clazz == null) {\r
+            throw new NullPointerException("clazz");\r
+        }\r
+        argTypeMap.remove(clazz);\r
+    }\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/BooleanType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/BooleanType.java
new file mode 100644 (file)
index 0000000..2eef9a5
--- /dev/null
@@ -0,0 +1,41 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import org.seasar.framework.util.StringUtil;\r
+\r
+/**\r
+ * {@link Boolean}を扱う{@link ArgumentType}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class BooleanType implements ArgumentType<Boolean> {\r
+\r
+    public Boolean toObject(String value) {\r
+        if (StringUtil.isEmpty(value)) {\r
+            return null;\r
+        }\r
+        return Boolean.valueOf(value);\r
+    }\r
+\r
+    public String toText(Boolean value) {\r
+        if (value == null) {\r
+            return "";\r
+        }\r
+        return value.toString();\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/CharacterType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/CharacterType.java
new file mode 100644 (file)
index 0000000..63b3afe
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import org.seasar.framework.util.StringConversionUtil;\r
+import org.seasar.framework.util.StringUtil;\r
+\r
+/**\r
+ * {@link Character}を扱う{@link ArgumentType}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class CharacterType implements ArgumentType<Character> {\r
+\r
+    public Character toObject(String value) {\r
+        if (StringUtil.isEmpty(value)) {\r
+            return null;\r
+        }\r
+        String s = value.replace("\\u", "");\r
+        int ch = Integer.valueOf(s);\r
+        return (char) ch;\r
+    }\r
+\r
+    public String toText(Character value) {\r
+        if (value == null) {\r
+            return "";\r
+        }\r
+        char ch = value.charValue();\r
+        return "\\u" + StringConversionUtil.toString((int) ch, "0000");\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ClassType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ClassType.java
new file mode 100644 (file)
index 0000000..76265b3
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import org.seasar.framework.util.StringUtil;\r
+import org.seasar.framework.util.tiger.ReflectionUtil;\r
+\r
+/**\r
+ * {@link Class}を扱う{@link ArgumentType}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ * @param <T>\r
+ *            クラスの型\r
+ */\r
+public class ClassType implements ArgumentType<Class<?>> {\r
+\r
+    public Class<?> toObject(String value) {\r
+        if (StringUtil.isEmpty(value)) {\r
+            return null;\r
+        }\r
+        return ReflectionUtil.forName(value);\r
+    }\r
+\r
+    public String toText(Class<?> value) {\r
+        if (value == null) {\r
+            return "";\r
+        }\r
+        return value.getName();\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/EnumType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/EnumType.java
new file mode 100644 (file)
index 0000000..df7235d
--- /dev/null
@@ -0,0 +1,56 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import org.seasar.framework.util.StringUtil;\r
+\r
+/**\r
+ * {@link Enum}を扱う{@link ArgumentType}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ * @param <T>\r
+ *            {@link Enum}のサブタイプ\r
+ */\r
+public class EnumType<T extends Enum<T>> implements ArgumentType<T> {\r
+\r
+    /** 列挙型のクラス */\r
+    protected Class<T> enumClass;\r
+\r
+    /**\r
+     * インスタンスを構築します。\r
+     * \r
+     * @param enumClass\r
+     *            列挙型のクラス\r
+     */\r
+    public EnumType(Class<T> enumClass) {\r
+        this.enumClass = enumClass;\r
+    }\r
+\r
+    public T toObject(String value) {\r
+        if (StringUtil.isEmpty(value)) {\r
+            return null;\r
+        }\r
+        return Enum.valueOf(enumClass, value);\r
+    }\r
+\r
+    public String toText(T value) {\r
+        if (value == null) {\r
+            return "";\r
+        }\r
+        return value.name();\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/FileType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/FileType.java
new file mode 100644 (file)
index 0000000..6e7b9ac
--- /dev/null
@@ -0,0 +1,47 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import java.io.File;\r
+\r
+import org.seasar.extension.jdbc.gen.internal.util.ArgumentUtil;\r
+import org.seasar.extension.jdbc.gen.internal.util.FileUtil;\r
+import org.seasar.framework.util.StringUtil;\r
+\r
+/**\r
+ * {@link File}を扱う{@link ArgumentType}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class FileType implements ArgumentType<File> {\r
+\r
+    public File toObject(String value) {\r
+        if (StringUtil.isEmpty(value)) {\r
+            return null;\r
+        }\r
+        String s = ArgumentUtil.decode(value);\r
+        return new File(s);\r
+    }\r
+\r
+    public String toText(File value) {\r
+        if (value == null) {\r
+            return "";\r
+        }\r
+        String path = FileUtil.getCanonicalPath(value);\r
+        return ArgumentUtil.encode(path);\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ListType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ListType.java
new file mode 100644 (file)
index 0000000..8dad176
--- /dev/null
@@ -0,0 +1,236 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.seasar.extension.jdbc.gen.internal.util.ArgumentUtil;\r
+import org.seasar.framework.util.StringUtil;\r
+\r
+import static org.seasar.extension.jdbc.gen.internal.argtype.ListType.TokenType.*;\r
+\r
+/**\r
+ * {@link List}を扱う{@link ArgumentType}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ * @param <T>\r
+ *            リストの要素の型\r
+ */\r
+public class ListType<T> implements ArgumentType<List<? extends T>> {\r
+\r
+    /** 開き角括弧 */\r
+    protected static String OPEN_BRACKET = "[";\r
+\r
+    /** 閉じ角括弧 */\r
+    protected static String CLOSE_BRACKET = "]";\r
+\r
+    /** リストの要素に対応する{@link ArgumentType} */\r
+    protected ArgumentType<T> argumentType;\r
+\r
+    /**\r
+     * @param argumentType\r
+     */\r
+    public ListType(ArgumentType<T> argumentType) {\r
+        this.argumentType = argumentType;\r
+    }\r
+\r
+    public List<? extends T> toObject(String value) {\r
+        if (StringUtil.isEmpty(value)) {\r
+            return null;\r
+        }\r
+        List<T> list = new ArrayList<T>();\r
+        String s = StringUtil.ltrim(value, OPEN_BRACKET);\r
+        s = StringUtil.rtrim(s, CLOSE_BRACKET);\r
+        Tokenizer tokenizer = new Tokenizer(s);\r
+        nextTokenLoop: for (;;) {\r
+            switch (tokenizer.nextToken()) {\r
+            case QUOTED_VALUE:\r
+            case VALUE:\r
+                String token = tokenizer.getToken();\r
+                list.add(argumentType.toObject(token));\r
+                break;\r
+            case END:\r
+                break nextTokenLoop;\r
+            }\r
+        }\r
+        return list;\r
+    }\r
+\r
+    public String toText(List<? extends T> value) {\r
+        if (value == null) {\r
+            return "";\r
+        }\r
+        StringBuilder buf = new StringBuilder();\r
+        buf.append(OPEN_BRACKET);\r
+        for (T o : value) {\r
+            buf.append(argumentType.toText(o));\r
+            buf.append(",");\r
+        }\r
+        if (value.size() > 0) {\r
+            buf.setLength(buf.length() - 1);\r
+        }\r
+        buf.append(CLOSE_BRACKET);\r
+        return buf.toString();\r
+    }\r
+\r
+    /**\r
+     * トークンのタイプです。\r
+     * \r
+     * @author taedium\r
+     */\r
+    protected static enum TokenType {\r
+        /** クォートされた値 */\r
+        QUOTED_VALUE,\r
+        /** クォートされていない値 */\r
+        VALUE,\r
+        /** 区切り文字 */\r
+        DELIMITER,\r
+        /** トークンの最後 */\r
+        END\r
+    }\r
+\r
+    /**\r
+     * リストの引数の値を区切るクラスです。\r
+     * \r
+     * @author taedium\r
+     */\r
+    protected static class Tokenizer {\r
+\r
+        /** 区切り文字 */\r
+        protected char delimiter = ArgumentUtil.DELIMITER_CHAR;\r
+\r
+        /** 引用句 */\r
+        protected char quote = ArgumentUtil.QUOTE_CHAR;\r
+\r
+        /** 値 */\r
+        protected String value;\r
+\r
+        /** 長さ */\r
+        protected int length;\r
+\r
+        /** 位置 */\r
+        protected int pos;\r
+\r
+        /** 次の位置 */\r
+        protected int nextPos;\r
+\r
+        /** トークン */\r
+        protected String token;\r
+\r
+        /** トークンのタイプ */\r
+        protected TokenType type;\r
+\r
+        /**\r
+         * インスタンスを構築します。\r
+         * \r
+         * @param value\r
+         *            値\r
+         */\r
+        protected Tokenizer(String value) {\r
+\r
+            this.value = value;\r
+            this.length = value.length();\r
+            peek(0);\r
+        }\r
+\r
+        /**\r
+         * 次のトークンを前もって調べます。\r
+         * \r
+         * @param index\r
+         *            インデックス\r
+         */\r
+        protected void peek(int index) {\r
+            if (index < length) {\r
+                char c = value.charAt(index);\r
+                if (c == delimiter) {\r
+                    type = DELIMITER;\r
+                    pos = index;\r
+                    nextPos = index + 1;\r
+                } else if (c == quote) {\r
+                    type = QUOTED_VALUE;\r
+                    pos = index;\r
+                    nextPos = index + 1;\r
+                } else {\r
+                    type = VALUE;\r
+                    pos = index;\r
+                    nextPos = index;\r
+                }\r
+            } else {\r
+                type = TokenType.END;\r
+            }\r
+        }\r
+\r
+        /**\r
+         * 次のトークンを返します。\r
+         * \r
+         * @return 次のトークン\r
+         */\r
+        protected TokenType nextToken() {\r
+            switch (type) {\r
+            case QUOTED_VALUE:\r
+                for (int i = nextPos; i < length; i++) {\r
+                    char c = value.charAt(i);\r
+                    if (c == quote) {\r
+                        i++;\r
+                        if (i >= length) {\r
+                            token = value.substring(pos, i);\r
+                            type = END;\r
+                            return QUOTED_VALUE;\r
+                        } else if (value.charAt(i) == delimiter) {\r
+                            token = value.substring(pos, i);\r
+                            peek(i);\r
+                            return QUOTED_VALUE;\r
+                        }\r
+                    }\r
+                }\r
+                token = value.substring(pos, length);\r
+                type = END;\r
+                return QUOTED_VALUE;\r
+            case VALUE:\r
+                for (int i = nextPos; i < length; i++) {\r
+                    char c = value.charAt(i);\r
+                    if (c == delimiter) {\r
+                        token = value.substring(pos, i);\r
+                        peek(i);\r
+                        return VALUE;\r
+                    }\r
+                }\r
+                token = value.substring(pos, length);\r
+                type = END;\r
+                return QUOTED_VALUE;\r
+            case DELIMITER:\r
+                token = value.substring(pos, nextPos);\r
+                peek(nextPos);\r
+                return DELIMITER;\r
+            case END:\r
+                token = null;\r
+                return END;\r
+            }\r
+            throw new IllegalStateException("type");\r
+        }\r
+\r
+        /**\r
+         * トークンを返します。\r
+         * \r
+         * @return トークン\r
+         */\r
+        protected String getToken() {\r
+            return token;\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/NumberType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/NumberType.java
new file mode 100644 (file)
index 0000000..fb77878
--- /dev/null
@@ -0,0 +1,59 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import org.seasar.framework.util.NumberConversionUtil;\r
+import org.seasar.framework.util.StringConversionUtil;\r
+import org.seasar.framework.util.StringUtil;\r
+\r
+/**\r
+ * {@link Number}を扱う{@link ArgumentType}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ * @param <T>\r
+ *            {@link Number}のサブタイプ\r
+ */\r
+public class NumberType<T extends Number> implements ArgumentType<T> {\r
+\r
+    /** 数値を表すクラス */\r
+    protected Class<T> numberClass;\r
+\r
+    /**\r
+     *インスタンスを構築します。\r
+     * \r
+     * @param numberClass\r
+     *            数値を表すクラス\r
+     */\r
+    public NumberType(Class<T> numberClass) {\r
+        this.numberClass = numberClass;\r
+    }\r
+\r
+    public T toObject(String value) {\r
+        if (StringUtil.isEmpty(value)) {\r
+            return null;\r
+        }\r
+        Object number = NumberConversionUtil.convertNumber(numberClass, value);\r
+        return numberClass.cast(number);\r
+    }\r
+\r
+    public String toText(T value) {\r
+        if (value == null) {\r
+            return "";\r
+        }\r
+        return StringConversionUtil.toString(value);\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/StringType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/StringType.java
new file mode 100644 (file)
index 0000000..cf3b704
--- /dev/null
@@ -0,0 +1,42 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.argtype;\r
+\r
+import org.seasar.extension.jdbc.gen.internal.util.ArgumentUtil;\r
+import org.seasar.framework.util.StringUtil;\r
+\r
+/**\r
+ * {@link String}を扱う{@link ArgumentType}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class StringType implements ArgumentType<String> {\r
+\r
+    public String toObject(String value) {\r
+        if (StringUtil.isEmpty(value)) {\r
+            return null;\r
+        }\r
+        return ArgumentUtil.decode(value);\r
+    }\r
+\r
+    public String toText(String value) {\r
+        if (value == null) {\r
+            return "";\r
+        }\r
+        return ArgumentUtil.encode(value);\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/AbstractCommand.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/AbstractCommand.java
new file mode 100644 (file)
index 0000000..69aaeb7
--- /dev/null
@@ -0,0 +1,177 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.command;\r
+\r
+import org.seasar.extension.jdbc.gen.command.Command;\r
+import org.seasar.extension.jdbc.gen.exception.CommandFailedRuntimeException;\r
+import org.seasar.extension.jdbc.gen.internal.util.SingletonS2ContainerFactorySupport;\r
+import org.seasar.framework.beans.BeanDesc;\r
+import org.seasar.framework.beans.PropertyDesc;\r
+import org.seasar.framework.beans.factory.BeanDescFactory;\r
+import org.seasar.framework.container.factory.SingletonS2ContainerFactory;\r
+import org.seasar.framework.log.Logger;\r
+\r
+/**\r
+ * コマンドの抽象クラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public abstract class AbstractCommand implements Command {\r
+\r
+    /** 設定ファイルのパス */\r
+    protected String configPath = "s2jdbc.dicon";\r
+\r
+    /** 環境名 */\r
+    protected String env = "ut";\r
+\r
+    /** {@link SingletonS2ContainerFactory}のサポート */\r
+    protected SingletonS2ContainerFactorySupport containerFactorySupport;\r
+\r
+    /**\r
+     * インスタンスを構築します。\r
+     */\r
+    public AbstractCommand() {\r
+    }\r
+\r
+    /**\r
+     * 設定ファイルのパスを返します。\r
+     * \r
+     * @return 設定ファイルのパス\r
+     */\r
+    public String getConfigPath() {\r
+        return configPath;\r
+    }\r
+\r
+    /**\r
+     * 設定ファイルのパスを設定します。\r
+     * \r
+     * @param configPath\r
+     *            設定ファイルのパス\r
+     */\r
+    public void setConfigPath(String configPath) {\r
+        this.configPath = configPath;\r
+    }\r
+\r
+    /**\r
+     * 環境名を返します。\r
+     * \r
+     * @return 環境名\r
+     */\r
+    public String getEnv() {\r
+        return env;\r
+    }\r
+\r
+    /**\r
+     * 環境名を設定します。\r
+     * \r
+     * @param env\r
+     *            環境名\r
+     */\r
+    public void setEnv(String env) {\r
+        this.env = env;\r
+    }\r
+\r
+    public final void execute() {\r
+        String commandClassName = getClass().getName();\r
+        getLogger().log("DS2JDBCGen0003", new Object[] { commandClassName });\r
+        logWritableProperties();\r
+        validate();\r
+        init();\r
+        try {\r
+            doExecute();\r
+        } catch (Throwable t) {\r
+            throw new CommandFailedRuntimeException(t, commandClassName);\r
+        } finally {\r
+            destroy();\r
+        }\r
+        getLogger().log("DS2JDBCGen0008", new Object[] { commandClassName });\r
+    }\r
+\r
+    /**\r
+     * 設定可能なプロパティの値をログ出力します。\r
+     */\r
+    protected void logWritableProperties() {\r
+        BeanDesc beanDesc = BeanDescFactory.getBeanDesc(getClass());\r
+        for (int i = 0; i < beanDesc.getPropertyDescSize(); i++) {\r
+            PropertyDesc propertyDesc = beanDesc.getPropertyDesc(i);\r
+            if (propertyDesc.hasWriteMethod() && propertyDesc.hasReadMethod()) {\r
+                getLogger().info(propertyDesc.getPropertyName());\r
+                getLogger().info(propertyDesc.getWriteMethod());\r
+                getLogger().log(\r
+                        "DS2JDBCGen0001",\r
+                        new Object[] { propertyDesc.getPropertyName(),\r
+                                propertyDesc.getValue(this) });\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * 検証します。\r
+     */\r
+    protected final void validate() {\r
+        doValidate();\r
+    }\r
+\r
+    /**\r
+     * 初期化します。\r
+     */\r
+    protected final void init() {\r
+        containerFactorySupport = new SingletonS2ContainerFactorySupport(\r
+                configPath, env);\r
+        containerFactorySupport.init();\r
+        doInit();\r
+    }\r
+\r
+    /**\r
+     * 破棄します。\r
+     */\r
+    protected final void destroy() {\r
+        doDestroy();\r
+        if (containerFactorySupport != null) {\r
+            containerFactorySupport.destory();\r
+        }\r
+    }\r
+\r
+    /**\r
+     * サブクラスで検証します。\r
+     */\r
+    protected abstract void doValidate();\r
+\r
+    /**\r
+     * サブクラスで初期化します。\r
+     */\r
+    protected abstract void doInit();\r
+\r
+    /**\r
+     * サブクラスで実行します。\r
+     * \r
+     * @throws Throwable\r
+     */\r
+    protected abstract void doExecute() throws Throwable;\r
+\r
+    /**\r
+     * サブクラスで破棄します。\r
+     */\r
+    protected abstract void doDestroy();\r
+\r
+    /**\r
+     * ロガーを返します。\r
+     * \r
+     * @return ロガー\r
+     */\r
+    protected abstract Logger getLogger();\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/CommandInvokerImpl.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/CommandInvokerImpl.java
new file mode 100644 (file)
index 0000000..dbdd03e
--- /dev/null
@@ -0,0 +1,31 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.command;\r
+\r
+import org.seasar.extension.jdbc.gen.command.Command;\r
+import org.seasar.extension.jdbc.gen.command.CommandInvoker;\r
+\r
+/**\r
+ * {@link CommandInvoker}の実装クラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class CommandInvokerImpl implements CommandInvoker {\r
+\r
+    public void invoke(Command command) {\r
+        command.execute();\r
+    }\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/ClassUnmatchRuntimeException.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/ClassUnmatchRuntimeException.java
new file mode 100644 (file)
index 0000000..b435651
--- /dev/null
@@ -0,0 +1,69 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.exception;\r
+\r
+import org.seasar.framework.exception.SRuntimeException;\r
+\r
+/**\r
+ * ある型を期待する型でキャストできない場合にスローされる例外です。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class ClassUnmatchRuntimeException extends SRuntimeException {\r
+\r
+    private static final long serialVersionUID = 1L;\r
+\r
+    /** 期待するクラス */\r
+    protected Class<?> expectedClass;\r
+\r
+    /** 実際のクラス */\r
+    protected Class<?> actualClass;\r
+\r
+    /**\r
+     * インスタンスを構築します。\r
+     * \r
+     * @param expectedClass\r
+     *            期待するクラス\r
+     * @param actualClass\r
+     *            実際のクラス\r
+     */\r
+    public ClassUnmatchRuntimeException(Class<?> expectedClass,\r
+            Class<?> actualClass) {\r
+        super("ES2JDBCGen0023", new Object[] { actualClass.getName(),\r
+                expectedClass.getName(), });\r
+        this.expectedClass = expectedClass;\r
+        this.actualClass = actualClass;\r
+    }\r
+\r
+    /**\r
+     * 期待するクラスを返します。\r
+     * \r
+     * @return 期待するクラス\r
+     */\r
+    public Class<?> getExpectedClass() {\r
+        return expectedClass;\r
+    }\r
+\r
+    /**\r
+     * 実際のクラスを返します。\r
+     * \r
+     * @return 実際のクラス\r
+     */\r
+    public Class<?> getActualClass() {\r
+        return actualClass;\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/SystemPropertyNotFoundRuntimeException.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/SystemPropertyNotFoundRuntimeException.java
new file mode 100644 (file)
index 0000000..ad31a63
--- /dev/null
@@ -0,0 +1,52 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.exception;\r
+\r
+import org.seasar.framework.exception.SRuntimeException;\r
+\r
+/**\r
+ * システムプロパティが見つからない場合にスローされる例外です。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class SystemPropertyNotFoundRuntimeException extends SRuntimeException {\r
+\r
+    private static final long serialVersionUID = 1L;\r
+\r
+    /** プロパティ名 */\r
+    protected String propertyName;\r
+\r
+    /**\r
+     * インスタンスを構築します。\r
+     * \r
+     * @param propertyName\r
+     *            プロパティ名\r
+     */\r
+    public SystemPropertyNotFoundRuntimeException(String propertyName) {\r
+        super("ES2JDBCGen0018", new Object[] { propertyName });\r
+        this.propertyName = propertyName;\r
+    }\r
+\r
+    /**\r
+     * プロパティ名を返します。\r
+     * \r
+     * @return プロパティ名\r
+     */\r
+    public String getPropertyName() {\r
+        return propertyName;\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ArgumentUtil.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ArgumentUtil.java
new file mode 100644 (file)
index 0000000..a3c3d82
--- /dev/null
@@ -0,0 +1,79 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.util;\r
+\r
+import org.seasar.framework.util.StringUtil;\r
+\r
+/**\r
+ * 引数に関するユーティリティクラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class ArgumentUtil {\r
+\r
+    /** 引用符 */\r
+    public static String QUOTE = "'";\r
+\r
+    /** char型としての引用符 */\r
+    public static char QUOTE_CHAR = '\'';\r
+\r
+    /** エスケープされた引用符 */\r
+    public static String ESCAPED_QUOTE = "'";\r
+\r
+    /** 区切り文字 */\r
+    public static String DELIMITER = ",";\r
+\r
+    /** char型としての区切り文字 */\r
+    public static char DELIMITER_CHAR = ',';\r
+\r
+    /**\r
+     * \r
+     */\r
+    protected ArgumentUtil() {\r
+    }\r
+\r
+    /**\r
+     * エンコードします。\r
+     * \r
+     * @param value\r
+     *            値\r
+     * @return エンコードされた値\r
+     */\r
+    public static String encode(String value) {\r
+        if (value == null) {\r
+            throw new NullPointerException("value");\r
+        }\r
+        String s = value.replace(QUOTE, ESCAPED_QUOTE);\r
+        return QUOTE + s + QUOTE;\r
+    }\r
+\r
+    /**\r
+     * デコードします。\r
+     * \r
+     * @param value\r
+     *            値\r
+     * @return デコードされた値\r
+     */\r
+    public static String decode(String value) {\r
+        if (value == null) {\r
+            throw new NullPointerException("value");\r
+        }\r
+        String s = StringUtil.ltrim(value, QUOTE);\r
+        s = StringUtil.rtrim(s, QUOTE);\r
+        return s.replace(ESCAPED_QUOTE, QUOTE);\r
+    }\r
+\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/EnvUtil.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/EnvUtil.java
new file mode 100644 (file)
index 0000000..deaa997
--- /dev/null
@@ -0,0 +1,64 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.util;\r
+\r
+import java.lang.reflect.Field;\r
+\r
+import org.seasar.framework.env.Env;\r
+import org.seasar.framework.util.tiger.ReflectionUtil;\r
+\r
+/**\r
+ * {@link Env}に関するユーティリティクラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class EnvUtil {\r
+\r
+    /** 環境名と環境名以外の区切り文字 */\r
+    public static char DELIMITER = '#';\r
+\r
+    /** {@link Env}の環境名を保持するフィールド */\r
+    protected static Field VALUE_FIELD;\r
+    static {\r
+        VALUE_FIELD = ReflectionUtil.getDeclaredField(Env.class, "value");\r
+        VALUE_FIELD.setAccessible(true);\r
+    }\r
+\r
+    /**\r
+     * \r
+     */\r
+    protected EnvUtil() {\r
+    }\r
+\r
+    /**\r
+     * 環境名を返します。\r
+     * \r
+     * @return 環境名\r
+     */\r
+    public static String getValue() {\r
+        return ReflectionUtil.getStaticValue(VALUE_FIELD);\r
+    }\r
+\r
+    /**\r
+     * 環境名を設定します。\r
+     * \r
+     * @param value\r
+     *            環境名\r
+     */\r
+    public static void setValue(String value) {\r
+        ReflectionUtil.setStaticValue(VALUE_FIELD, value);\r
+    }\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/FileUtil.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/FileUtil.java
new file mode 100644 (file)
index 0000000..80d79fe
--- /dev/null
@@ -0,0 +1,247 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.util;\r
+\r
+import java.io.BufferedInputStream;\r
+import java.io.BufferedOutputStream;\r
+import java.io.File;\r
+import java.io.FilenameFilter;\r
+import java.io.IOException;\r
+import java.util.Arrays;\r
+import java.util.Comparator;\r
+\r
+import org.seasar.framework.exception.IORuntimeException;\r
+import org.seasar.framework.util.FileInputStreamUtil;\r
+import org.seasar.framework.util.FileOutputStreamUtil;\r
+import org.seasar.framework.util.InputStreamUtil;\r
+import org.seasar.framework.util.OutputStreamUtil;\r
+\r
+/**\r
+ * {@link File}に関するユーティリティクラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class FileUtil {\r
+\r
+    /**\r
+     * \r
+     */\r
+    protected FileUtil() {\r
+    }\r
+\r
+    /**\r
+     * ディレクトリをコピーします。\r
+     * \r
+     * @param srcDir\r
+     *            コピー元ディレクトリ\r
+     * @param destDir\r
+     *            コピー先ディレクトリ\r
+     * @param filter\r
+     *            フィルタ\r
+     */\r
+    public static void copyDirectory(File srcDir, File destDir,\r
+            FilenameFilter filter) {\r
+        if (!srcDir.isDirectory()) {\r
+            throw new IllegalArgumentException("srcDir");\r
+        }\r
+        if (!getCanonicalPath(srcDir).equals(getCanonicalPath(srcDir))\r
+                && getCanonicalPath(srcDir)\r
+                        .startsWith(getCanonicalPath(srcDir))) {\r
+            throw new IllegalArgumentException("destDir");\r
+        }\r
+        copyDir(srcDir, destDir, filter);\r
+    }\r
+\r
+    /**\r
+     * ディレクトリを再帰的にコピーします。\r
+     * \r
+     * @param srcDir\r
+     *            コピー元ディレクトリ\r
+     * @param destDir\r
+     *            コピー先ディレクトリ\r
+     * @param filter\r
+     *            フィルタ\r
+     */\r
+    protected static void copyDir(File srcDir, File destDir,\r
+            FilenameFilter filter) {\r
+        destDir.mkdirs();\r
+        File[] srcFiles = srcDir.listFiles(filter);\r
+        for (File src : srcFiles) {\r
+            File dest = new File(destDir, src.getName());\r
+            if (src.isDirectory()) {\r
+                copyDir(src, dest, filter);\r
+            } else {\r
+                copyFile(src, dest);\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * ファイルをコピーします。\r
+     * \r
+     * @param src\r
+     *            コピー元ファイル\r
+     * @param dest\r
+     *            コピー先ファイル\r
+     */\r
+    protected static void copyFile(File src, File dest) {\r
+        BufferedInputStream in = null;\r
+        BufferedOutputStream out = null;\r
+        try {\r
+            in = new BufferedInputStream(FileInputStreamUtil.create(src));\r
+            out = new BufferedOutputStream(FileOutputStreamUtil.create(dest));\r
+            byte[] buf = new byte[1024];\r
+            int length;\r
+            while (-1 < (length = in.read(buf))) {\r
+                out.write(buf, 0, length);\r
+                out.flush();\r
+            }\r
+        } catch (IOException e) {\r
+            throw new IORuntimeException(e);\r
+        } finally {\r
+            InputStreamUtil.close(in);\r
+            OutputStreamUtil.close(out);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * ディレクトリを削除します。\r
+     * \r
+     * @param dir\r
+     *            ディレクトリ\r
+     */\r
+    public static void deleteDirectory(File dir) {\r
+        if (!dir.isDirectory()) {\r
+            throw new IllegalArgumentException("dir");\r
+        }\r
+        if (!dir.exists()) {\r
+            throw new IllegalArgumentException("dir");\r
+        }\r
+        deleteDir(dir);\r
+    }\r
+\r
+    /**\r
+     * ディレクトリを再帰的に削除します。\r
+     * \r
+     * @param dir\r
+     *            ディレクトリ\r
+     */\r
+    protected static void deleteDir(File dir) {\r
+        for (File file : dir.listFiles()) {\r
+            if (file.isDirectory()) {\r
+                deleteDir(file);\r
+                file.delete();\r
+            } else {\r
+                file.delete();\r
+            }\r
+        }\r
+        dir.delete();\r
+    }\r
+\r
+    /**\r
+     * この抽象パス名の正規のパス名文字列を返します。\r
+     * \r
+     * @param file\r
+     *            ファイル\r
+     * @return この抽象パス名と同じファイルまたはディレクトリを示す正規パス名文字列\r
+     */\r
+    public static String getCanonicalPath(File file) {\r
+        try {\r
+            return file.getCanonicalPath();\r
+        } catch (IOException e) {\r
+            throw new IORuntimeException(e);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * この抽象パス名の正規の形式を返します。\r
+     * \r
+     * @param file\r
+     *            ファイル\r
+     * @return この抽象パス名と同じファイルまたはディレクトリを示す正規の形式\r
+     */\r
+    public static File getCanonicalFile(File file) {\r
+        try {\r
+            return file.getCanonicalFile();\r
+        } catch (IOException e) {\r
+            throw new IORuntimeException(e);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * ディレクトリを横断します。\r
+     * \r
+     * @param dir\r
+     * @param filter\r
+     * @param comparator\r
+     * @param handler\r
+     */\r
+    public static void traverseDirectory(File dir, FilenameFilter filter,\r
+            Comparator<File> comparator, FileHandler handler) {\r
+        if (!dir.exists()) {\r
+            return;\r
+        }\r
+        File[] files = dir.listFiles(filter);\r
+        if (files == null) {\r
+            return;\r
+        }\r
+        Arrays.sort(files, comparator);\r
+        for (File file : files) {\r
+            if (file.isDirectory()) {\r
+                traverseDirectory(file, filter, comparator, handler);\r
+            }\r
+            handler.handle(file);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Javaファイルを作成します。\r
+     * \r
+     * @param baseDir\r
+     *            ベースディレクトリ\r
+     * @param packageName\r
+     *            パッケージ名\r
+     * @param shortClassName\r
+     *            クラスの単純名\r
+     * @return Javaファイル\r
+     */\r
+    public static File createJavaFile(File baseDir, String packageName,\r
+            String shortClassName) {\r
+        File packageDir;\r
+        if (packageName == null) {\r
+            packageDir = baseDir;\r
+        } else {\r
+            packageDir = new File(baseDir, packageName.replace('.',\r
+                    File.separatorChar));\r
+        }\r
+        return new File(packageDir, shortClassName + ".java");\r
+    }\r
+\r
+    /**\r
+     * ファイルを扱うインタフェースです・\r
+     * \r
+     * @author taedium\r
+     */\r
+    public interface FileHandler {\r
+\r
+        /**\r
+         * 処理します。\r
+         * \r
+         * @param file\r
+         */\r
+        void handle(File file);\r
+    }\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ReflectUtil.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ReflectUtil.java
new file mode 100644 (file)
index 0000000..6622e6f
--- /dev/null
@@ -0,0 +1,53 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.util;\r
+\r
+import org.seasar.extension.jdbc.gen.internal.exception.ClassUnmatchRuntimeException;\r
+import org.seasar.framework.util.ClassUtil;\r
+\r
+/**\r
+ * リフレクションに関するユーティリティクラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class ReflectUtil {\r
+\r
+    /**\r
+     * \r
+     */\r
+    protected ReflectUtil() {\r
+    }\r
+\r
+    /**\r
+     * インスタンス化します。\r
+     * \r
+     * @param <T>\r
+     *            期待するクラスの型\r
+     * @param expectedClass\r
+     *            期待するクラス\r
+     * @param className\r
+     *            インスタンス化対象のクラス名\r
+     * @return 期待するクラスのインスタンス\r
+     */\r
+    public static <T> T newInstance(Class<T> expectedClass, String className) {\r
+        Class<?> actualClass = ClassUtil.forName(className);\r
+        Object obj = ClassUtil.newInstance(actualClass);\r
+        if (expectedClass.isInstance(obj)) {\r
+            return expectedClass.cast(obj);\r
+        }\r
+        throw new ClassUnmatchRuntimeException(expectedClass, actualClass);\r
+    }\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/SingletonS2ContainerFactorySupport.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/SingletonS2ContainerFactorySupport.java
new file mode 100644 (file)
index 0000000..a5c8070
--- /dev/null
@@ -0,0 +1,74 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.internal.util;\r
+\r
+import org.seasar.framework.container.factory.SingletonS2ContainerFactory;\r
+\r
+/**\r
+ * {@link SingletonS2ContainerFactory}の初期化と破棄をサポートするクラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public class SingletonS2ContainerFactorySupport {\r
+\r
+    /** 設定ファイルのパス */\r
+    protected String configPath;\r
+\r
+    /** 環境名 */\r
+    protected String env;\r
+\r
+    /** 元の環境名 */\r
+    protected String originalEnv;\r
+\r
+    /** 初期化された場合{@code true} */\r
+    protected boolean initialized;\r
+\r
+    /**\r
+     * インスタンスを構築します。\r
+     * \r
+     * @param configPath\r
+     *            設定ファイルのパス\r
+     * @param env\r
+     *            環境名\r
+     */\r
+    public SingletonS2ContainerFactorySupport(String configPath, String env) {\r
+        this.configPath = configPath;\r
+        this.env = env;\r
+    }\r
+\r
+    /**\r
+     * 初期化します。\r
+     */\r
+    public void init() {\r
+        if (!SingletonS2ContainerFactory.hasContainer()) {\r
+            initialized = true;\r
+            originalEnv = EnvUtil.getValue();\r
+            EnvUtil.setValue(env);\r
+            SingletonS2ContainerFactory.setConfigPath(configPath);\r
+            SingletonS2ContainerFactory.init();\r
+        }\r
+    }\r
+\r
+    /**\r
+     * 破棄します。\r
+     */\r
+    public void destory() {\r
+        if (initialized) {\r
+            SingletonS2ContainerFactory.destroy();\r
+            EnvUtil.setValue(originalEnv);\r
+        }\r
+    }\r
+}\r
diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/task/AbstractTask.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/task/AbstractTask.java
new file mode 100644 (file)
index 0000000..d781695
--- /dev/null
@@ -0,0 +1,184 @@
+/*\r
+ * Copyright 2004-2008 the Seasar Foundation and the Others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r
+ * either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+package org.seasar.extension.jdbc.gen.task;\r
+\r
+import java.util.List;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.tools.ant.Task;\r
+import org.apache.tools.ant.taskdefs.Java;\r
+import org.apache.tools.ant.types.Commandline;\r
+import org.apache.tools.ant.types.Environment;\r
+import org.apache.tools.ant.types.Path;\r
+import org.apache.tools.ant.types.Reference;\r
+import org.seasar.extension.jdbc.gen.command.Command;\r
+import org.seasar.extension.jdbc.gen.command.CommandAdapter;\r
+import org.seasar.extension.jdbc.gen.internal.arg.ArgumentsBuilder;\r
+import org.seasar.extension.jdbc.gen.internal.command.CommandInvokerImpl;\r
+\r
+/**\r
+ * {@link Task}の抽象クラスです。\r
+ * \r
+ * @author taedium\r
+ */\r
+public abstract class AbstractTask extends Task {\r
+\r
+    /** JavaタスクのresultPropertyのサフィックス */\r
+    protected static String RESULT_PROPERTY_NAME_SUFFIX = "_result";\r
+\r
+    /** JavaタスクのerrorPropertyのサフィックス */\r
+    protected static String ERROR_PROPERTY_NAME_SUFFIX = "_error";\r
+\r
+    /** Javaタスク */\r
+    protected Java java = new Java();\r
+\r
+    /** JVMのコマンドライン */\r
+    protected Commandline jvmCommandline = new Commandline();\r
+\r
+    /** コマンドを呼び出すクラスの名前 */\r
+    protected String commandInvokerClassName = CommandInvokerImpl.class\r
+            .getName();\r
+\r
+    /** クラスパス */\r
+    protected Path classpath;\r
+\r
+    /**\r
+     * JVMの引数を作成します。\r
+     * \r
+     * @return JVMの引数\r
+     */\r
+    public Commandline.Argument createJvmarg() {\r
+        return jvmCommandline.createArgument();\r
+    }\r
+\r
+    /**\r
+     * コマンドを呼び出すクラスの名前を返します。\r
+     * \r
+     * @return コマンドを呼び出すクラスの名前\r
+     */\r
+    public String getCommandInvokerClassName() {\r
+        return commandInvokerClassName;\r
+    }\r
+\r
+    /**\r
+     * コマンドを呼び出すクラスの名前を設定します。\r
+     * \r
+     * @param commandInvokerClassName\r
+     *            コマンドを呼び出すクラスの名前\r
+     */\r
+    public void setCommandInvokerClassName(String commandInvokerClassName) {\r
+        this.commandInvokerClassName = commandInvokerClassName;\r
+    }\r
+\r
+    /**\r
+     * クラスパスを設定します。\r
+     * \r
+     * @param classpath\r
+     *            クラスパス\r
+     */\r
+    public void setClasspath(Path classpath) {\r
+        createClasspath().append(classpath);\r
+    }\r
+\r
+    /**\r
+     * クラスパスの参照を設定します。\r
+     * \r
+     * @param reference\r
+     *            クラスパスの参照\r
+     */\r
+    public void setClasspathRef(Reference reference) {\r
+        createClasspath().setRefid(reference);\r
+    }\r
+\r
+    /**\r
+     * クラスパスを作成します。\r
+     * \r
+     * @return クラスパス\r
+     */\r
+    public Path createClasspath() {\r
+        if (classpath == null) {\r
+            classpath = new Path(getProject());\r
+        }\r
+        return classpath.createPath();\r
+    }\r
+\r
+    @Override\r
+    public void execute() throws BuildException {\r
+        if (classpath == null) {\r
+            throw new BuildException("classpath is not specified for '"\r
+                    + getTaskName() + "' task");\r
+        }\r
+        if (classpath.list().length == 0) {\r
+            throw new BuildException("classpath is empty for '" + getTaskName()\r
+                    + "' task");\r
+        }\r
+        executeCommand();\r
+    }\r
+\r
+    /**\r
+     * コマンドを実行します。\r
+     */\r
+    protected void executeCommand() {\r
+        Command command = getCommand();\r
+        String commandName = command.getClass().getName();\r
+\r
+        ArgumentsBuilder builder = new ArgumentsBuilder(command);\r
+        List<String> args = builder.build();\r
+\r
+        Environment.Variable commandProperty = new Environment.Variable();\r
+        commandProperty.setKey(CommandAdapter.COMMAND_KEY);\r
+        commandProperty.setValue(commandName);\r
+\r
+        Environment.Variable commandInvokerProperty = new Environment.Variable();\r
+        commandInvokerProperty.setKey(CommandAdapter.COMMAND_INVOKER_KEY);\r
+        commandInvokerProperty.setValue(commandInvokerClassName);\r
+\r
+        long time = System.currentTimeMillis();\r
+        String resultPropertyName = commandName + time\r
+                + RESULT_PROPERTY_NAME_SUFFIX;\r
+        String errorPropertyName = commandName + time\r
+                + ERROR_PROPERTY_NAME_SUFFIX;\r
+\r
+        java.bindToOwner(this);\r
+        java.addSysproperty(commandProperty);\r
+        java.addSysproperty(commandInvokerProperty);\r
+        for (String arg : args) {\r
+            java.createArg().setValue(arg);\r
+        }\r
+        for (String arg : jvmCommandline.getArguments()) {\r
+            java.createJvmarg().setValue(arg);\r
+        }\r
+        java.setClasspath(classpath);\r
+        java.setClassname(CommandAdapter.class.getName());\r
+        java.setResultProperty(resultPropertyName);\r
+        java.setErrorProperty(errorPropertyName);\r
+        java.setFork(true);\r
+        java.execute();\r
+\r
+        String result = getProject().getProperty(resultPropertyName);\r
+        if (!"0".equals(result)) {\r
+            throw new BuildException(getProject()\r
+                    .getProperty(errorPropertyName));\r
+        }\r
+    }\r
+\r
+    /**\r
+     * コマンドを返します。\r
+     * \r
+     * @return コマンド\r
+     */\r
+    protected abstract Command getCommand();\r
+}\r