home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / COM / security_com / CMyCOMObject.java next >
Encoding:
Java Source  |  2000-05-04  |  1.9 KB  |  68 lines

  1. // CMyCOMObject.java
  2. //
  3. //
  4. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  5. //
  6.  
  7. package comsamp;
  8.  
  9. import com.ms.com.*;
  10.  
  11.  
  12. // jactivex-generated.
  13. /** @com.class(classid=8EACC4B2-289A-11D1-BA1D-006008039BF0,DynamicCasts)
  14. */
  15. class CMyCOMObjectImp implements IUnknown,com.ms.com.NoAutoScripting,IMyInterface
  16. {
  17.   /** @com.method() */
  18.   public native void COMCheckedLoad(String filename, byte[] buffer, int[] bufsize);
  19.  
  20.   /** @com.method() */
  21.   public native void JavaCheckedLoad(String filename, byte[] buffer, int[] bufsize);
  22.  
  23.  
  24.   public static final com.ms.com._Guid clsid = new com.ms.com._Guid((int)0x8eacc4b2, (short)0x289a, (short)0x11d1, (byte)0xba, (byte)0x1d, (byte)0x0, (byte)0x60, (byte)0x8, (byte)0x3, (byte)0x9b, (byte)0xf0);
  25. }
  26.  
  27.  
  28. /**
  29.  * Wraps the COM implementation of CMyCOMObject and re-implements the
  30.  * JavaCheckedLoad method to perform a security check before invoking
  31.  * the existing COM implementation.
  32.  * The implementation of COMCheckedLoad simply delegates to the COM
  33.  * implementation.
  34.  */
  35. public class CMyCOMObject
  36. {
  37.     IMyInterface imp = new CMyCOMObjectImp();
  38.  
  39.     public void COMCheckedLoad(String filename, byte[] buffer, int[] bufsize)
  40.     {
  41.         imp.COMCheckedLoad(filename, buffer, bufsize);
  42.     }
  43.  
  44.     public void JavaCheckedLoad (String filename, byte[] buffer, int[] bufsize)
  45.     {
  46.         SecurityManager security = System.getSecurityManager();
  47.         if (security != null)
  48.             security.checkRead(filename);
  49.         imp.JavaCheckedLoad(filename, buffer, bufsize);
  50.     }
  51. }
  52.  
  53.  
  54. /**
  55.  * Used from COM to perform security checks.
  56.  */
  57. class CMyCOMObjectSecurity implements IMyCOMObjectSecurity
  58. {
  59.     public void CheckRead (String filename)
  60.     {
  61.         SecurityManager security = System.getSecurityManager();
  62.         if (security != null)
  63.             security.checkRead(filename);
  64.     }
  65. }
  66.  
  67.  
  68.