src/share/classes/com/sun/org/apache/xml/internal/security/keys/storage/StorageResolver.java
Print this page
*** 1,53 ****
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
! /*
! * Copyright 1999-2004 The Apache Software Foundation.
! *
! * Licensed under the Apache License, Version 2.0 (the "License");
! * you may not use this file except in compliance with the License.
! * You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
! * Unless required by applicable law or agreed to in writing, software
! * distributed under the License is distributed on an "AS IS" BASIS,
! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! * See the License for the specific language governing permissions and
! * limitations under the License.
! *
*/
package com.sun.org.apache.xml.internal.security.keys.storage;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.sun.org.apache.xml.internal.security.keys.storage.implementations.KeyStoreResolver;
import com.sun.org.apache.xml.internal.security.keys.storage.implementations.SingleCertificateResolver;
-
/**
* This class collects customized resolvers for Certificates.
- *
- * @author $Author: mullan $
*/
public class StorageResolver {
! /** {@link java.util.logging} logging facility */
! static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(StorageResolver.class.getName());
! /** Field _storageResolvers */
! List<Object> _storageResolvers = null;
!
! /** Field _iterator */
! Iterator<Object> _iterator = null;
/**
* Constructor StorageResolver
*
*/
--- 1,51 ----
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
! /**
! * Licensed to the Apache Software Foundation (ASF) under one
! * or more contributor license agreements. See the NOTICE file
! * distributed with this work for additional information
! * regarding copyright ownership. The ASF licenses this file
! * to you under the Apache License, Version 2.0 (the
! * "License"); you may not use this file except in compliance
! * with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
! * Unless required by applicable law or agreed to in writing,
! * software distributed under the License is distributed on an
! * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
! * KIND, either express or implied. See the License for the
! * specific language governing permissions and limitations
! * under the License.
*/
package com.sun.org.apache.xml.internal.security.keys.storage;
import java.security.KeyStore;
+ import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+ import java.util.NoSuchElementException;
import com.sun.org.apache.xml.internal.security.keys.storage.implementations.KeyStoreResolver;
import com.sun.org.apache.xml.internal.security.keys.storage.implementations.SingleCertificateResolver;
/**
* This class collects customized resolvers for Certificates.
*/
public class StorageResolver {
! /** {@link org.apache.commons.logging} logging facility */
! private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(StorageResolver.class.getName());
! /** Field storageResolvers */
! private List<StorageResolverSpi> storageResolvers = null;
/**
* Constructor StorageResolver
*
*/
*** 66,80 ****
* Method addResolver
*
* @param resolver
*/
public void add(StorageResolverSpi resolver) {
! if (_storageResolvers==null)
! _storageResolvers=new ArrayList<Object>();
! this._storageResolvers.add(resolver);
!
! this._iterator = null;
}
/**
* Constructor StorageResolver
*
--- 64,77 ----
* Method addResolver
*
* @param resolver
*/
public void add(StorageResolverSpi resolver) {
! if (storageResolvers == null) {
! storageResolvers = new ArrayList<StorageResolverSpi>();
! }
! this.storageResolvers.add(resolver);
}
/**
* Constructor StorageResolver
*
*** 88,98 ****
* Method addKeyStore
*
* @param keyStore
*/
public void add(KeyStore keyStore) {
-
try {
this.add(new KeyStoreResolver(keyStore));
} catch (StorageResolverException ex) {
log.log(java.util.logging.Level.SEVERE, "Could not add KeyStore because of: ", ex);
}
--- 85,94 ----
*** 117,198 ****
}
/**
* Method getIterator
* @return the iterator for the resolvers.
- *
*/
! public Iterator<Object> getIterator() {
!
! if (this._iterator == null) {
! if (_storageResolvers==null)
! _storageResolvers=new ArrayList<Object>();
! this._iterator = new StorageResolverIterator(this._storageResolvers.iterator());
! }
!
! return this._iterator;
}
/**
! * Method hasNext
! *
! * @return true if there is more elements.
*/
! public boolean hasNext() {
! if (this._iterator == null) {
! if (_storageResolvers==null)
! _storageResolvers=new ArrayList<Object>();
! this._iterator = new StorageResolverIterator(this._storageResolvers.iterator());
! }
! return this._iterator.hasNext();
! }
/**
! * Method next
*
! * @return the next element
*/
! public X509Certificate next() {
! return (X509Certificate) this._iterator.next();
}
! /**
! * Class StorageResolverIterator
! *
! * @author $Author: mullan $
! * @version $Revision: 1.5 $
! */
! static class StorageResolverIterator implements Iterator<Object> {
! /** Field _resolvers */
! Iterator<Object> _resolvers = null;
! /**
! * Constructor FilesystemIterator
! *
! * @param resolvers
! */
! public StorageResolverIterator(Iterator<Object> resolvers) {
! this._resolvers = resolvers;
}
/** @inheritDoc */
! public boolean hasNext() {
! return _resolvers.hasNext();
}
! /** @inheritDoc */
! public Object next() {
! return _resolvers.next();
}
/**
* Method remove
*/
public void remove() {
! throw new UnsupportedOperationException(
! "Can't remove keys from KeyStore");
}
}
}
--- 113,188 ----
}
/**
* Method getIterator
* @return the iterator for the resolvers.
*/
! public Iterator<Certificate> getIterator() {
! return new StorageResolverIterator(this.storageResolvers.iterator());
}
/**
! * Class StorageResolverIterator
! * This iterates over all the Certificates found in all the resolvers.
*/
! static class StorageResolverIterator implements Iterator<Certificate> {
! /** Field resolvers */
! Iterator<StorageResolverSpi> resolvers = null;
! /** Field currentResolver */
! Iterator<Certificate> currentResolver = null;
/**
! * Constructor StorageResolverIterator
*
! * @param resolvers
*/
! public StorageResolverIterator(Iterator<StorageResolverSpi> resolvers) {
! this.resolvers = resolvers;
! currentResolver = findNextResolver();
}
! /** @inheritDoc */
! public boolean hasNext() {
! if (currentResolver == null) {
! return false;
! }
! if (currentResolver.hasNext()) {
! return true;
! }
! currentResolver = findNextResolver();
! return (currentResolver != null);
}
/** @inheritDoc */
! public Certificate next() {
! if (hasNext()) {
! return currentResolver.next();
}
! throw new NoSuchElementException();
}
/**
* Method remove
*/
public void remove() {
! throw new UnsupportedOperationException("Can't remove keys from KeyStore");
! }
!
! // Find the next storage with at least one element and return its Iterator
! private Iterator<Certificate> findNextResolver() {
! while (resolvers.hasNext()) {
! StorageResolverSpi resolverSpi = resolvers.next();
! Iterator<Certificate> iter = resolverSpi.getIterator();
! if (iter.hasNext()) {
! return iter;
! }
! }
!
! return null;
}
}
}