<document>
	<body>
		<section name="Introduction">
			<p>
				Thinking in Dobo (Define Object By cOntext) is about
				understanding that each object can have different
				behavior in different context.Terminology :
				<ul>
					<li>
						The Client
						<p>
							Client is the object which require Interface
							of Dobo.
						</p>
					</li>
					<li>
						The Interface of Dobo
						<p>
							Interface of Dobo is the interface which can
							accessed by the client.Eg : Thread can use
							Runnable, if we define Dobo for Runnable
							then Runnable is the Interface of Dobo.
							(interface of dobo also known as
							<i>ContextInterface</i>
							).
						</p>
					</li>
					<li>
						The Context.
						<p>
							The Context is the annotation which bind the
							Interface of Dobo(
							<i>ContextInterface</i>
							) .
						</p>
					</li>
					<li>
						The Dobo
						<p>
							The Dobo is the object which annotated with
							context. The dobo object also known as
							<i>ContextObject</i>
						</p>
					</li>
				</ul>
			</p>
		</section>
		<section name="Sample of Dobo">
			<subsection name="Dobo in Simple Java">
				<ul>
					<li>The Client : java.lang.Thread</li>
					<li>The Interface of Dobo : java.lang.Runnable</li>
					<li>
						The Context : dobo.sample.RunnableContext
						<p>
							dobo.sample.RunnableContext is a Context, in
							essence it is an annotation that we need to
							create or generated for dobo to bind
							java.lang.Runnable into Dobo Object.
						</p>
						<source>
							<![CDATA[
@Context(java.lang.Runnable.class) // here we define that this annotation is a Context of Runnable (MANDATORY) 
public @interface RunnableContext { // the name of the context is RunnableContext, we can put a different name as we like

	/* 
	 * Here we define a Context member, which will bind to method name run in the interface 
	 */ 
	@Target(ElementType.METHOD) // this annotation is for method (MANDATORY)
	@Retention(RetentionPolicy.RUNTIME) // this annotation can be read at runtime (MANDATORY) 
	@ContextMemberType(void.class) // this annotation means that method run will return void (note : for void return type it is optional to define @ContextMemberType)
	@ContextMemberMethod(name = "run", parameterType = {}) // This annotation will be bind to a method name "run" which has empty "parameter" of the interface
	java.lang.Runnable public @interface run { }

}
							]]>
						</source>
					</li>
					<li>
						The Dobo : dobo.sample.HelloDobo
						<p>HelloDobo is the object which is Dobo.</p>
						<source>
						<![CDATA[
public class HelloDobo {
	@RunnableContext.run 
	public void helloDobo(){ 
		System.out.println("Hello Dobo"); 
	} 
}
							]]>
						</source>
						<p>The main</p>
						<source>
						<![CDATA[
public static void main(String [] args){
	Thread t = new Thread((Runnable)
	Dobo.instantiate(new HelloDobo(),RunnableContext.class)); 
	t.start(); 
}
							]]>
						</source>
					</li>
				</ul>
			</subsection>
			<subsection
				name="Dobo in Spring Framework">
				<ul>
					<li>The Client : springframework</li>
					<li>
						The Interface of Dobo :
						org.springframework.web.servlet.mvc.Controller
					</li>
					<li>
						The Context : dobo.sample.RunnableContext
						<p>
							dobo.sample.ControllerContext is a Context,
							in essence it is an annotation that we need
							to create or generated for dobo to bind
							java.lang.Runnable into Dobo Object.
						</p>
						<source>
							<![CDATA[
@Context(org.springframework.web.servlet.mvc.Controller.class)
public @interface ControllerContext{

	@Target(ElementType.METHOD)
	@Retention(RetentionPolicy.RUNTIME)
	@ContextMemberType(org.springframework.web.servlet.ModelAndView.class)
	@ContextMemberMethod(name="handleRequest",parameterType={javax.servlet.http.HttpServletRequest.class,javax.servlet.http.HttpServletResponse.class})
	public @interface handleRequest{}

}
							]]>
						</source>
					</li>
					<li>
						The Dobo : dobo.sample.ControllerObject
						<p>
							ControllerObject is the object which is
							Dobo.
						</p>
						<source>
						<![CDATA[
public class ControllerObject {

	@ControllerContext.handleRequest 
	public ModelAndView doSomeAction(HttpServletRequest request,HttpServletResponse response){
		return new ModelAndView("hello"); 
	} 
}
							]]>
						</source>
						<p>The spring-xml</p>
						<source>
							<![CDATA[
<bean id="controllerObject" class="dobo.sample.ControllerObject"/>

<bean id="springappController" class="net.sf.dobo.spring.DoboFactoryBean">
	<property name="context" value="dobo.sample.ControllerContext"/>
	<property name="contextImplementationObject"><ref bean="controllerObject"/></property>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
	<property name="mappings">
		<props>
			<prop key="/hello.htm">springappController</prop>
		</props>
	</property>
</bean>
]]>

						</source>
					</li>
				</ul>
			</subsection>
			<subsection name="Dobo in Google Guice">
				<ul>
					<li>The Client : googleguice</li>
					<li>
						The Interface of Dobo : dobo.sample.HelloWorld
					</li>
					<source>
					<![CDATA[
import java.io.PrintStream;

public interface HelloWorld { 
	public void setStringToPrint(String toBePrinted); 
	public boolean sayHello(PrintStream printStream); 
}
						]]>
					</source>
					<li>
						The Context : dobo.sample.HelloWorldContext
						<source>
							<![CDATA[
@Context(net.sf.dobo.sample.helloworld.HelloWorld.class)
public @interface HelloWorldContext{

	@Target(ElementType.METHOD)
	@Retention(RetentionPolicy.RUNTIME)
	@ContextMemberType(void.class)
	@ContextMemberMethod(name="setStringToPrint",parameterType={java.lang.String.class})
	public @interface setStringToPrint{}

	@Target(ElementType.METHOD)
	@Retention(RetentionPolicy.RUNTIME)
	@ContextMemberType(boolean.class)
	@ContextMemberMethod(name="sayHello",parameterType={java.io.PrintStream.class})
	public @interface sayHello{}

}
							]]>
						</source>
					</li>
					<li>
						The Dobo : dobo.sample.HelloWorldObject
						<source>
							<![CDATA[
public class HelloWorldObject {

	private String toBePrinted;

	@HelloWorldContext.sayHello public boolean
	hello(PrintStream printStream) {
		printStream.print(toBePrinted); return true;
	}

	@HelloWorldContext.setStringToPrint 
	public void setTheStringBaby(String toBePrinted) {
		this.toBePrinted = toBePrinted; 
	}
}
						]]>
						</source>
						<p>The guice main</p>
						<source>
							<![CDATA[
public class HelloWorldRunner {
	
	@Inject
	private HelloWorld helloWorld;
	
	public void sayHello(String nameToPrint){
		helloWorld.setStringToPrint(nameToPrint);
		helloWorld.sayHello(System.out);
	}
	public static void main(String [] args){
		Injector injector = Guice.createInjector(new AbstractModule(){
			public void configure() {
				bind(HelloWorld.class).toProvider(new DoboProvider<HelloWorld>(new HelloWorldObject(),HelloWorldContext.class));
			}
		});
		
		HelloWorldRunner client = new HelloWorldRunner();
		injector.injectMembers(client);
		client.sayHello("Hello World");
	}
}
]]>

						</source>
					</li>
				</ul>
			</subsection>
		</section>
		<section name="Generating The Context">
			<p>
				Creating the Context is troublesome if you don't have
				much time, and dealing with deadline. However dobo comes
				with generator to generate the context. You can specify
				the context name and package, and after that you can
				refactor the name to what ever you like. In order to
				generate Context all you have to do is.
			</p>
			<source>java -jar dobo-X.X.jar</source>
			<p>Don't forget to include required classpath.</p>
			<subsection name="Generating The Context in the IDE">
				<p>Generating context using IDE, you need to run</p>
				<source>java net.sf.dobo.Dobo</source>
				<p>
					See in console window, and follow the questions.
				</p>
			</subsection>
		</section>
	</body>
</document>
