avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leo Simons <leosim...@apache.org>
Subject Re: Containment model @ java.beans.
Date Thu, 07 Aug 2003 08:03:21 GMT
Vinay Chandran wrote:
> http://java.sun.com/j2se/1.4.1/docs/guide/beans/spec/beancontextTOC.fm.html
> Has anyone gone through the above javabeans  specs 
> and thought about its relevance to us (Avalon)?

played with it a little a while ago.

If you're feeling like sacrificing proper IoC and SoC, passive component 
apis, clean encapsulation, security, an api that is not a mess, that 
does not tie you to any gui concept (IIRC it has supportsGUI(), 
needsGUI() etc etc), does not have dumbly stated contracts (like 
"implementation of interface X must synchronize globally against static 
object Y") that fall apart in a multi-classloader world, bloated 
collections-api-incorporating interface definitions, then....

...it is a compelling replacement for the use of avalon (or pico, or 
similar) inside a single-classloader, single-vendor environment, 
especially if you're building a GUI. And it allows you to do useful 
things like hierarchy synchronization IIRC and everything is exposed 
through the beans-style event api.

It goes a little something like:

class MyBean
   extends SomeAbstractImplementationThatYouHaveToWriteYourself
   implements SomeInterfaceIDontRememberNameOf
	setContext( BeanContext bc )
		if(m_bc != null)

		m_bc = bc;

	void myMethod()

		// do stuff

	void fireBeanContextChangeEvent( BeanContext bc )
		// loop over property change and
		// vetoing listeners and send them the
		// old and new values
	void checkBeanContextAvailable()
		throws IllegalStateException
		// you really want to check setContext()
		// has been called and stuff is available,
		// because you really can't be sure with
		// the BC

class MyOtherBean
   extends SomeAbstractImplementationThatYouHaveToWriteYourself
   implements SomeInterfaceIDontRememberNameOf
	// ...

	void doStuff()

	void setup()

		Iterator it = m_bc.iterator();
		while( it.hasNext() )
			Object bean = it.next();
			if(bean instanceof MyBean)
				m_myBean = bean;

			// and something like that for all
			// dependencies

// in your app
BeanContext bc = new BeanContextImplementation();
bc.add( new MyBean() );
bc.add( new MyOtherBean() );

Not very clean, is it? No dependency management, no object creation 
policies, no security, no transparency (if you use beancontext its 
difficult to code a setup where your clients don't).


- Leo

To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org

View raw message