| 1 |
/* |
| 2 |
* Copyright 1999-2010 University of Chicago |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 |
* express or implied. |
| 12 |
* |
| 13 |
* See the License for the specific language governing permissions and limitations under the License. |
| 14 |
*/ |
| 15 |
package org.globus.gsi; |
| 16 |
|
| 17 |
import java.util.Set; |
| 18 |
import java.util.Hashtable; |
| 19 |
|
| 20 |
import org.globus.util.I18n; |
| 21 |
|
| 22 |
/** |
| 23 |
* Represents a set of X.509 extensions. |
| 24 |
*/ |
| 25 |
public class X509ExtensionSet { |
| 26 |
|
| 27 |
private static I18n i18n = |
| 28 |
I18n.getI18n("org.globus.gsi.errors", |
| 29 |
X509ExtensionSet.class.getClassLoader()); |
| 30 |
|
| 31 |
private Hashtable extensions; |
| 32 |
|
| 33 |
/** |
| 34 |
* Creates an empty X509ExtensionSet object. |
| 35 |
*/ |
| 36 |
public X509ExtensionSet() { |
| 37 |
this.extensions = new Hashtable(); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Adds a X509Extension object to this set. |
| 42 |
* |
| 43 |
* @param extension the extension to add |
| 44 |
* @return an extension that was removed with the same oid as the |
| 45 |
* new extension. Null, if none existed before. |
| 46 |
*/ |
| 47 |
public X509Extension add(X509Extension extension) { |
| 48 |
if (extension == null) { |
| 49 |
throw new IllegalArgumentException(i18n |
| 50 |
.getMessage("extensionNull")); |
| 51 |
} |
| 52 |
return (X509Extension)this.extensions.put(extension.getOid(), |
| 53 |
extension); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Retrieves X509Extension by given oid. |
| 58 |
* |
| 59 |
* @param oid the oid of the extension to retrieve. |
| 60 |
* @return the extension with the specified oid. Can be null if |
| 61 |
* there is no extension with such oid. |
| 62 |
*/ |
| 63 |
public X509Extension get(String oid) { |
| 64 |
if (oid == null) { |
| 65 |
throw new IllegalArgumentException(i18n.getMessage("oidNull")); |
| 66 |
} |
| 67 |
return (X509Extension)this.extensions.get(oid); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Removes X509Extension by given oid. |
| 72 |
* |
| 73 |
* @param oid the oid of the extension to remove. |
| 74 |
* @return extension that was removed. Null, if extension with the |
| 75 |
* specified oid does not exist in this set. |
| 76 |
*/ |
| 77 |
public X509Extension remove(String oid) { |
| 78 |
if (oid == null) { |
| 79 |
throw new IllegalArgumentException(i18n.getMessage("oidNull")); |
| 80 |
} |
| 81 |
return (X509Extension)this.extensions.remove(oid); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Returns the size of the set. |
| 86 |
* |
| 87 |
* @return the size of the set. |
| 88 |
*/ |
| 89 |
public int size() { |
| 90 |
return this.extensions.size(); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Returns if the set is empty. |
| 95 |
* |
| 96 |
* @return true if the set if empty, false otherwise. |
| 97 |
*/ |
| 98 |
public boolean isEmpty() { |
| 99 |
return this.extensions.isEmpty(); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Removes all extensions from the set. |
| 104 |
*/ |
| 105 |
public void clear() { |
| 106 |
this.extensions.clear(); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Returns a set view of the OIDs of the extensions contained in this |
| 111 |
* extension set. |
| 112 |
* |
| 113 |
* @return the set with oids. |
| 114 |
*/ |
| 115 |
public Set oidSet() { |
| 116 |
return this.extensions.keySet(); |
| 117 |
} |
| 118 |
|
| 119 |
} |