/*
 * @author : Simeon M. Greene

 * @version 1.0
 *
 * Development Environment : Oracle9i JDeveloper
 *
 * Name of the File        : RpcLitTopdownImpl.java
 *

 * Creation / Modification History
 *    Simeon            05-May-2003       Created
 *    Chandar          22-Aug-2003        Modified
 *
 *  Overview :
 *  This class is implementation class of RPC literal Web Service.
   *  It defines methods that take input paramters of various types

   *  and also return those types to the client.
 */

package oracle.demo.topdownrpc.service;

// JAx-RPC related imports
import javax.xml.rpc.holders.StringHolder;
import javax.xml.rpc.holders.IntHolder;

import javax.xml.rpc.holders.FloatHolder;

// rmi import
import java.rmi.RemoteException;

// util and IO imports
import java.util.logging.*;
import java.io.StringWriter;
import java.io.PrintWriter;


import oracle.demo.topdownrpc.types.*;

public class RpcLitTopdownImpl implements SoapTestPortTypeRpc{

   // Logger object
    private Logger m_logger;

   /**
   *  Construction definition

   */
    public RpcLitTopdownImpl(){

       // create an anonymous logger
       m_logger = Logger.getAnonymousLogger
                              ("oracle.demo.topdownrpc.service.RpcLitTopdownImpl");

       // Set the log level specifying which message levels will be logged by this logger
       m_logger.setLevel(Level.ALL);

      // create the formatter

       SimpleFormatter formatter = getFormatter();

       // parent handler for logging messages should not be used
       m_logger.setUseParentHandlers(false);

      // Add a log Handler to receive logging messages.
       m_logger.addHandler(new StreamHandler(System.out,formatter){
            public synchronized void publish(LogRecord record){

                // Format and publish a LogRecord.
                super.publish(record);
                flush();

            }
        });
    }

   /**
    *  This method returns a SimpleFormatter that can be used by Logger object
    *  to format messages.
   */
    private SimpleFormatter getFormatter() {
        return new SimpleFormatter(){
            // define method to format the log record
            public synchronized String format(LogRecord record){
                StringBuffer sb = new StringBuffer();


                // Localize and format the message string from  log record
                String message = formatMessage(record);

                //append the level of record
                sb.append(record.getLevel().getLocalizedName());
                sb.append(": ");
                sb.append(message);
                sb.append(System.getProperty("line.separator"));
                if(record.getThrown() != null){
                    try{
                        StringWriter sw = new StringWriter();
                        PrintWriter pw = new PrintWriter(sw);
                        record.getThrown().printStackTrace(pw);

                        pw.close();
                    }
                    catch(Exception ex){  // catch exceptions

                    }
                }
                return sb.toString();
            }
        };
    }

   /**
    *  This method takes struct type as  a parameter and logs the contents of struct.
    *  @param : SOAPStruct
    *  @return  : SOAPStruct

    */
    public SOAPStruct echoStruct(SOAPStruct inputStruct) throws
            RemoteException {

       // get the float type attribute
       String floatVal = "" + inputStruct.getVarFloat();

       // get Integer attribute
       String intVal = "" + inputStruct.getVarInt();

       // get String attribute
       String sVal = "" + inputStruct.getVarString();

       // log the message with above values
        m_logger.log(Level.INFO,"demo.structdata.msg",new Object[]{floatVal,intVal,sVal});
        return inputStruct;

    }

   /**
    *  This method takes array of struct type as  a parameter and logs the contents of
    *  each element
    *  @param : ArrayOfSOAPStruct
    *  @return  : ArrayOfSOAPStruct
    */
    public ArrayOfSOAPStruct echoStructArray(ArrayOfSOAPStruct inputStructArray) throws
            RemoteException {

        // get the struct array from input paramter
        SOAPStruct[] structs = inputStructArray.getStructItem();
         Integer count = new Integer(structs.length);

        //log the number of elements in struct array
        m_logger.log(Level.INFO, "demo.echoStructArray.count",count);


        // for each element
        for(int i = 0; i < structs.length;i++){
           // log the contents of struct
            m_logger.log(Level.INFO,"demo.echoStructArray.msg",new Object[]{
               new String() + i,
               new String() + structs[i].getVarFloat(),
               new String() + structs[i].getVarInt(),
               structs[i].getVarString()
            });
        }

        // return the struct array to client
        return inputStructArray;
    }

   /**
    *  This method takes a struct type as  a parameter and logs the contents of

    *  each element. It also stores the values of struct elements in various
    *  Holder objects sent by client as parameters. The holder objects can
    *  then be used by the client to manipulate their values.
    *  @param : SOAPStruct
    *  @param : StringHolder
    *  @param : IntHolder
    *  @param : FloatHolder
    */
    public void echoStructAsSimpleTypes(SOAPStruct inputStruct,
                                          StringHolder outputString,
                                        IntHolder outputInteger,
                                          FloatHolder outputFloat)
                                          throws  RemoteException {
       // log the values of input struct
        m_logger.log(Level.INFO, "demo.structdata.msg",new Object[]{
            "" + inputStruct.getVarFloat(),
            "" + inputStruct.getVarInt(),
            "" + inputStruct.getVarString()
        });


        // store the struct values in Holder objects
        outputString.value = inputStruct.getVarString();
        outputInteger.value = inputStruct.getVarInt();
        outputFloat.value = inputStruct.getVarFloat();
    }

