/**
 * Copyright  2001 The JA-SIG Collaborative.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the JA-SIG Collaborative
 *    (http://www.jasig.org/)."
 *
 * THIS SOFTWARE IS PROVIDED BY THE JA-SIG COLLABORATIVE "AS IS" AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JA-SIG COLLABORATIVE OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

package  org.jasig.portal.channels.groupsmanager;

/**
 * <p>Title: uPortal</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Columbia University</p>
 * @author Don Fracapane
 * @version 2.0
 */

import  org.jasig.portal.*;
import  org.jasig.portal.services.*;
import  org.jasig.portal.utils.*;

/**
 * CGroupsManagerServant is an IServant subclass of CGroupsManager
 * This will allow other channels to delegate to CGroupsManager at runtime
 *
 * Master channels should instantiate this channel with the following
 * staticData parameter preset:
 *
 * prmOwners = IPermissible[] owners
 *
 * where owners is an array with a single element being an instance of the
 * master's representative IPermissible class.
 *
 * see org.jasig.portal.IPermissible for more information
 *
 */

public class CGroupsManagerServant extends MultithreadedCacheableChannelAdapter
      implements IServant {
   final IMultithreadedChannel channel;
   final String uid;

   /**
    * put your documentation comment here
    * @param channel (IMultithreadedChannel)
    * @param uid (String)
    */
   public CGroupsManagerServant (IMultithreadedChannel channel, String uid) {
      super(channel,uid);
      this.channel = channel;
      this.uid = uid;
   }

   /**
    * True when the servant is ready to pass control back to the master channel.
    * @return boolean
    */
   public boolean isFinished () {
      CGroupsManagerSessionData sessionData = getSessionData();
      ChannelStaticData staticData = sessionData.staticData;
      boolean isFinished = false;
      if (staticData.containsKey("groupManagerFinished") && staticData.getParameter("groupManagerFinished").equals("true")) {
         isFinished = true;
      }
      return  isFinished;
   }

   CGroupsManagerSessionData getSessionData(){
    return ((CGroupsManager) channel).getSessionData(uid);
   }

   /**
    * Sets the staticData.
    * @param sd (ChannelStaticData)
    */
   public void setStaticData (ChannelStaticData sd) {
      try {
         channel.setStaticData(sd, uid);
         getSessionData().servantMode = true;
      }
      catch (PortalException pex) {
         Utility.logMessage("ERROR", this.getClass().getName()
            + ".setStaticData() : Unable to set static data for servant. "
            + "staticData parm = " + sd
            + "uid parm = " + uid, pex);
      }
   }

   /**
    * Create a SESSION_DONE event. This event is caught by CGroupsManager which deletes
    * the session data object.
    * @throws Throwable
    */
   protected void finalize() throws Throwable{
      super.finalize();
      // send SESSION_DONE event to the wrapped CGroupsManager channel.
      PortalEvent ev=new PortalEvent(PortalEvent.SESSION_DONE);
      channel.receiveEvent(ev, uid);
   }

   /**
    * Returns an array of objects representing the result set.
    * Note that these are IGroupMembers !!
    * @return Object[]
    */
   public Object[] getResults () {
      CGroupsManagerSessionData sessionData = ((CGroupsManager) channel).getSessionData(uid);
      ChannelStaticData staticData = sessionData.staticData;
      ChannelRuntimeData runtimeData = sessionData.runtimeData;
      IGroupsManagerCommand cmd = GroupsManagerCommandFactory.instance().get("Done");
      try{
         cmd.execute(sessionData);
      }
      catch(Exception e){
         Utility.logMessage("ERROR", e.toString(), e);
         sessionData.feedback = "Error executing command Done: "+e.getMessage();
      }
      Object[] results = (Object[])staticData.get("princResults");
      if (results == null){
        results = new Object[0];
      }
      Utility.logMessage("DEBUG", "CGroupsManagerservant.getResults()");
      return  results;
   }
}




@@ -1648,186 +1648,8 @@
 r;%0A%0A
-/**%0A * %3Cp%3ETitle: uPortal%3C/p%3E%0A * %3Cp%3EDescription: %3C/p%3E%0A * %3Cp%3ECopyright: Copyright (c) 2002%3C/p%3E%0A * %3Cp%3ECompany: Columbia University%3C/p%3E%0A * @author Don Fracapane%0A * @version 2.0%0A */%0A%0A
 impo
@@ -1742,16 +1742,62 @@
 utils.*;
+%0Aimport  org.jasig.portal.groups.IGroupMember;
 %0A%0A/**%0A *
@@ -1942,339 +1942,71 @@
 e%0A *
-%0A * Master channels should instantiate this channel with the following%0A * staticData parameter preset:%0A *%0A * prmOwners = IPermissible%5B%5D owners%0A *%0A * where owners is an array with a single element being an instance of the%0A * master's representative IPermissible class.%0A *%0A * see org.jasig.portal.IPermissible for more information%0A *
+ @author Alex Vigdor, av317@columbia.edu%0A * @version $Revision$
 %0A */
@@ -4820,22 +4820,28 @@
 s = new 
-Object
+IGroupMember
 %5B0%5D;%0A   

Changed the object returned in getResults() from an Object[] to an IGroupMember[].