[Jiemamy-notify:2780] commit [3704] InterfaceEnhancerに関するサンプル集を追加

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 10月 5日 (月) 20:36:43 JST


Revision: 3704
          http://sourceforge.jp/projects/jiemamy/svn/view?view=rev&revision=3704
Author:   ashigeru
Date:     2009-10-05 20:36:43 +0900 (Mon, 05 Oct 2009)

Log Message:
-----------
InterfaceEnhancerに関するサンプル集を追加

Modified Paths:
--------------
    leto/factory-enhancer-example/branches/interface-enhancer/pom.xml

Added Paths:
-----------
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsFactory.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsInterface.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/Main.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsFactory.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsInterface.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/Main.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SayPointcut.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SuppressHandle.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsFactory.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsInterface.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/Main.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Dao.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoFactory.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoInitializer.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Main.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/NewPointcut.java
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/enhancer/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/enhancer/example/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/enhancer/example/_09dao/
    leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/enhancer/example/_09dao/example.properties

Modified: leto/factory-enhancer-example/branches/interface-enhancer/pom.xml
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/pom.xml	2009-10-05 10:55:00 UTC (rev 3703)
+++ leto/factory-enhancer-example/branches/interface-enhancer/pom.xml	2009-10-05 11:36:43 UTC (rev 3704)
@@ -63,7 +63,7 @@
     <dependency>
       <groupId>org.jiemamy</groupId>
       <artifactId>factory-enhancer</artifactId>
