001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.util.component; 018 019import java.util.Collections; 020import java.util.HashMap; 021import java.util.HashSet; 022import java.util.Map; 023import java.util.Set; 024 025/** 026 * Base class for a collection of ApiMethods. Meant to be extended by Components to create the api name map. 027 */ 028public abstract class ApiCollection<E extends Enum<E> & ApiName, T> { 029 030 protected final Map<E, ApiMethodHelper<? extends ApiMethod>> apis = new HashMap<E, ApiMethodHelper<? extends ApiMethod>>(); 031 protected final HashMap<Class<? extends ApiMethod>, E> apiMethods = new HashMap<Class<? extends ApiMethod>, E>(); 032 033 public final Map<E, ApiMethodHelper<? extends ApiMethod>> getApiHelpers() { 034 return Collections.unmodifiableMap(apis); 035 } 036 037 public final Map<Class<? extends ApiMethod>, E> getApiMethods() { 038 return Collections.unmodifiableMap(apiMethods); 039 } 040 041 /** 042 * Returns a {@link ApiMethodHelper} for a particular API. 043 * @param apiName name of the API 044 * @return helper class to work with {@link ApiMethod} 045 */ 046 public final ApiMethodHelper<? extends ApiMethod> getHelper(E apiName) { 047 return apis.get(apiName); 048 } 049 050 /** 051 * Returns a list of API name strings. 052 * @return list of API names. 053 */ 054 public final Set<String> getApiNames() { 055 final Set<String> result = new HashSet<String>(); 056 for (E api : apis.keySet()) { 057 result.add(api.getName()); 058 } 059 return Collections.unmodifiableSet(result); 060 } 061 062 public final E getApiName(Class<? extends ApiMethod> apiMethod) { 063 return apiMethods.get(apiMethod); 064 } 065 066 /** 067 * Creates an endpoint configuration for a particular API 068 * @param apiName name of the API. 069 * @return Endpoint configuration object for the API. 070 */ 071 public abstract T getEndpointConfiguration(E apiName); 072}