home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / AspContext.java < prev    next >
Text File  |  1997-10-25  |  4KB  |  126 lines

  1. /*  ********************************************************************************
  2.     AspContext.java ****************************************************************
  3.     ********************************************************************************  */
  4.  
  5. package aspcomp;
  6.  
  7. import com.ms.com.*;
  8. import com.ms.asp.*;
  9. import com.ms.mtx.*;
  10.  
  11. /**
  12.  * The class from which a component gains access to the ASP intrinsic covers of the
  13.  * framework. 
  14.  * All the methods are static, to allow them to be called without creating an
  15.  * instance of this class.
  16.  */
  17.  
  18. public class AspContext
  19. {
  20.  
  21. /*  ********************************************************************************
  22.     Internal (Private) Constants ***************************************************
  23.     ********************************************************************************  */
  24.     
  25.     private static final String REQUEST = "Request";
  26.     private static final String RESPONSE = "Response";
  27.     private static final String SERVER = "Server";
  28.     private static final String SESSION = "Session";
  29.     private static final String APPLICATION = "Application";
  30.  
  31.  
  32. /*  ********************************************************************************
  33.     Internal (Private) Access Methods **********************************************
  34.     ********************************************************************************  */
  35.  
  36.     private static Object getIntrinsic(String strIntrinsic) 
  37.         throws AspComponentException
  38.     {
  39.         Variant v;
  40.         IGetContextProperties cp;
  41.  
  42.         try
  43.         {
  44.             cp = (IGetContextProperties) MTx.GetObjectContext();
  45.         }
  46.  
  47.         catch(Exception e)
  48.         {
  49.             throw new AspComponentException(
  50.                 AspLocalizedStrings.ASP_E_FAIL_GET_CONTEXT);
  51.         }
  52.         
  53.         if ( (strIntrinsic.equals(REQUEST))     ||
  54.              (strIntrinsic.equals(RESPONSE))    ||
  55.              (strIntrinsic.equals(SERVER))      ||
  56.              (strIntrinsic.equals(SESSION))     ||
  57.              (strIntrinsic.equals(APPLICATION)) )
  58.         {
  59.              v = cp.GetProperty(strIntrinsic);
  60.  
  61.              return v.getDispatch();
  62.         }
  63.         else 
  64.         {
  65.             throw new AspComponentException(
  66.                 AspLocalizedStrings.ASP_E_FAIL_GET_INTRINSIC);
  67.         }
  68.     }
  69.  
  70.  
  71. /*  ********************************************************************************
  72.     External (Public) Methods ******************************************************
  73.     ********************************************************************************  */
  74.  
  75.     public static Request getRequest()
  76.     {
  77.         IRequest aspRequest = (IRequest) getIntrinsic(REQUEST);
  78.         IResponse aspResponse = (IResponse) getIntrinsic(RESPONSE);
  79.         return new Request(aspRequest, aspResponse);
  80.     }
  81.  
  82.     public static Response getResponse()
  83.     {
  84.         IResponse aspResponse = (IResponse) getIntrinsic(RESPONSE);
  85.         return new Response(aspResponse);
  86.     }
  87.  
  88.     public static Server getServer()
  89.     {
  90.         IServer aspServer = (IServer) getIntrinsic(SERVER);
  91.         return new Server(aspServer);
  92.     }
  93.  
  94.     public static Session getSession()
  95.     {
  96.         ISessionObject aspSession = (ISessionObject) getIntrinsic(SESSION);
  97.         return new Session(aspSession);
  98.     }
  99.  
  100.     public static Application getApplication()
  101.     {
  102.         IApplicationObject aspApplication = 
  103.             (IApplicationObject) getIntrinsic(APPLICATION);
  104.  
  105.         return new Application(aspApplication);
  106.     }
  107.  
  108.     public static IObjectContext getObjectContext()
  109.     {
  110.         IObjectContext objContext;
  111.  
  112.         try
  113.         {
  114.             objContext = (IObjectContext) MTx.GetObjectContext(); 
  115.         }
  116.  
  117.         catch(Exception e)
  118.         {
  119.              throw new AspComponentException(
  120.                 AspLocalizedStrings.ASP_E_FAIL_GET_CONTEXT);
  121.         }
  122.  
  123.         return objContext;
  124.     }
  125. }
  126.