import HelloApp.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; /** * HelloImplWithTie example of a distributed object according to the delegation model * *@author Didier Donsez *@version 21 juin 2003 */ public class HelloImplWithTie2 // may extend a super class implements HelloOperations { private String language; /** * Constructor for the HelloImplWithTie object */ public HelloImplWithTie2() { setLanguage("en"); } /** * Constructor for the HelloImplWithTie object * *@param language the default language */ public HelloImplWithTie2(String language) { setLanguage(language); } /** * Gets the language attribute of the HelloServant object * *@return The language value */ public String getLanguage() { return language; } /** * Sets the language attribute of the HelloServant object * *@param language The new language value */ public void setLanguage(String language) { this.language = language; } /** * implement sayHello(name) IDL operation * *@param name the name to hello *@return the hello sentence in the default language */ public String sayHello(String name) { if (language.equals("fr")) { return "\nSalut " + name + " !!\n"; } else if (language.equals("it")) { return "\nCiao " + name + " !!\n"; } else if (language.equals("es")) { return "\nHola " + name + " !!\n"; } else if (language.equals("en-us")) { return "\nHi " + name + " !!\n"; } else if (language.equals("de")) { return "\nHallo " + name + " !!\n"; } else { return "\nHello " + name + " !!\n"; } } /** * implement shutdown() IDL operation */ public void shutdown() { if (orb != null) { orb.shutdown(false); } } //================================================================= // Fields and methods for ORB registering //================================================================= // the distributed reference of the current servant private Hello myRef; private ORB orb; private POA poa; /** * Sets the poa attribute of the HelloImplWithTie object * *@param poa The new pOA value */ public void setPOA(POA poa) { this.poa = poa; } /** * Sets the orb attribute of the HelloImplWithTie object * *@param orb The new oRB value */ public void setORB(ORB orb) { this.orb = orb; } /** * Get the distributed reference of the current servant This method creates * the delegate (if it does not already exist) and then raises its activation * if the POA is in the IMPLICIT mode * *@return the distributed reference of the current servant */ public Hello getReference() { if (poa == null) { return null; } if (myRef == null) { try { myRef = HelloHelper.narrow( poa.servant_to_reference(new HelloPOATie(this))); } catch (Exception ex) { System.out.println("HelloImplWithTie : got an exception " + ex); } } return myRef; } }