J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * reserved comment block |
| 3 | * DO NOT REMOVE OR ALTER! |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Copyright 1999-2004 The Apache Software Foundation. |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | * |
| 21 | */ |
| 22 | package com.sun.org.apache.xml.internal.security.keys.storage.implementations; |
| 23 | |
| 24 | |
| 25 | |
| 26 | import java.security.cert.X509Certificate; |
| 27 | import java.util.Iterator; |
| 28 | |
| 29 | import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolverSpi; |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * This {@link StorageResolverSpi} makes a single {@link X509Certificate} |
| 34 | * available to the {@link com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver}. |
| 35 | * |
| 36 | * @author $Author: raul $ |
| 37 | */ |
| 38 | public class SingleCertificateResolver extends StorageResolverSpi { |
| 39 | |
| 40 | /** Field _certificate */ |
| 41 | X509Certificate _certificate = null; |
| 42 | |
| 43 | /** Field _iterator */ |
| 44 | Iterator _iterator = null; |
| 45 | |
| 46 | /** |
| 47 | * |
| 48 | * |
| 49 | * @param x509cert the single {@link X509Certificate} |
| 50 | */ |
| 51 | public SingleCertificateResolver(X509Certificate x509cert) { |
| 52 | this._certificate = x509cert; |
| 53 | this._iterator = new InternalIterator(this._certificate); |
| 54 | } |
| 55 | |
| 56 | /** @inheritDoc */ |
| 57 | public Iterator getIterator() { |
| 58 | return this._iterator; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Class InternalIterator |
| 63 | * |
| 64 | * @author $Author: raul $ |
| 65 | */ |
| 66 | class InternalIterator implements Iterator { |
| 67 | |
| 68 | /** Field _alreadyReturned */ |
| 69 | boolean _alreadyReturned = false; |
| 70 | |
| 71 | /** Field _certificate */ |
| 72 | X509Certificate _certificate = null; |
| 73 | |
| 74 | /** |
| 75 | * Constructor InternalIterator |
| 76 | * |
| 77 | * @param x509cert |
| 78 | */ |
| 79 | public InternalIterator(X509Certificate x509cert) { |
| 80 | this._certificate = x509cert; |
| 81 | } |
| 82 | |
| 83 | /** @inheritDoc */ |
| 84 | public boolean hasNext() { |
| 85 | return (!this._alreadyReturned); |
| 86 | } |
| 87 | |
| 88 | /** @inheritDoc */ |
| 89 | public Object next() { |
| 90 | |
| 91 | this._alreadyReturned = true; |
| 92 | |
| 93 | return this._certificate; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Method remove |
| 98 | * |
| 99 | */ |
| 100 | public void remove() { |
| 101 | throw new UnsupportedOperationException( |
| 102 | "Can't remove keys from KeyStore"); |
| 103 | } |
| 104 | } |
| 105 | } |