View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.config;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import java.io.Serializable;
26  import java.util.Collection;
27  import java.util.HashMap;
28  import java.util.Map;
29  
30  public class RenderersConfigImpl implements RenderersConfig, Serializable {
31  
32    private static final long serialVersionUID = 1L;
33  
34    private static final Logger LOG = LoggerFactory.getLogger(RenderersConfigImpl.class);
35  
36    private Map<String, RendererConfig> rendererMap = new HashMap<String, RendererConfig>();
37  
38    private boolean merged = false;
39  
40    public boolean isMerged() {
41      return merged;
42    }
43  
44    public void setMerged(boolean merged) {
45      this.merged = merged;
46    }
47  
48    public Collection<RendererConfig> getRendererConfigs() {
49      return rendererMap.values();
50    }
51  
52    public void addRenderer(RendererConfig rendererConfig) {
53      final String name = rendererConfig.getName();
54      if (rendererMap.containsKey(name)) {
55        rendererMap.get(name).merge(rendererConfig);
56      } else {
57        rendererMap.put(name, rendererConfig);
58      }
59    }
60  
61    public boolean isMarkupSupported(String rendererName, String markup) {
62      if (LOG.isDebugEnabled()) {
63        LOG.debug("calling isMarkupSupported('{}', '{}')", rendererName, markup);
64      }
65      RendererConfig rendererConfig = rendererMap.get(rendererName);
66      if (rendererConfig != null) {
67        return rendererConfig.contains(markup);
68      } else {
69        LOG.error("Calling isMarkupSupported('{}', '{}'), but no configuration found.", rendererName, markup);
70        return false;
71      }
72    }
73  
74    public void merge(RenderersConfig renderersConfig, boolean override) {
75      Collection<RendererConfig> renderers = renderersConfig.getRendererConfigs();
76      for (RendererConfig rendererConfig : renderers) {
77        addRenderer(rendererConfig);
78      }
79    }
80  
81    public String toString() {
82      return rendererMap.toString();
83    }
84  }