Dennis Kang wrote:
Dennis:In Avalon, the typical way to get a component is to use serviceManager(originally componentManager)'s lookup method. But what should it be when one component contains other components. For example, we have component SalesDepartment and SalesPerson, the SalesDepartment has an array of SalesPerson. How could SalesDepartment initialize the SalesPerson arrays and implement some function like add a new SalesPerson?
In you example your describing SalesDepartment as a
container (because its doing the creation of a set of
component it is managing). For this sort of thing you
can use the avalon-sandbox/assembly API.
Here is an example of some code inside SalesDepartment
to handle the setup of meta-information about SalesPerson
public void setup() throws Exception
{
final String classname = "DefaultSalesPerson";
RepositoryManager repository = m_engine.getRepository();
Type type = repository.getTypeManager().getType( classname );
m_profile = repository.getProfileManager().getProfile( type );
}
This is a utility method to create a sales person given
an int id. The id will supplied to the sales person witin
the contextualization phase under the key "urn:demo:id".
public void createSalesPerson( int id ) throws Exception
{
Map map = new Hashtable();
map.put( "urn:demo:id", id );
Appliance appliance = m_engine.createAppliance( m_profile, map, false );
m_engine.assemble( appliance );
return appliance;
}
This is simply a demonstration of using the above to create,
deploy and destroy a bunch of sales persons.
public void demo() throws Exception
{
setup(); for( int i=0; i<5; i++ )
{
Appliance appliance = createSalesPerson( i );
Object person = apliance.access();
appliance.remove( object );
}
}
What's missing in the above code (apart form business logic
and error handling) is details of the creation of the assembly
engine. If you look for the string "setUpEngine" in the
EngineTestCase source you will find a complete example. You
will also need to setup a logging system and supply this as part
of the engine setup. As example of this is available in
TestCaseBase - just look for "setUpLogging()".
Cheers, Steve.
Thanks.
Dennis
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
-- Stephen J. McConnell OSM SARL digital products for a global economy mailto:[EMAIL PROTECTED] http://www.osm.net -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
