View Javadoc

1   /*
2    * Copyright 2004 Sun Microsystems, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package com.sun.syndication.feed.synd.impl;
18  
19  import com.sun.syndication.io.impl.PlugableClasses;
20  import com.sun.syndication.feed.synd.SyndFeed;
21  import com.sun.syndication.feed.synd.Converter;
22  
23  import java.util.Map;
24  import java.util.List;
25  import java.util.HashMap;
26  import java.util.Collections;
27  import java.util.ArrayList;
28  
29  /***
30   * Created by IntelliJ IDEA.
31   * User: tucu
32   * Date: May 21, 2004
33   * Time: 5:26:04 PM
34   * To change this template use Options | File Templates.
35   */
36  public class Converters {
37      private Map _converters;
38      private List _types;
39  
40      private Map loadConverters(String defaultFile,String fileProperty) {
41          Map map = new HashMap();
42          PlugableClasses pClasses = new PlugableClasses(defaultFile,fileProperty,
43                                                         Constants.CONVERTERS_KEY,true,SyndFeed.class.getClassLoader());
44          Object[] converters;
45          try {
46              converters = pClasses.createInstances();
47          }
48          catch (Exception ex) {
49              throw new RuntimeException(ex);
50          }
51          for (int i=0;i<converters.length;i++) {
52              Converter converter  = (Converter) converters[i];
53              map.put(converter.getType(),converter);
54          }
55          return map;
56      }
57  
58      public Converters() {
59          this(Constants.DEFAULT_IMPLS_FILE,Constants.IMPLS_FILE_PROPERTY);
60      }
61  
62      public Converters(String defaultFile,String fileProperty) {
63          _converters = loadConverters(defaultFile,fileProperty);
64          _types = Collections.unmodifiableList(new ArrayList(_converters.keySet()));
65      }
66  
67      public List getSupportedFeedTypes() {
68          return _types;
69      }
70  
71      public Converter getConverter(String type) {
72          return (Converter) _converters.get(type);
73      }
74  
75  }