Can somebody help me?
This is my TraceStack:
DEBUG 10533 [ROLES ] (): added Role de.kpleines.avalon.Store
with shorthand store for de.kpleines.avalon.SimpleStoreImpl
DEBUG 10533 [ROLES ] (): looking up shorthand store, returning
de.kpleines.avalon.Store
DEBUG 10533 [MANAGER ] (): Adding component
(de.kpleines.avalon.Store = de.kpleines.avalon.SimpleStoreImpl)
DEBUG 10533 [MANAGER ] (): Attempting to get Handler for:
de.kpleines.avalon.Store
DEBUG 10533 [MANAGER ] (): Handler type =
org.apache.avalon.excalibur.component.ThreadSafeComponentHandler
DEBUG 10533 [MANAGER ] (): ComponentFactory creating new instance
of de.kpleines.avalon.SimpleStoreImpl.
ERROR 10533 [MANAGER ] (): Caught an exception trying to
initialize the component handler.
java.lang.ClassCastException
at org.apache.avalon.excalibur.component.ThreadSafeComponentHandler.initialize(ThreadSafeComponentHandler.java:84)
at org.apache.avalon.excalibur.component.ExcaliburComponentManager.initialize(ExcaliburComponentManager.java:167)
at de.kpleines.AvalonUser.<init>(AvalonUser.java:52)
at de.kpleines.AvalonUser.main(AvalonUser.java:83)
DEBUG 10533 [MANAGER ] (): ComponentFactory creating new instance
of de.kpleines.avalon.SimpleStoreImpl.
DEBUG 10533 [MANAGER ] (): Could not access the Component for
role: de.kpleines.avalon.Store
java.lang.ClassCastException
at org.apache.avalon.excalibur.component.ThreadSafeComponentHandler.initialize(ThreadSafeComponentHandler.java:84)
at org.apache.avalon.excalibur.component.ExcaliburComponentManager.lookup(ExcaliburComponentManager.java:331)
at de.kpleines.AvalonUser.<init>(AvalonUser.java:61)
at de.kpleines.AvalonUser.main(AvalonUser.java:83)
Can't find component
org.apache.avalon.framework.component.ComponentException: Could not
access the Component
at org.apache.avalon.excalibur.component.ExcaliburComponentManager.lookup(ExcaliburComponentManager.java:342)
at de.kpleines.AvalonUser.<init>(AvalonUser.java:61)
at de.kpleines.AvalonUser.main(AvalonUser.java:83)
Caused by: java.lang.ClassCastException
at org.apache.avalon.excalibur.component.ThreadSafeComponentHandler.initialize(ThreadSafeComponentHandler.java:84)
at org.apache.avalon.excalibur.component.ExcaliburComponentManager.lookup(ExcaliburComponentManager.java:331)
... 2 more
This is my component Interface:
package de.kpleines.avalon;
import org.apache.avalon.framework.component.Component;
public interface Store extends Component {
String ROLE = Store.class.getName();
boolean put(String key, Object object);
Object get(String key);
}
This is my component:
public class SimpleStoreImpl extends AbstractLoggable implements
Initializable, Parameterizable, ThreadSafe{
private Map store;
private int max;
public void parameterize(Parameters params) {
this.max = params.getParameterAsInteger( "max", 100);
}
public void initialize() throws Exception {
this.store = new HashMap();
}
public boolean put(String key, Object object) {
if( this.store.size() < this.max ){
this.store.put(key, object);
return true;
}
return false;
}
public Object get(String key) {
return this.store.get(key);
}
}
This is my role/system configuration file for instanciate the
components:
<my-system>
<store>
<parameter name="max" value="10"/>
</store>
</my-system>
<role-list>
<role name="de.kpleines.avalon.Store"
shorthand="store"
default-class="de.kpleines.avalon.SimpleStoreImpl"/>
</role-list>
This is my main class:
public class AvalonUser
implements Initializable, Disposable{
ComponentHandler docs =null;
ComponentHandler guard = null;
ExcaliburComponentManager manager = new
ExcaliburComponentManager();
/** Creates a new instance of AvalonUser */
public AvalonUser() {
DefaultRoleManager roles = null;
DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder( );
try {
Configuration sysConfig = builder.buildFromFile(
confDir+"./conf/system.xconf.xml");
Configuration roleConfig = builder.build(
confDir+"./conf/document.role.xml");
roles = new DefaultRoleManager();
roles.setLogger(
Hierarchy.getDefaultHierarchy().getLoggerFor("ROLES"));
roles.configure(roleConfig);
this.manager.setLogger(
Hierarchy.getDefaultHierarchy().getLoggerFor("MANAGER"));
this.manager.setRoleManager( roles );
this.manager.configure( sysConfig );
this.manager.initialize();
}
catch (Exception e){
System.exit(1);
}
Store store = null;
try {
store = (Store) this.manager.lookup(Store.ROLE);
} catch (ComponentException ex){
System.out.println( "Can't find component ");
ex.printStackTrace();
System.exit(1);
}
String key = "key";
String value ="value";
store.put(key, value);
System.out.println( "Read value for "+key+" from Store
>"+store.get( key )+"<");
this.manager.release( store);
}
}