module Factory { interface IGreetings { string hello( in string Name); }; interface IGreetingsFriends:IGreetings { }; interface IGreetingsBusiness:IGreetings { }; interface IGreetingFactory { exception GreetingExcp { string strWhy; long lErrorCode; }; IGreetings createIGreetings( in string strNameOfInterface) raises (GreetingExcp); }; }; |
public class GreetingsFriends: IGreetingsFriendsPOA { public override string hello( string _strName ) { string strGreeting = "Greetings to my Friend " +_strName; return strGreeting; } } public class GreetingsBusiness: IGreetingsBusinessPOA { public override string hello( string _strName ) { string strGreeting = "Greetings to my business partner " + _strName; return strGreeting; } } |
public class GreetingFactory: IGreetingFactoryPOA { private GreetingsBusiness m_GreetingsBusiness = null; private GreetingsFriends m_GreetingsFriends = null; public override IGreetings createIGreetings( string _strNameOfInterface ) { Factory.IGreetings oIGreetings = null; switch( _strNameOfInterface) { case "Business": if( m_GreetingsBusiness == null) { m_GreetingsBusiness = new GreetingsBusiness(); } oIGreetings = m_GreetingsBusiness._this(); break; case "Friends": if( m_GreetingsFriends == null) { m_GreetingsFriends = new GreetingsFriends(); } oIGreetings = m_GreetingsFriends._this(); break; default: throw new Factory.IGreetingFactoryPackage.GreetingExcp("Request for an unknown Interface", 1001); } return oIGreetings; } } |
Ics.CORBA.Object oObj = m_oOrb.string_to_object( "file://c:\\Factory.ior"); m_oIGreetingFactory = Factory.IGreetingFactoryHelper.narrow( oObj); |
try { // should result in an 'IGreetingsBusiness' reference: Factory.IGreetings oIGreetings = m_oIGreetingFactory.createIGreetings("Business"); System.Console.WriteLine("Create business greetings:\n\t '{0}'\n", oIGreetings.hello("K. Dudly")); // should result in an 'IGreetingsFriends' reference: oIGreetings = m_oIGreetingFactory.createIGreetings("Friends"); System.Console.WriteLine("Create friends greetings:\n\t'{0}'\n", oIGreetings.hello("M. Maier")); // should result in a 'GreetingsExcp' exception: oIGreetings = m_oIGreetingFactory.createIGreetings("Aliens"); System.Console.WriteLine("Create aliens greetings:\n\t'{0}'\n", oIGreetings.hello("M. Maier")); } catch( Factory.IGreetingFactoryPackage.GreetingExcp ex) { System.Console.WriteLine("Exception from Server. Reason:'{0}', ErrorCode:{1}", ex.strWhy, ex.lErrorCode); } |
a.) Start the Server.
b.) Start the Client.