Hi All,
I tried to use the RoleManager to get the Class Name for another Implementaion of a
component using the <hint> tag, But it failed ... I don't know if I use it in a proper
way ... I have a working Interface (ITestManger) and tow implementaion classes :
(TestManger),(SecondTestManger)
and the Roles.xml file is like :
**************************************************************************
<role-list>
<role
name="com.imkenberg.bo.Order.test.ITestManger"
shorthand="test"
default-class="com.imkenberg.bo.Order.test.SecondTestManger">
<hint shorthand="manager1"
class="com.imkenberg.bo.Order.test.TestManger"/>
<hint shorthand="manager2"
class="com.imkenberg.bo.Order.test.SecondTestManger"/>
</role>
<!--default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">-->
</role-list>
***************************************************************************
below is a snippet code of what I'm doing:
****************************************************************************
static String rootdir = "c:/avalon";
static ComponentManager manager;
static ExcaliburComponentManager exManager;
static DefaultRoleManager roleManager;
ExcaliburComponentSelector exSelector;
static {
try {
init();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void init() throws Exception {
roleManager = new DefaultRoleManager();
DefaultContext context = new DefaultContext();
context.put("context-root", new File(rootdir));
ExcaliburComponentManagerCreator ecmc = new
ExcaliburComponentManagerCreator(context, new File(rootdir + "/logkit.xml"),
new File(rootdir + "/roles.xml"), new File(rootdir + "/xconf.xml"),
null);
manager = ecmc.getComponentManager();
exManager = new ExcaliburComponentManager(manager);
exManager.setRoleManager(roleManager);
}
public void execute() throws com.imkenberg.command.CommandException {
try {
// exSelector = (ExcaliburComponentSelector) lookup(ITestManger.ROLE,
"manager1");
ITestManger test = (ITestManger) lookup ( ITestManger.ROLE, "manager1");
} catch (Exception e) {
System.out.println("Error in Getting the Component");
}
}
public static Component lookup(String role, String hint) throws ComponentException {
String className = roleManager.getDefaultClassNameForHint(role, hint);
return exManager.lookup(className);
}
***************************************************************************************************
Does I'm doing something wrong ? is that way the proper way to use " RoleManger " to
get "Multiple Implemention for a component "
BTW : I used also ExcaliubarComponentselector with the RoleManger But it also Failed.
Any Help
Thanx in advance
Mohamed