PR c/63357
[official-gcc.git] / libjava / classpath / java / security / Provider.java
blobb1d6d9ce2a9e57d423f3e97e24183eec7d1e65cc
1 /* Provider.java -- Security provider information
2 Copyright (C) 1998, 1999, 2000, 2002, 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.security;
40 import java.io.Serializable;
41 import java.util.Properties;
43 /**
44 * This class represents a Java security architecture service provider. The
45 * services provided by a such a provider can range from security algorithms to
46 * key generation.
47 * <p>
48 * Providers are installed by name and version number. See the static
49 * initializer of the {@link java.security.Security} class for the default
50 * security providers installed by this class library.
52 * @author Aaron M. Renn (arenn@urbanophile.com)
54 public abstract class Provider
55 extends Properties
56 implements Serializable
58 private static final long serialVersionUID = -4298000515446427739L;
60 /**
61 * This is a textual description of the provider
63 private String info;
65 /**
66 * This is the name of the provider
68 private String name;
70 /**
71 * This is the version number of the provider
73 private double version;
75 /**
76 * This method initializes a new instance of <code>Provider</code> to have
77 * the specified name, version, and description information.
79 * @param name The name to assign to this <code>Provider</code>.
80 * @param version The version number for this <code>Provider</code>.
81 * @param info A textual description of this provider.
83 protected Provider(String name, double version, String info)
85 this.name = name;
86 this.version = version;
87 this.info = info;
90 /**
91 * This method returns the name assigned to this <code>Provider</code>.
93 * @return The <code>Provider</code>'s name.
95 public String getName()
97 return (name);
101 * This method retunrs the version number of this <code>Provider</code>.
103 * @return The <code>Provider</code>'s version number.
105 public double getVersion()
107 return (version);
111 * This method returns a textual description of the <code>Provider</code>.
113 * @return A description of the <code>Provider</code>.
115 public String getInfo()
117 return (info);
121 * Maps a key property to a designated value.
122 * <p>
123 * If there is an installed {@link SecurityManager} object in the underlying
124 * VM, its {@link SecurityManager#checkSecurityAccess(String)} method is
125 * called with the string <code>"putProviderProperty." + name</code>, where
126 * <code>name</code> is this provider's name. For the default implementation
127 * this translates into a {@link SecurityManager#checkPermission(Permission)}
128 * for a <code>SecurityPermission("putProviderProperty." + name)</code>.
130 * @param key The property key.
131 * @param value The property value.
132 * @return The previous value of the specified property (<code>key</code>),
133 * or <code>null</code> if it did not have one.
134 * @throws SecurityException If a security manager is installed and its
135 * {@link SecurityManager#checkSecurityAccess(String)} method
136 * disallows adding properties at run-time.
137 * @since Classpath 0.4+cvs, JDK 1.2
138 * @see java.lang.Object#equals(Object)
139 * @see java.util.Hashtable#get(Object)
141 public Object put(Object key, Object value)
143 SecurityManager sm = System.getSecurityManager();
144 if (sm != null)
145 sm.checkSecurityAccess("putProviderProperty." + this.name);
146 return super.put(toCanonicalKey(key), value);
149 // overrides same in java.util.Hashtable
150 public Object get(Object key)
152 return super.get(toCanonicalKey(key));
156 * This method removes the specified key entry (and its associated value)
157 * from the property mapping collection.
158 * <p>
159 * If there is an installed {@link SecurityManager} object in the underlying
160 * VM, its {@link SecurityManager#checkSecurityAccess(String)} method is
161 * called with the string <code>"removeProviderProperty." + name</code>, where
162 * <code>name</code> is this provider's name. For the default implementation
163 * this translates into a {@link SecurityManager#checkPermission(Permission)}
164 * for a <code>SecurityPermission("removeProviderProperty." + name)</code>.
166 * @param key The key to remove
167 * @return The previous value for this key, or <code>null</code> if no
168 * previous value.
170 public Object remove(Object key)
172 SecurityManager sm = System.getSecurityManager();
173 if (sm != null)
174 sm.checkSecurityAccess("removeProviderProperty." + this.name);
175 return super.remove(toCanonicalKey(key));
179 * This method clears the entire property collection such that it no longer
180 * contains the properties used to look up the services provided by
181 * this <code>Provider</code>.
182 * <p>
183 * If there is an installed {@link SecurityManager} object in the underlying
184 * VM, its {@link SecurityManager#checkSecurityAccess(String)} method is
185 * called with the string <code>"clearProviderProperties." + name</code>,
186 * where <code>name</code> is this provider's name. For the default
187 * implementation this translates into a
188 * {@link SecurityManager#checkPermission(Permission)} for a
189 * <code>SecurityPermission("clearProviderProperties." + name)</code>.
191 public void clear()
193 SecurityManager sm = System.getSecurityManager();
194 if (sm != null)
195 sm.checkSecurityAccess("clearProviderProperties." + this.name);
196 super.clear();
200 * This method returns a <code>String</code> representation of this
201 * object. This will include the <code>Provider</code> name and
202 * version number.
204 * @return A <code>String</code> representation of this object.
206 public String toString()
208 return (getClass().getName() + ": name=" + getName() + " version=" +
209 version);
212 private Object toCanonicalKey(Object key)
214 if (key.getClass().isAssignableFrom(String.class)) // is it ours?
215 return ((String) key).toUpperCase(); // use default locale
216 return key;