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