import HelloApp.*; import java.util.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; /** * Dynamic Skeleton Invocation example * servant must extend DynamicImplementation * *@author donsez *@created 16 juin 2003 */ class DSIHelloServant extends DynamicImplementation { /** store the repository ID for the implemented interface */ static String[] myIDs = {"IDL:HelloApp/Hello:1.0"}; /** the ORB which the object is connected on */ ORB orb; /** * create a reference to the ORB */ public DSIHelloServant() { } /** * Sets the oRB attribute of the DSIHelloServant object * *@param orb The new oRB value */ public void setORB(ORB orb) { this.orb = orb; } /** * must implement invoke() for handling requests * *@param request Description of the Parameter */ public void invoke(ServerRequest request) { try { System.out.println("DSI: invoke called, op = " + request.operation()); // create an NVList to hold the parameters NVList nvlist = orb.create_list(0); // need an if statement like this for each method name if (request.operation().equals("sayHello") == true) { // need an Any for each argument Any any1 = orb.create_any(); any1.insert_string(""); nvlist.add_value("arg1", any1, ARG_IN.value); /* * Any any2 = orb.create_any(); * any2.insert_string(""); * nvlist.add_value("arg2", any2, ARG_IN.value); */ // pass the NVList to the request to get values request.arguments(nvlist); System.err.println("Argument 1: In value: " + nvlist.item(0).value().extract_string()); // System.err.println("Argument 2: In value: " + nvlist.item(1).value().extract_short()); TypeCode result_tc = orb.get_primitive_tc(TCKind.tk_string); Any result_any = orb.create_any(); result_any.type(result_tc); request.set_result(result_any); } else { throw new org.omg.CORBA.BAD_OPERATION(); } } catch (org.omg.CORBA.BAD_OPERATION badopex) { throw badopex; } catch (Exception ex) { ex.printStackTrace(); System.out.println("DSIExample: Exception thrown: " + ex); } } /** * implement an _ids method to return repository ID of interface * *@return Description of the Return Value */ public String[] _ids() { return myIDs; } }