Package org.apache.james.jdkim.impl

Source Code of org.apache.james.jdkim.impl.MultiplexingPublicKeyRecordRetriever

/****************************************************************
* 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 org.apache.james.jdkim.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.james.jdkim.api.PublicKeyRecordRetriever;
import org.apache.james.jdkim.exceptions.PermFailException;
import org.apache.james.jdkim.exceptions.TempFailException;

public class MultiplexingPublicKeyRecordRetriever implements
        PublicKeyRecordRetriever {

    private Map<String, PublicKeyRecordRetriever> retrievers;

    public MultiplexingPublicKeyRecordRetriever() {
        retrievers = new HashMap<String, PublicKeyRecordRetriever>();
    }

    public MultiplexingPublicKeyRecordRetriever(String methodName,
            PublicKeyRecordRetriever pkrr) {
        this();
        addRetriever(methodName, pkrr);
    }

    public void addRetriever(String methodName, PublicKeyRecordRetriever pkrr) {
        retrievers.put(methodName, pkrr);
    }

    public List<String> getRecords(CharSequence methodAndOption, CharSequence selector,
            CharSequence token) throws TempFailException, PermFailException {
        int pos = methodAndOption.toString().indexOf('/');
        String method = pos != -1 ? methodAndOption.subSequence(0, pos)
                .toString() : methodAndOption.toString();
        PublicKeyRecordRetriever pkrr = retrievers.get(method);
        if (pkrr != null) {
            return pkrr.getRecords(methodAndOption, selector, token);
        } else {
            throw new PermFailException(
                    "Unknown public key record retrieving method: "
                            + methodAndOption);
        }
    }

}
TOP

Related Classes of org.apache.james.jdkim.impl.MultiplexingPublicKeyRecordRetriever

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.