(sorry if there are two I fat fingered)
I'm still waiting for someone to give a sensible DI example that would
show how we deal with the fact that there can be an unlimited number
of unknown dependancies.
mailet.xml
<mailets>
<mailet>
<name>MyMailet</name>
<class>org.foo.MyMailetImpl</class>
<interface>org.foo.MyMailet</interface>
<constructors>
<constructor/>
<constructor>
<arguments>
<argument>java.lang.String</argument>
</arguments>
</constructor>
</constructors>
<attributes>
<attribute>
<name>foo</name>
<type>java.lang.String</type>
<getter>getFoo</getter>
<setter>setFoo</setter>
</attribtue>
<attribute>
<name>MyOtherMailet</name>
<type>org.foo.MyOtherMailet</type>
<setter>getMyOtherMailet</setter>
<depends>true</depends>
</attribute>
<attribute>
<name>YetAnotherMailet</name>
<type>org.foo.YetAnotherMailet</type>
<setter>setYetAnotherMailet</setter>
<jndi>true</jndi>
<depends>true</depends>
</attribute>
</attributes>
</mailet>
</mailets>
OR
@org.apache.mailet.Mailet(name="MyMailet"
class="org.foo.MyMailet)
public class MyMailetImpl implements MyMailet {
... public members snipped ...
@org.apache.mailet.Constructor
public MyMailetImpl() {}
@org.apache.mailet.Constructor
public MyMailetImpl(String bar) {
this.bar = bar;
}
@org.apache.mailet.Attribute
public void setFoo(String foo) {
this.foo = foo;
}
public String getFoo() {
return this.foo;
}
@org.apache.mailet.Attribute(depends=true)
public void setMyOtherMailet(MyOtherMailet mailet) {
this.mom = mailet;
}
@org.apache.mailet.Attribute(depends=true jndi=true)
public void setYetAnotherMailet(YetAnotherMailet yam) {
this.yam = yam;
}
public void start() {
}
public void stop() {
}
}
myserver-specific-config.xml (unspecified but example)
<mailet-instance>
<mailet>
<name>MyMailet</name>
<instance-name>MyMailet1</instance-name>
<constructor>
<arguments>
<argument type="java.lang.String">Hi man</argument>
</arguments>
</constructor>
<attributes>
<attribute name="foo">Hello</attribute>
<attribute name="MyOtherMailet">MyOtherMailet1</attribute>
<attribute name="YetAnotherMailet">java://yam</attribute>
</attributes>
</mailet>
</mailet-instance>
CONTRACTS:
Constructors are called in any order.
Each mailet has a method called start.
Each mailet has a method called stop.
Attributes are "set" after construction but before "start".
Interfaces are proxies (ala java.lang.reflect.Proxy) and thus can be
passed before the service is started
Start is then called once dependencies are satisfied (below).
Mailets with no <depends>true</depends> are started first.
Mailets whose dependencies are satisfied are started next (loop).
Mutual and circular dependencies are not allowed (error).
JNDI dependencies are satisfied when the jndi lookup exists and the
service has been started.
stops are called in reverse order that starts were called.
Notes:
attribute annotations can be either on the implementation or the
interface.
constructor annotations must be on the implementation (duh)
annotations and/or XML are equivalent
annotations should not be used for configuration (vendor specific
example in xml above)
This is more or less the same idea used for JBoss XMBeans, Geronimo
GBeans, and EJB3.