   /**
    *  This method takes simple types as  a parameter and logs the contents of
    *  each parameter.  The method constructs a struct from these types and returns
    *  to the client.
    *  @param : String
    *  @param : int
    *  @param : float
    */
    public SOAPStruct echoSimpleTypesAsStruct(String inputString,
                                                int inputInteger,
                                              float inputFloat)
                                               throws  RemoteException {


           // log the input simple types
           m_logger.log(Level.INFO, "demo.structdata.msg",new Object[]{
               "" + inputFloat,
               "" + inputInteger,
               inputString
            });

       //   construct  a struct and return to client
        return new SOAPStruct(inputString,inputInteger,inputFloat);
    }

   /**
    *  This method takes a nested struct as the parameter and logs the contents of
    *  each struct .  The method also returns the nested struct to client
    *  @param : SOAPStructStruct
    *  @return : SOAPStructStruct
    */
    public SOAPStructStruct echoNestedStruct(SOAPStructStruct inputStruct)
                                               throws RemoteException {

       // log the contents of simple elements of struct

        m_logger.log(Level.INFO, "demo.structdata.msg1",new Object[]{
           "top level stuct data",
           "" + inputStruct.getVarFloat(),
           "" + inputStruct.getVarInt(),
           inputStruct.getVarString()
        });

        // log the contents of nested struct
        m_logger.log(Level.INFO, "demo.structdata.msg1",new Object[]{
           "nested level stuct data",
           "" + inputStruct.getStructItem().getVarFloat(),
           "" + inputStruct.getStructItem().getVarInt(),
           inputStruct.getStructItem().getVarString()
        });

        // return the nested struct back
        return inputStruct;
    }

   /**
    *  This method takes array of  nested struct as the parameter and logs the contents of
    *  each struct element.

    *  @param : SOAPStructStruct
    *  @return : SOAPStructStruct
    */
    public SOAPArrayStruct echoNestedArray(SOAPArrayStruct inputStruct) throws
            RemoteException {

        // log values of simple types in struct
        m_logger.log(Level.INFO, "demo.structdata.msg",new Object[]{
               "" + inputStruct.getVarFloat(),
               "" + inputStruct.getVarInt(),
               inputStruct.getVarString()
            });

         // get the string array in the input struct
        ArrayOfstring aos = inputStruct.getVarArray();
         String array[] = aos.getStringItem();

        // log the values of each string element
        for(int i = 0; i < array.length;i++){
            m_logger.log(Level.INFO, "demo.stringarraydata.msg",new Object[]{
               "String",
               "" + i,
               array[i]

            });
        }

        // retrun the nested struct array to the client
        return inputStruct;
    }

   /**
    *  This method takes user defined type containing string array as an
    *  attribute and logs the contents of  each element in string array
    *  @param : ArrayOfstring
    *  @return   : ArrayOfstring
    */
    public ArrayOfstring echoStringArray(ArrayOfstring inputStringArray) throws
            RemoteException {
        //get the string array
        String array[] = inputStringArray.getStringItem();

        // log the value of each element in String array
        for(int i = 0; i < array.length;i++){
            m_logger.log(Level.INFO, "demo.stringarraydata.msg",new Object[]{
               "String",
               "" + i,
               array[i]

            });
        }

        // return the ArrayofString type to client
        return inputStringArray;
    }

   /**
    *  This method takes user defined type containing Integer  array as an
    *  attribute and logs the contents of  each element in int array
    *  @param : ArrayOfint
    *  @return   : ArrayOfint
    */
   public ArrayOfint echoIntegerArray(ArrayOfint inputIntegerArray)
                                         throws RemoteException {
        // get the integer array from the input parameter
        int array[] = inputIntegerArray.getInteger();

        // log values of each int element
        for(int i = 0; i < array.length;i++){
            m_logger.log(Level.INFO, "demo.stringarraydata.msg",new Object[]{
               "Integer",
               "" + i,
               "" + array[i]
            });

        }

        // return int array type to client
        return inputIntegerArray;
    }

   /**
    *  This method takes boolean type as parameter and logs its value
    *  @param : boolean
    *  @return   : boolean
    */
    public boolean echoBoolean(boolean inputBoolean) throws RemoteException {

        // log the boolean value
        m_logger.log(Level.INFO,"demo.echoData.msg",new Object[]{
            "boolean",
            "" + inputBoolean
        });

        return inputBoolean;
    }

   /**
    *  This method takes String type as parameter and logs its value
    *  @param : String
    *  @return   : String

    */
    public String echoString(String inputString) throws
            RemoteException {
        m_logger.log(Level.INFO,"demo.echoData.msg",new Object[]{
            "String",
            inputString
        });
        return inputString;
    }
}

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy