Package org.jxchange.client.cdo121

Source Code of org.jxchange.client.cdo121.JXCdoSession

/* j-XChange - MSExchange Unbounded !
* Copyright (C) 2007  Vikram Roopchand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package org.jxchange.client.cdo121;

import java.net.UnknownHostException;

import org.jinterop.dcom.common.IJIAuthInfo;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JIProgId;
import org.jinterop.dcom.core.JISession;
import org.jinterop.dcom.core.JIVariant;
import org.jinterop.dcom.impls.JIObjectFactory;
import org.jinterop.dcom.impls.automation.IJIDispatch;

/**
* <p>
* Class representation for CDO _Session. This is the entry point into the
* Client side access to MSExchange. It internally encapsulates a
* <code>JISession</code> (of j-Interop). <br>
* Sample Usage:- <br>
* <code>
* </code>
* </p>
* <br>
*
* @since 1.0
* @author Vikram Roopchand
*/
public final class JXCdoSession {

  // having this block here to load the enums into memory. Better to have this
  // at session start
  // then in the middle of the execution.
  static {
    int intialLoad = JXCdoEnum.ActMsgDisplayType.ActMsgAgent.intValue();
  }

  private JISession mapiSession = null;

  private JIComServer mapiServer = null;

  private IJIDispatch mapiSessionDispatch = null;

  /**
   * <p>
   * Similar to <code>JISession.createSession</code>. Starts a MAPI Session
   * instead with the machine where CDO is installed.
   * </p>
   *
   * @param cdoInstalledMachine
   *            Machine IP or Hostname where CDO is installed.
   * @throws JIException
   * @throws UnknownHostException
   *
   * @see JISession.createSession(IJIAuthInfo)
   */
  public JXCdoSession(String cdoInstalledMachine, IJIAuthInfo authInfo)
      throws UnknownHostException, JIException {
    mapiSession = JISession.createSession(authInfo);
    init(cdoInstalledMachine);
  }

  /**
   * <p>
   * Similar to <code>JISession.createSession</code>. Starts a MAPI Session
   * instead with the machine where CDO is installed.
   * </p>
   *
   * @param cdoInstalledMachine
   *            Machine IP or Hostname where CDO is installed.
   * @throws JIException
   * @throws UnknownHostException
   *
   * @see JISession.createSession(String domain,String username,String
   *      password)
   */
  public JXCdoSession(String cdoInstalledMachine, String domain,
      String username, String password) throws UnknownHostException,
      JIException {
    mapiSession = JISession.createSession(domain, username, password);
    init(cdoInstalledMachine);
  }

  private void init(String cdoInstalledMachine) throws UnknownHostException,
      JIException {
    mapiServer = new JIComServer(JIProgId.valueOf("MAPI.Session"), cdoInstalledMachine, mapiSession);
    mapiSessionDispatch = (IJIDispatch)JIObjectFactory.narrowObject(mapiServer.createInstance().queryInterface(IJIDispatch.IID));
  }

  /**
   * <p>
   * From CDO Documentation:- The Application property returns the name of the
   * active application, namely the CDO Library, 'Collaboration Data Objects'.
   * </p>
   *
   * @return
   * @throws JIException
   */
  public JIVariant GetApplication() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("Application");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The Parent property returns the parent of the
   * object.
   * </p>
   *
   * @throws JIException
   */
  public JIVariant GetParent() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("Parent");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  // /**<p>From CDO Documentation:- The Parent property returns the parent of
  // the object. </p>
  // *
  // * @param parent
  // */
  // public void setParent(JIVariant parent)
  // {
  // mapiSessionDispatch.put("Parent",parent);
  // }
  //  
  /**
   * <p>
   * From CDO Documentation:- The Session property returns the top-level
   * Session object associated with the specified CDO Library object
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetSession() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("Session");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  // /**<p>From CDO Documentation:- The Session property returns the top-level
  // Session object associated with the specified CDO Library object</p>
  // *
  // */
  // public void setSession(JIVariant session)
  // {
  // mapiSessionDispatch.put("Session",session);
  // }
  //  

  /**
   * <p>
   * From CDO Documentation:- The Class property returns a numeric constant
   * that identifies the CDO Library object.
   * </p>
   *
   * @throws JXCdoException
   */
  public JIVariant GetCdoClass() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("Class");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The Version property returns the version number
   * of the CDO Library.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetVersion() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("Version");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The OperatingSystem property returns the name
   * and version number of the current operating system.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetOperatingSystem() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("OperatingSystem");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The Name property returns the display name of
   * the profile logged on to this session.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetName() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("Name");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The CurrentUser property returns the active user
   * as an AddressEntry object.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetCurrentUser() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("CurrentUser");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The Inbox property returns a Folder object
   * representing the current user's Inbox folder.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetInbox() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("Inbox");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The Outbox property returns a Folder object
   * representing the current user's Outbox folder.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetOutbox() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("Outbox");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The InfoStores property returns an InfoStores
   * collection available to this session.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetInfoStores() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("InfoStores");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The AddressLists property returns a single
   * AddressList object or an AddressLists collection object.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetAddressLists() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("AddressLists");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The OutofOffice property indicates whether the
   * user is currently considered out of the office.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetOutOfOffice() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("OutOfOffice");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The OutofOffice property indicates whether the
   * user is currently considered out of the office.
   * </p>
   *
   * @param outOfOffice
   * @throws JXCdoException
   */
  public void GetOutOfOffice(JIVariant outOfOffice) throws JXCdoException {
    try {
      mapiSessionDispatch.put("OutOfOffice", outOfOffice);
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The OutOfOfficeText property is the text of the
   * message others receive if they send mail to this user while the user is
   * out of the office.
   * </p>
   *
   * @throws JXCdoException
   *
   */
  public JIVariant GetOutOfOfficeText() throws JXCdoException {
    try {
      return mapiSessionDispatch.get("OutOfOfficeText");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The OutofOffice property indicates whether the
   * user is currently considered out of the office.
   * </p>
   *
   * @param outOfOffice
   * @throws JXCdoException
   */
  public void SetOutOfOfficeText(JIVariant outOfOfficeText)
      throws JXCdoException {
    try {
      mapiSessionDispatch.put("OutOfOfficeText", outOfOfficeText);
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * <p>
   * From CDO Documentation:- The Logon method logs on to the messaging system
   * </p>
   *
   * @param profileName
   *            optional - please use JVIariant.OPTIONAL
   * @param profilePassword
   *            optional - please use JVIariant.OPTIONAL
   * @param showDialog
   *            optional - please use JVIariant.OPTIONAL
   * @param newSession
   *            optional - please use JVIariant.OPTIONAL
   * @param parentWindow
   *            optional - please use JVIariant.OPTIONAL
   * @param noMail
   *            optional - please use JVIariant.OPTIONAL
   * @param profileInfo
   *            optional - please use JVIariant.OPTIONAL
   * @throws JXCdoException
   */
  public void Logon(JIVariant profileName, JIVariant profilePassword,
      JIVariant showDialog, JIVariant newSession, JIVariant parentWindow,
      JIVariant noMail, JIVariant profileInfo) throws JXCdoException {
    try {
      mapiSessionDispatch.callMethod("Logon", new Object[] { profileName,
          profilePassword, showDialog, newSession, parentWindow,
          noMail, profileInfo });
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The Logoff method logs off from the messaging system.
   *
   * @throws JXCdoException
   */
  public JIVariant Logoff() throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("Logoff");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The GetInfoStore method returns an InfoStore object that can be used to
   * navigate through both public folders and the user's personal folders.")]
   *
   * @param storeID
   *            optional
   * @return
   * @throws JXCdoException
   */
  public JIVariant GetInfoStore(JIVariant storeID) throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetInfoStore",
          new Object[] { storeID })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The GetFolder method returns a Folder object from a message store.
   *
   * @param storeID
   *            optional
   * @return
   * @throws JXCdoException
   */
  public JIVariant GetFolder(JIVariant folderID, JIVariant storeID)
      throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetFolder", new Object[] {
          folderID, storeID })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The GetMessage method returns a Message object from a message store.
   *
   * @param storeID
   *            optional
   * @return
   * @throws JXCdoException
   */
  public JIVariant GetMessage(JIVariant messageID, JIVariant storeID)
      throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetMessage", new Object[] {
          messageID, storeID })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The GetArticle method returns a Message object from a message store based
   * on its article ID.
   *
   * @param storeID
   *            optional
   * @return
   * @throws JXCdoException
   */
  public JIVariant GetArticle(JIVariant articleID, JIVariant folderID,
      JIVariant storeID) throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetArticle", new Object[] {
          articleID, folderID, storeID })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The GetAddressEntry method returns an AddressEntry object.
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant GetAddressEntry(JIVariant entryID) throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetAddressEntry",
          new Object[] { entryID })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The AddressBook method displays a modal dialog box that allows the user
   * to select entries from the address book. The selections are returned in a
   * Recipients collection object.
   *
   * @param ALL
   *            optional
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant AddressBook(JIVariant recipients, JIVariant title,
      JIVariant oneAddress, JIVariant forceResolution,
      JIVariant recipLists, JIVariant toLabel, JIVariant ccLabel,
      JIVariant bccLabel, JIVariant parentWindow) throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("AddressBook", new Object[] {
          recipients, title, oneAddress, forceResolution, recipLists,
          toLabel, ccLabel, bccLabel, parentWindow })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The DeliverNow method requests immediate delivery of all undelivered
   * messages submitted in the current session.
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant DeliverNow() throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("DeliverNow");
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The CompareIDs method determines whether two CDO Library objects are the
   * same object.
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant CompareIDs(JIVariant id1, JIVariant id2)
      throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("CompareIDs", new Object[] {
          id1, id2 })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The CreateConversationIndex method creates a new conversation index or a
   * child conversation index based on a parent conversation index.
   *
   * @param optional
   * @return
   * @throws JXCdoException
   */
  public JIVariant CreateConversationIndex(JIVariant parentIndex)
      throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("CreateConversationIndex",
          new Object[] { parentIndex })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The SetLocaleIDs method sets the Locale, Sort Locale, and Codepage IDs
   * for the current session.
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant SetLocaleIDs(JIVariant localeID, JIVariant codePageID)
      throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("SetLocaleIDs",
          new Object[] { localeID, codePageID })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The GetDefaultFolder method returns the default folder of the specified
   * type.
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant GetDefaultFolder(JIVariant objectType)
      throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetDefaultFolder",
          new Object[] { objectType })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The GetAddressList method returns the default address list of the
   * specified type.
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant GetAddressList(JIVariant objectType) throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetAddressList",
          new Object[] { objectType })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The GetOption method returns a user preference.
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant GetOption(JIVariant optType) throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetOption",
          new Object[] { optType })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * The SetOption method sets a user preference.
   *
   * @return
   * @throws JXCdoException
   */
  public JIVariant SetOption(JIVariant optType, JIVariant optValue)
      throws JXCdoException {
    try {
      return mapiSessionDispatch.callMethodA("GetOption", new Object[] {
          optType, optValue })[0];
    } catch (JIException e) {
      throw new JXCdoException(e);
    }
  }

  /**
   * @exclude
   * @return
   */
  IJIComObject getInnerComObjectToUsAsTemplate()
  {
    return mapiSessionDispatch;
  }
}
TOP

Related Classes of org.jxchange.client.cdo121.JXCdoSession

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.