/**

 * Created by IntelliJ IDEA.
 * User: sgreene
 * Date: May 9, 2003
 * Time: 4:08:45 PM
 * Modified by : Chandar on Aug 25,2003


 * File Name : DocLitLoggerImpl.java
 *
 *   Overview :
 *   This file defines the Document Literal Web Service implementation class. It exposes
 *   methods to log event and to get the logged events. The logged events are stored
 *   in the HashSet object.
 */

package oracle.demo.topdowndoclit.service;


// util imports
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import java.util.ArrayList;
import java.util.Calendar;

import java.rmi.RemoteException;
import oracle.demo.topdowndoclit.types.*;

public class DocLitLoggerImpl implements LoggingFacilityLogPortType{

    // variable to store logged events

    private Set m_logSet;

   /*
    * Constructor definition
    */
    public DocLitLoggerImpl(){

        // initialize HashSet object
        m_logSet = new HashSet();
    }


    /*
     * This method stores the event logged by client in the HashSet object
     * The event to be logged is received in a LogEventRequestType user
     *  defined type.
     */
    public void logEvent(LogEventRequestType document) throws
            RemoteException {

        // add the log message sent by client to HashSet object
        synchronized(this){

             m_logSet.add(document);
          }
    }

    /*
     * This method retrieves the event logged so far by the client and sends them
     * back to the client in a GetEventResopnseType user defined object.
     * It takes as input the UserId of the user  whose events should be retrieved.
     * The UserId is received in a parameter of GetEventRequestType.
     */
    public GetEventsResponseType getEvents(GetEventsRequestType document) throws
            GetEventsFaultType_Exception, RemoteException {


        // create an object of GetEventsResponseType user defined type
        GetEventsResponseType response = new GetEventsResponseType();

        //initialize an ArrayList to store events
        List responseList = new ArrayList();
        synchronized(this){
          // get an iterator on HashSet that stores logged events
          Iterator it = m_logSet.iterator();

          // get the User Id from input parameter
          String id = document.getDemoUserID();


          // iterate through all the logged events
          while(it.hasNext()){
            // get the next event
            LogEventRequestType req = (LogEventRequestType)it.next();

            // if User id  of event is equal to input User id
            if(id.equals(req.getDemoUserID())){

                // create a LogEntry and add to ArrayList
                 responseList.add(createLogEntryFromRequest(req));
            }
          }

          //create an array of LogEntry user defined type from ArrayList

          // and return it to the client in GetEventsResponseType object
          response.setLogEntry((LogEntry[])responseList.toArray(new LogEntry[0]));
         }
        return response;
    }

   /*
    * This method creates a LogEntry object from LogEventRequestType object
    */
    private LogEntry createLogEntryFromRequest(LogEventRequestType req) {
        LogEntry le = new LogEntry();
        le.setAny(req.getAny());
        le.setEventDescription(req.getEventDescription());
        le.setEventID(req.getEventID());
        le.setServiceID(req.getServiceID());

        le.setTimestamp(Calendar.getInstance());
        return le;
    }
}

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