svnno****@sourc*****
svnno****@sourc*****
2009年 10月 8日 (木) 21:45:24 JST
Revision: 3733 http://sourceforge.jp/projects/jiemamy/svn/view?view=rev&revision=3733 Author: ashigeru Date: 2009-10-08 21:45:24 +0900 (Thu, 08 Oct 2009) Log Message: ----------- AOP Allianceのドライバに関するサンプルを追加 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/_11aopalliance/ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/GreetingsFactory.java leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/GreetingsInterface.java leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/Main.java leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/SayPointcut.java leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/SuppressInterceptor.java Modified: leto/factory-enhancer-example/branches/interface-enhancer/pom.xml =================================================================== --- leto/factory-enhancer-example/branches/interface-enhancer/pom.xml 2009-10-08 12:39:30 UTC (rev 3732) +++ leto/factory-enhancer-example/branches/interface-enhancer/pom.xml 2009-10-08 12:45:24 UTC (rev 3733) @@ -65,5 +65,10 @@ <artifactId>factory-enhancer</artifactId> <version>0.2.0-SNAPSHOT</version> </dependency> + <dependency> + <groupId>aopalliance</groupId> + <artifactId>aopalliance</artifactId> + <version>1.0</version> + </dependency> </dependencies> </project> Added: leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/GreetingsFactory.java =================================================================== --- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/GreetingsFactory.java (rev 0) +++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/GreetingsFactory.java 2009-10-08 12:45:24 UTC (rev 3733) @@ -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._11aopalliance; + +/** + * {@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/_11aopalliance/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/_11aopalliance/GreetingsInterface.java =================================================================== --- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/GreetingsInterface.java (rev 0) +++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/GreetingsInterface.java 2009-10-08 12:45:24 UTC (rev 3733) @@ -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._11aopalliance; + +/** + * 単純なオブジェクト。 + * @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/_11aopalliance/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/_11aopalliance/Main.java =================================================================== --- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/Main.java (rev 0) +++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/Main.java 2009-10-08 12:45:24 UTC (rev 3733) @@ -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._11aopalliance; + +import java.util.Arrays; + +import org.jiemamy.utils.enhancer.Enhance; +import org.jiemamy.utils.enhancer.Enhancer; +import org.jiemamy.utils.enhancer.InterfaceEnhancer; +import org.jiemamy.utils.enhancer.driver.AopAllianceDriver; + +/** + * このパッケージのプログラムエントリ。 + * @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[] { + // 07と同じだが、AOP Allianceのインターフェースを利用しているのでドライバを使う + new Enhance( + new SayPointcut(), + AopAllianceDriver.toHandler(new SuppressInterceptor())) + }) + ); + 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/_11aopalliance/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/_11aopalliance/SayPointcut.java =================================================================== --- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/SayPointcut.java (rev 0) +++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/SayPointcut.java 2009-10-08 12:45:24 UTC (rev 3733) @@ -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._11aopalliance; + +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/_11aopalliance/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/_11aopalliance/SuppressInterceptor.java =================================================================== --- leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/SuppressInterceptor.java (rev 0) +++ leto/factory-enhancer-example/branches/interface-enhancer/src/main/java/org/jiemamy/util/enhancer/example/_11aopalliance/SuppressInterceptor.java 2009-10-08 12:45:24 UTC (rev 3733) @@ -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._11aopalliance; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + +/** + * {@link AbstractMethodError}を抑制するAOP Allianceのインターセプタ。 + * @version $Date$ + * @author Suguru ARAKAWA (Gluegent, Inc.) + */ +public class SuppressInterceptor implements MethodInterceptor { + + public Object invoke(MethodInvocation invocation) throws Throwable { + System.out.printf("%s の呼び出しをフック%n", invocation.getMethod()); + 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/_11aopalliance/SuppressInterceptor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native