home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / Provider.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  152 lines

  1. /*
  2.  * @(#)Provider.java    1.19 97/01/30
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.security;
  24.  
  25. import java.io.*;
  26. import java.util.*;
  27.  
  28. /**
  29.  * This class represents a "provider" for the
  30.  * Java Security API.  A provider implements some or all parts of
  31.  * Java Security, including:<ul>
  32.  *
  33.  * <li>Algorithms (such as DSA, RSA, MD5 or SHA-1).
  34.  *
  35.  * <li>Key generation and management facilities (such as for
  36.  * algorithm-specific keys).
  37.  *
  38.  * </ul>
  39.  *
  40.  * <p>Each provider has a name and a version number, and is configured
  41.  * in each runtime it is installed in. 
  42.  * 
  43.  * <p>There is a default provider that comes standard with the JDK. It is
  44.  * called the SUN Provider.
  45.  * 
  46.  * See <a href =
  47.  * "../guide/security/CryptoSpec.html#Provider">The Provider Class</a> 
  48.  * in the "Java Cryptography Architecture API Specification & Reference"
  49.  * for information about how providers work and how to install them.
  50.  * 
  51.  * @version     1.19, 01/30/97
  52.  * @author Benjamin Renaud */
  53.  
  54. public abstract class Provider extends Properties {
  55.  
  56.     private String name;
  57.     private String info;
  58.     private double version;
  59.  
  60.     /**
  61.      * Constructs a provider with the specified name, version number,
  62.      * and information.
  63.      *
  64.      * @param name the provider name.
  65.      *
  66.      * @param version the provider version number.
  67.      * 
  68.      * @param info a description of the provider and its services.
  69.      */
  70.     protected Provider(String name, double version, String info) {
  71.     this.name = name;
  72.     this.version = version;
  73.     this.info = info;
  74.     }
  75.  
  76.     /**
  77.      * Constructs a provider with the specified name. Assigns it
  78.      * version 1.0.
  79.      *
  80.      * @param name the provider name.  
  81.      */
  82.     Provider(String name) {
  83.     this(name, 1.0, "no information available");
  84.     }
  85.  
  86.     /**
  87.      * Returns the name of this provider.     
  88.      * 
  89.      * @return the name of this provider.
  90.      */
  91.     public String getName() {
  92.     return name;
  93.     }
  94.  
  95.     /**
  96.      * Returns the version number for this provider.     
  97.      * 
  98.      * @return the version number for this provider.
  99.      */
  100.     public double getVersion() {
  101.     return version;
  102.     }
  103.  
  104.     /**
  105.      * Returns a human-readable description of the provider and its
  106.      * services.  This may return an HTML page, with relevant links.
  107.      *
  108.      * @return a description of the provider and its services.  
  109.      */
  110.     public String getInfo() {
  111.     return info;
  112.     }
  113.  
  114.  
  115.     static Provider loadProvider(String name) {
  116.     
  117.     try {
  118.         Class cl = Class.forName(name);
  119.         Object instance = cl.newInstance();
  120.  
  121.         if (instance instanceof Provider) {
  122.         return (Provider)instance;
  123.         }
  124.  
  125.     } catch (Exception e) {
  126.         debug("error loading provider " + name, e);
  127.     }
  128.     return null;
  129.     }
  130.  
  131.  
  132.     /**
  133.      * Returns a string with the name and the version number
  134.      * of this provider.     
  135.      * 
  136.      * @return the string with the name and the version number
  137.      * for this provider.
  138.      */
  139.     public String toString() {
  140.     return name + " version " + version;
  141.     }
  142.  
  143.     private static void debug(String msg) {
  144.     Security.debug(msg);
  145.     }
  146.  
  147.     private static void debug(String msg, Throwable t) {
  148.     Security.debug(msg, t);
  149.     }
  150. }
  151.  
  152.