/* 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 PrimativeAnyTestImpl extends primativeAnyTest._patImplBase
{

	//Constructor for transient object		
	public PrimativeAnyTestImpl()
	{
	}

	//Constructor for persistent object		
	public PrimativeAnyTestImpl(String name)
	{
		super(name);
	}

	public int testPrimativeAny(
		org.omg.CORBA.Any inPrimativeAny,
		org.omg.CORBA.AnyHolder inoutPrimativeAnyHolder, 
		org.omg.CORBA.AnyHolder outPrimativeAnyHolder)
	{
		///////////////////////////////////////////////////////
		//	Begin Parameter Extraction
		//
		//Extract the inLongVal from the Any
		int inLongVal = inPrimativeAny.extract_long();

		//Extract the inout Any from the holder
		org.omg.CORBA.Any inoutPrimativeAny = inoutPrimativeAnyHolder.value;
		//Extract the inoutLongVal from the Any
		int inoutLongVal = inoutPrimativeAny.extract_long();
		//
		//	End Parameter Extraction
		///////////////////////////////////////////////////////


		//For demonstration, print out the passed values.  
		System.out.println("\n\nBegining method testPrimativeAny()\n" + 
			"\tin parameter " + inLongVal + "\n" +  
			"\tinout parameter " + inoutLongVal);

		///////////////////////////////////////////////////////
		//	Begin Setting values for Return
		//
		//Set the value on the inoutLongVal
		inoutLongVal = 6;
		//Insert this inoutLongVal into the Any
		inoutPrimativeAny.insert_long(inoutLongVal);


		//We must create a outLongVal to add into the
		//any to be passed back to the client.
		int outLongVal = 6;
		//Create a new Any to be put into the outAnyHolder.  Note that
		//we create this by calling to the org.omg.CORBA.ORB accessed
		//through our inherited _orb() method
		org.omg.CORBA.Any outPrimativeAny = _orb().create_any();
		//Assign the outPrimativeAny to the outPrimativeAnyHolder
		outPrimativeAnyHolder.value = outPrimativeAny;
		//Insert the new outLongVal into the out Any.
		outPrimativeAny.insert_long(outLongVal);
		//
		//	End Setting values for Return
		///////////////////////////////////////////////////////


		//For deonstration, print-out the values being returned
		System.out.println("\n\nAbout to exit method testPrimativeAny()\n" + 
			"\tinout parameter " + inoutLongVal + "\n" +  
			"\tout parameter " + outLongVal);

		return 0;
	}

	//Put registration code here in a main for convienence
	public static void main(String[] args) {
            try {
                // Initialize the ORB.
                org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);


                // Initialize the BOA.
                com.inprise.vbroker.CORBA.BOA boa = ((com.inprise.vbroker.CORBA.ORB)orb).BOA_init();

                // Create the objects.
                PrimativeAnyTestImpl primativeAnyTest=
                    new PrimativeAnyTestImpl("PrimativeAny Sample");

			// Export the newly create object.
			boa.obj_is_ready(primativeAnyTest);

			System.out.println(primativeAnyTest + " is ready.");

			// Wait for incoming requests
			boa.impl_is_ready();
		}
		catch(org.omg.CORBA.SystemException ex)
		{
			ex.printStackTrace();
		}
	}
}