-      <version>0.1.1-SNAPSHOT</version>
+      <version>0.2.0-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </project>

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsFactory.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsFactory.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsFactory.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._06interface;
+
+/**
+ * {@link GreetingsInterface}オブジェクトのみを生成するファクトリのインターフェース。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public interface GreetingsFactory {
+    
+    /**
+     * @return greetings
+     */
+    GreetingsInterface newGreetings();
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsInterface.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsInterface.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsInterface.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._06interface;
+
+/**
+ * 単純なオブジェクト。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public interface GreetingsInterface {
+    
+    /**
+     * say Hello
+     */
+    void say();
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/GreetingsInterface.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/Main.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/Main.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/Main.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._06interface;
+
+import java.util.Arrays;
+
+import org.jiemamy.utils.enhancer.Enhance;
+import org.jiemamy.utils.enhancer.Enhancer;
+import org.jiemamy.utils.enhancer.InterfaceEnhancer;
+
+/**
+ * このパッケージのプログラムエントリ。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public class Main {
+
+    /**
+     * プログラムエントリ。
+     * @param args 無視される
+     * @throws Exception うまくいかない場合
+     */
+    public static void main(String...args) throws Exception {
+        Enhancer<GreetingsFactory> enhancer = new InterfaceEnhancer<GreetingsFactory>(
+                GreetingsFactory.class,
+                Object.class,
+                Arrays.<Enhance>asList(new Enhance[] {
+                        // とりあえず何もしない
+                })
+        );
+        System.out.println("ファクトリを生成");
+        GreetingsFactory factory = enhancer.getFactory().newInstance();
+
+        System.out.println("プロダクトを生成");
+        GreetingsInterface greetings = factory.newGreetings();
+
+        System.out.println("greetings.say()の実行...だけど");
+        try {
+            greetings.say();
+        }
+        catch (AbstractMethodError e) {
+            System.out.println("そんなメソッドはだれも実装していない");
+            e.printStackTrace(System.out);
+        }
+    }
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_06interface/Main.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsFactory.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsFactory.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsFactory.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._07hookmethod;
+
+/**
+ * {@link GreetingsInterface}オブジェクトのみを生成するファクトリのインターフェース。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public interface GreetingsFactory {
+    
+    /**
+     * @return greetings
+     */
+    GreetingsInterface newGreetings();
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsInterface.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsInterface.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsInterface.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._07hookmethod;
+
+/**
+ * 単純なオブジェクト。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public interface GreetingsInterface {
+    
+    /**
+     * say Hello
+     */
+    void say();
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/GreetingsInterface.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/Main.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/Main.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/Main.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._07hookmethod;
+
+import java.util.Arrays;
+
+import org.jiemamy.utils.enhancer.Enhance;
+import org.jiemamy.utils.enhancer.Enhancer;
+import org.jiemamy.utils.enhancer.InterfaceEnhancer;
+
+/**
+ * このパッケージのプログラムエントリ。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public class Main {
+
+    /**
+     * プログラムエントリ。
+     * @param args 無視される
+     * @throws Exception うまくいかない場合
+     */
+    public static void main(String...args) throws Exception {
+        Enhancer<GreetingsFactory> enhancer = new InterfaceEnhancer<GreetingsFactory>(
+                GreetingsFactory.class,
+                Object.class,
+                Arrays.<Enhance>asList(new Enhance[] {
+                        // Greetings.say()をフックして、実際に呼び出さないようにする
+                        new Enhance(new SayPointcut(), new SuppressHandle())
+                })
+        );
+        System.out.println("ファクトリを生成");
+        GreetingsFactory factory = enhancer.getFactory().newInstance();
+
+        System.out.println("プロダクトを生成");
+        GreetingsInterface greetings = factory.newGreetings();
+
+        System.out.println("greetings.say()の実行");
+        greetings.say();
+
+        System.out.println("ハンドルしたので正常終了");
+    }
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/Main.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SayPointcut.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SayPointcut.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SayPointcut.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._07hookmethod;
+
+import javassist.CtBehavior;
+import javassist.CtClass;
+
+import org.jiemamy.utils.enhancer.InvocationPointcut;
+
+/**
+ * {@link GreetingsInterface#say()}のみを対象とするポイントカット。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public class SayPointcut implements InvocationPointcut {
+
+    public boolean isTarget(CtClass self, CtBehavior behavior) {
+
+        // GreetingInterfaceのみに制限
+        if (self.getName().equals(GreetingsInterface.class.getName()) == false) {
+            return false;
+        }
+
+        // sayという名前だけに制限
+        return behavior.getName().equals("say");
+    }
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SayPointcut.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SuppressHandle.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SuppressHandle.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SuppressHandle.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._07hookmethod;
+
+import org.jiemamy.utils.enhancer.Invocation;
+import org.jiemamy.utils.enhancer.InvocationHandler;
+
+/**
+ * {@link AbstractMethodError}を抑制する。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public class SuppressHandle implements InvocationHandler {
+
+    public Object handle(Invocation invocation) throws Throwable {
+        System.out.printf("%s の呼び出しをフック%n", invocation.getTarget());
+        System.out.println("invocation.proceed()するとAbstractMethodErrorがスローされるからやめとく");
+        return null;
+    }
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_07hookmethod/SuppressHandle.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsFactory.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsFactory.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsFactory.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._08extends;
+
+/**
+ * {@link GreetingsInterface}オブジェクトのみを生成するファクトリのインターフェース。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public interface GreetingsFactory {
+    
+    /**
+     * @return greetings
+     */
+    GreetingsInterface newGreetings();
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsInterface.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsInterface.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsInterface.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._08extends;
+
+/**
+ * 単純なオブジェクト。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public interface GreetingsInterface {
+    
+    /**
+     * say Hello
+     */
+    void say();
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/GreetingsInterface.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/Main.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/Main.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/Main.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._08extends;
+
+import java.util.Arrays;
+import java.util.Date;
+
+import org.jiemamy.utils.enhancer.Enhance;
+import org.jiemamy.utils.enhancer.Enhancer;
+import org.jiemamy.utils.enhancer.InterfaceEnhancer;
+
+/**
+ * このパッケージのプログラムエントリ。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public class Main {
+
+    /**
+     * プログラムエントリ。
+     * @param args 無視される
+     * @throws Exception うまくいかない場合
+     */
+    public static void main(String...args) throws Exception {
+        Enhancer<GreetingsFactory> enhancer = new InterfaceEnhancer<GreetingsFactory>(
+                GreetingsFactory.class,
+                Date.class, // Dateを実装するようにする
+                Arrays.<Enhance>asList(new Enhance[] {
+                        // メソッドなどはフックしない
+                })
+        );
+        System.out.println("ファクトリを生成");
+        GreetingsFactory factory = enhancer.getFactory().newInstance();
+
+        System.out.println("プロダクトを生成");
+        GreetingsInterface greetings = factory.newGreetings();
+
+        if (greetings instanceof Date) {
+            System.out.println("なぜかDateを実装しているので");
+            System.out.println(greetings);
+            System.out.println("今の時刻が表示される");
+        }
+    }
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_08extends/Main.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Dao.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Dao.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Dao.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._09dao;
+
+/**
+ * 単純なオブジェクト。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public interface Dao {
+
+    /**
+     * どこかで見たメソッド。
+     * @param key キー名
+     * @return なにか
+     */
+    String getProperty(String key);
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Dao.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoFactory.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoFactory.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoFactory.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._09dao;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * {@link Dao}オブジェクトのみを生成するファクトリのインターフェース。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public interface DaoFactory {
+
+    /**
+     * @param url 設定情報?
+     * @return 生成したDao
+     * @throws IOException 初期化に失敗した場合
+     */
+    Dao newInstance(URL url) throws IOException;
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoInitializer.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoInitializer.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoInitializer.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2009 the Seasar Foundation and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._09dao;
+
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.jiemamy.utils.enhancer.Invocation;
+import org.jiemamy.utils.enhancer.InvocationHandler;
+
+/**
+ * {@link DaoFactory#newInstance(URL)}のあたりをフックする。
+ * @version $Date$
+ * @author Suguru ARAKAWA
+ */
+public class DaoInitializer implements InvocationHandler {
+
+    public Object handle(Invocation invocation) throws Throwable {
+        System.out.printf("%s の呼び出しをフック%n", invocation);
+
+        // とりあえずインスタンスを生成するところまで
+        Object result;
+        try {
+            result = invocation.proceed();
+        }
+        catch (InvocationTargetException e) {
+            throw e.getCause();
+        }
+
+        // なぜかインスタンスがProperties
+        assert result instanceof Properties;
+
+        // そして引数にはURLが来てる
+        URL url = (URL) invocation.getArguments()[0];
+        System.out.printf("url=%s%n", url);
+
+        // ロードしておく
+        InputStream in = url.openStream();
+        try {
+            ((Properties) result).load(in);
+        }
+        finally {
+            in.close();
+        }
+
+        System.out.printf("properties=%s%n", result);
+
+        // 最後にnewした結果として返す
+        return result;
+    }
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/DaoInitializer.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Main.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Main.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Main.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2009 Jiemamy Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._09dao;
+
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.jiemamy.utils.enhancer.Enhance;
+import org.jiemamy.utils.enhancer.Enhancer;
+import org.jiemamy.utils.enhancer.InterfaceEnhancer;
+
+/**
+ * このパッケージのプログラムエントリ。
+ * @version $Date$
+ * @author Suguru ARAKAWA (Gluegent, Inc.)
+ */
+public class Main {
+
+    /**
+     * プログラムエントリ。
+     * @param args 無視される
+     * @throws Exception うまくいかない場合
+     */
+    public static void main(String...args) throws Exception {
+        Enhancer<DaoFactory> enhancer = new InterfaceEnhancer<DaoFactory>(
+                DaoFactory.class,
+                Properties.class, // Propertiesを実装するようにする
+                Arrays.<Enhance>asList(
+                    // Daoの実装を生成する際に、 DaoFactory.newInstanceの引数でうまい具合に初期化
+                    new Enhance(new NewPointcut(), new DaoInitializer())
+                )
+        );
+        System.out.println("ファクトリを生成");
+        DaoFactory factory = enhancer.getFactory().newInstance();
+
+        System.out.println("プロダクトを生成");
+        Dao dao = factory.newInstance(Main.class.getResource("example.properties"));
+
+        System.out.println("helloプロパティの表示");
+        String hello = dao.getProperty("hello");
+        System.out.printf("dao.getProperty(\"hello\") = %s%n", hello);
+    }
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/Main.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/NewPointcut.java
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/NewPointcut.java	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/NewPointcut.java	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2009 the Seasar Foundation and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.util.enhancer.example._09dao;
+
+import java.net.URL;
+
+import javassist.CtBehavior;
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.NotFoundException;
+
+import org.jiemamy.utils.enhancer.InvocationPointcut;
+
+/**
+ * {@link Dao}をnewする(実際にはその実装)個所をフック。
+ * @version $Date$
+ * @author Suguru ARAKAWA
+ */
+public class NewPointcut implements InvocationPointcut {
+
+    public boolean isTarget(CtClass self, CtBehavior behavior) {
+        try {
+            // Daoのみ
+            if (self.getName().equals(Dao.class.getName()) == false) {
+                return false;
+            }
+
+            // newのみ
+            if ((behavior instanceof CtConstructor) == false) {
+                return false;
+            }
+
+            // 引数は(URL)のみ
+            CtClass[] params = behavior.getParameterTypes();
+            if (params.length != 1 || params[0].getName().equals(URL.class.getName()) == false) {
+                return false;
+            }
+
+            return true;
+        }
+        catch (NotFoundException e) {
+            return false;
+        }
+    }
+}


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_09dao/NewPointcut.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/enhancer/example/_09dao/example.properties
===================================================================
--- leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/enhancer/example/_09dao/example.properties	                        (rev 0)
+++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/enhancer/example/_09dao/example.properties	2009-10-05 11:36:43 UTC (rev 3704)
@@ -0,0 +1 @@
+hello=world


Property changes on: leto/factory-enhancer-example/branches/interface-enhancer/src/main/resources/org/jiemamy/util/enhancer/example/_09dao/example.properties
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native




Jiemamy-notify メーリングリストの案内
Back to archive index