とりあえず最小限の構成で触ってみた。
servlet-api.jarは必須かぁ…
メイン
public class Main {public static final void main(String[] args) {
S2Container container = new S2ContainerImpl();
container.register(FooImpl.class);
container.register(BarImpl.class);
container.register(ZooImpl.class);
container.register(BazImpl.class);
Baz baz = (Baz) container.getComponent(Baz.class);
baz.perform();
}}
コンポーネント(インターフェース)
public interface Bar {public void perform();
}
public interface Baz {public void perform();
}
public interface Foo {public void perform();
}
public interface Zoo {public void perform();
}
コンポーネント(実装)
public class BarImpl implements Bar {public void perform() {
System.out.println(this);
}}
public class BazImpl implements Baz {private Foo foo = null;
public void setFoo(Foo foo) {
this.foo = foo;
}private Bar bar = null;
public void setBar(Bar bar) {
this.bar = bar;
}/////////////////////////////////////////////////////////////////
public void perform() {
System.out.println(this);
foo.perform();
bar.perform();
}}
public class FooImpl implements Foo {private Zoo zoo = null;
public void setZoo(Zoo zoo) {
this.zoo = zoo;
}public void perform() {
System.out.println(this);
zoo.perform();
}
}
public class ZooImpl implements Zoo {public void perform() {
System.out.println(this);
}
}