View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  package com.addthis.codec.plugins;
15  
16  import com.google.common.annotations.Beta;
17  
18  @Beta
19  public final class Plugins {
20      private Plugins() {}
21  
22      public static String classNameSuggestions(PluginRegistry pluginRegistry,
23                                                PluginMap pluginMap,
24                                                String type) {
25          StringBuilder builder = new StringBuilder();
26  
27          builder.append("Could not instantiate an instance of the ")
28                 .append(pluginMap.category()).append(" category that you have specified")
29                 .append(" with \"").append(type).append("\".");
30  
31          if (pluginRegistry != null) {
32              for (PluginMap otherMap : pluginRegistry.asMap().values()) {
33                  if (otherMap.asBiMap().containsKey(type)) {
34                      builder.append("\nIt looks like you tried to instantiate a ")
35                             .append(otherMap.category()).append('.');
36                      return builder.toString();
37                  }
38              }
39          }
40  
41          builder.append("\nPerhaps you intended one of the following: ")
42                 .append(pluginMap.asBiMap().keySet());
43          return builder.toString();
44      }
45  }