/* This sample demonstrates using the CORBA Any
 * type to pass primative types between the client 
 * and server.  Note that there is one
 * more level of objects to notice when 
 * dealing with inout/out Anys.  
 *
 *   AnyHolder
 *       |
 *      Any
 *       |
 * member of Any
 *
 * We will use the IDL type long, aka the Java type Int
 */
public class Client 
{

	public static void main(String[] args)
	{
		try
		{

                // Initialize the ORB.
                org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);

			//Bind to the Implementation
			primativeAnyTest.pat primativeAnyTest_ = 
				primativeAnyTest.patHelper.bind(orb, "PrimativeAny Sample");
			

			///////////////////////////////////////////////////////
			//	Begin Parameter Initialization
			//
			//	Create the in value
			int inLongVal = 5;
			//	Create the in Any
			org.omg.CORBA.Any inPrimativeAny = orb.create_any();
			//	Pack the inLongVal into the Any
			inPrimativeAny.insert_long(inLongVal);
			//	Create the inAnyHolder, passing the in Any into the 
			//	constructor
			org.omg.CORBA.AnyHolder inPrimativeAnyHolder = 
				new org.omg.CORBA.AnyHolder(inPrimativeAny);

			//	Create the inout value
			int inoutLongVal = 5;
			//	Create the inout Any
			org.omg.CORBA.Any inoutPrimativeAny = orb.create_any();
			//	Pack the inoutLongVal into the Any
			inoutPrimativeAny.insert_long(inoutLongVal);
			//	Create the inoutAnyHolder, passing the inout Any into the 
			//	constructor
			org.omg.CORBA.AnyHolder inoutPrimativeAnyHolder = 
				new org.omg.CORBA.AnyHolder(inoutPrimativeAny);

			//	Create the outAnyHolder
			org.omg.CORBA.AnyHolder outPrimativeAnyHolder = 
				new org.omg.CORBA.AnyHolder();
			//
			//	End Parameter Initialization
			///////////////////////////////////////////////////////


			//For demonstration purposes, print the values 
			//before calling the remote method
			System.out.println("\n\nBefore method testPrimativeAny()\n" + 
				"\tin parameter " + inLongVal + "\n" +  
				"\tinout parameter " + inoutLongVal);

			//Call remote method
			int returnValue = primativeAnyTest_.testPrimativeAny(
				inPrimativeAny,
				inoutPrimativeAnyHolder, 
				outPrimativeAnyHolder);


			///////////////////////////////////////////////////////
			//	Begin Parameter Extraction
			//
			//Retrieve the inoutPrimativeAny from the
			//holder
			inoutPrimativeAny = inoutPrimativeAnyHolder.value;
			//Retrieve the inoutLongVal from the any
			inoutLongVal = inoutPrimativeAny.extract_long();

			//Retrieve the outPrimativeAny from the holder
			org.omg.CORBA.Any outPrimativeAny = outPrimativeAnyHolder.value;
			//Retrieve the outLongVal from the any
			int outLongVal = outPrimativeAny.extract_long();
			//
			//	End Parameter Extraction
			///////////////////////////////////////////////////////


			//For demonstration purposes, print out the values 
			//after calling remote method
			System.out.println("\n\nAfter calling method testPrimativeAny()\n" + 
				"\tinout parameter " + inoutLongVal + "\n" +  
				"\tout parameter " + outLongVal);
		}
		catch(org.omg.CORBA.SystemException ex)
		{
			ex.printStackTrace();
		}
	}
}

