I am trying to create a map object using osgi @reference ie) registering the below class as a factory with dependency as Hashmap objects. My intention is create an object using the factory which should create a hashmap. When i am trying to register it as factory state is unsatisfied. Is it possible to create a map object by the below approach? if not, can any one please let me know what i am doing wrong? or why we should not do this? Because Map is a interface.
@Component(name = "ExampleComponentFactoryServiceProvider1", factory = "example.factory.provider1")
@Service
public class ExampleComponentFactoryServiceProvider1 implements ExampleFactoryService {
@Reference(name = "MapObject", bind = "createMap", unbind = "disolveMapObject", referenceInterface = Map.class)
private Map<String, String> testMap = null;
@Activate
public void activate(Map<String, String> props) {
System.out.println("Activated 1 !!!!!");
}
public void createMap(Map<String, String> aMap) {
this.testMap = aMap;
System.out.println("Map created !! " + testMap);
}
public void disolveMapObject(Map<String, String> aMap) {
this.testMap = null;
}
@Override
public void start() {
System.out.println("Started 1 !!!!");
}
@Override
public void stop() {
System.out.println("Stopped 1 !!!!");
}
}