This forum has been archived. Please start a new discussion on GitHub.

Adapter Factories


I have used the Ice Object factories to instantiate different concrete implementations of Ice Objects and it is an elegant way to do so.

I'm just wondering if there is an equivalent one for adapters? Does Ice come with an "Adapter factory". I have two different implementations of an adapter and I would like to instantiate a different one based on certain conditionals.

Could you show me how to do this?


  • benoit
    benoit Rennes, France

    Sorry, I'm not sure I understand your question. By "adapter", are you refering to Ice object adapters? Object adapters are created through the communicator. Perhaps you could describe a little more what you're trying to do or what you're looking for with an example?

  • Hi benoit,

    Sorry, I may have got the terminology incorrect.

    The idea is add a "AlloySubAnalyserI" or a "KKSubAnalyserI" depending on a condition. I want these to have the same identity.
    	String subAnalyserType = "AlloySubAnalyser"
    	Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SubAnalyser");
            Ice.Properties properties = communicator().getProperties();
            Ice.Identity id = communicator().stringToIdentity(properties.getProperty("Identity"));
            if (subAnalyserType.equals("AlloySubAnalyser")) {	
            	adapter.add(new AlloySubAnalyserI(), id);
            } else if (subAnalyserType.equals("KKSubAnalyser")) {
            	adapter.add(new KKSubAnalyserI(), id);
  • matthew
    matthew NL, Canada
    Do you want this to have effect on a per-request basis or at server startup? If you want to do it on server startup then what is wrong with the approach that you have taken below? If you want it to be on a per-request basis then you could use a servant locator to do what you want...
  • Thank you. Servant locators are exactly what I need. Cheers.