PicoContainer

PicoContainer Homepage.

A short example, how you can invoke a remote service with the PicoContainer with a XML-RPC service provider. First you register a CrispyComponentAdapterFactory and a ClassPropertiesLoader by the DefaultPicoContainer . Than you generate a proxy service object. With this this proxy, you can work how a local java object.

MiniXmlRpcServer server = new MiniXmlRpcServer();
try {
	// add the service to the server
	server.addService(Echo.class.getName(), EchoImpl.class.getName());
	// start the server
	server.start();
		
	// first example
	// register the	CrispyComponentAdapterFactory and a PropertiesLoader
	DefaultPicoContainer pico = new DefaultPicoContainer(new CrispyComponentAdapterFactory());
	pico.registerComponentImplementation(new ClassPropertiesLoader(PropertiesLoaderTest.class, 
						"test-xml-rpc2.properties"), PropertiesLoader.class);
	// register the service interface
	pico.registerComponentImplementation(Echo.class);

	// get a proxy object from the service interface
	Echo echo =  (Echo) pico.getComponentInstance(Echo.class);
	System.out.println("Echo: " + echo.echo("Hello Girl!"));
						


	// second example
	DefaultPicoContainer pico2 = new DefaultPicoContainer();
	pico2.registerComponentImplementation(ClassPropertiesLoader.class, 
						ClassPropertiesLoader.class, 
						new Parameter[] { 
						new ConstantParameter(PropertiesLoaderTest.class), 
						new ConstantParameter("test-xml-rpc2.properties") } );
	pico2.registerComponentImplementation(ServiceManager.class);
	Echo echo2 =  (Echo) pico2.getComponentInstance(Echo.class);
	System.out.println("Echo: " + echo2.echo("Hello Boy!"));
				
} catch (Exception e) {
	e.printStackTrace();
}
finally {
	server.stop();
}