-Beehive
休日ですが、ためた仕事のため出社。しかし息抜きにBeehive-NetUIの仕様を見てみる。。。惜しい。ベースがStrutsだからしょうがないのだろうが、型付がぬるいのと縛られるAPIが結構多いみたい。
Beehiveの一例:拡張子が「.jpf」なのを自前コンパイル(Javaソースなのに拡張子が違うのはちょっと違和感。専用プラグインPolinateへの対策かな?)
public class LoginController extends PageFlowController { @Jpf.Action( forwards={ @Jpf.Forward(name="SUCCESS", path="success.jsp") @Jpf.Forward(name="FAIL", path="fail.jsp") } ) public Forward login() { LoginService service = (LoginService)s2.getComponent(LoginService.class); String result = service.login(...); return new Forward(result); } }
同じようなのを実現するIkushipe案:12/1のから考察を進めました。機能は同じですが、Beehiveがアクションコマンドのフレームワークである一方、Ikushipeはページ指向のフレームワークとして設計しているので位置づけが異なります。また、アノテーション中の型付を厳しく、しかも不要な実装を作らないコンセプトです。このインターフェイスをインプリするものは作りません。
public interface LoginPage extends ActionPage { @DelegateAction( delegate=LoginService.class, handleResult={ @HandleResult(result="SUCCESS", moveTo=SuccessPage.class), @HandleResult(result="FAIL", moveTo=FailPage.class) }, handleThrow={ @HandleThrow(throw=LoginException.class, moveTo=ErrorPage.class) } ) void login(); }
しかし、そうはいってもBeehiveは侮れん。とにかく全貌がすぐには分からないぐらいデカいし。
-つづき
protected Type findPageModelType(Class clazz1) { for(Type type2: clazz1.getGenericInterfaces()) { if(type2 instanceof Class) { Class clazz2 = (Class)type2; Type ret2 = findPageModelType(clazz2); if(ret2 != null) { return ret2; } } else if(type2 instanceof ParameterizedType) { ParameterizedType param2 = (ParameterizedType)type2; Type raw = param2.getRawType(); if(raw.equals(ActionPage.class)) { Type[] types3 = param2.getActualTypeArguments(); return types3[0]; } } } return null; } public Class getPageModelClass( Class formPageClass) { Type type = findPageModelType(formPageClass); if(type == null) { return Object.class; if(type instanceof Class) { return Class.class.cast(type); } // TODO 総称型をモデルに指定したときはクラス型が取れない。 throw new IllegalStateException(); }
先日の総称型のリフレクションですが。。。Typeは上記コード(findPageModelType)で取れるようです。しかし、Typeから確実にインスタンスを作る方法が無いのでちょっと制限ができてしまう。。。IndexPage extends ActionPage