| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.config.faces.element.impl; |
| 17 | |
|
| 18 | |
import java.util.HashMap; |
| 19 | |
import java.util.Iterator; |
| 20 | |
import java.util.LinkedList; |
| 21 | |
import java.util.List; |
| 22 | |
import java.util.Map; |
| 23 | |
import java.util.Map.Entry; |
| 24 | |
|
| 25 | |
import org.seasar.framework.util.AssertionUtil; |
| 26 | |
import org.seasar.teeda.core.config.faces.element.ApplicationElement; |
| 27 | |
import org.seasar.teeda.core.config.faces.element.ComponentElement; |
| 28 | |
import org.seasar.teeda.core.config.faces.element.ConverterElement; |
| 29 | |
import org.seasar.teeda.core.config.faces.element.FacesConfig; |
| 30 | |
import org.seasar.teeda.core.config.faces.element.FactoryElement; |
| 31 | |
import org.seasar.teeda.core.config.faces.element.LifecycleElement; |
| 32 | |
import org.seasar.teeda.core.config.faces.element.ManagedBeanElement; |
| 33 | |
import org.seasar.teeda.core.config.faces.element.NavigationRuleElement; |
| 34 | |
import org.seasar.teeda.core.config.faces.element.ReferencedBeanElement; |
| 35 | |
import org.seasar.teeda.core.config.faces.element.RenderKitElement; |
| 36 | |
import org.seasar.teeda.core.config.faces.element.RendererElement; |
| 37 | |
import org.seasar.teeda.core.config.faces.element.ValidatorElement; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public class FacesConfigWrapperImpl implements FacesConfig { |
| 44 | |
|
| 45 | 6 | private List applications_ = new LinkedList(); |
| 46 | |
|
| 47 | 6 | private List factories_ = new LinkedList(); |
| 48 | |
|
| 49 | 6 | private List lifecycles_ = new LinkedList(); |
| 50 | |
|
| 51 | 6 | private List referencedBeans_ = new LinkedList(); |
| 52 | |
|
| 53 | 6 | private List navigationRules_ = new LinkedList(); |
| 54 | |
|
| 55 | 6 | private Map components_ = new HashMap(); |
| 56 | |
|
| 57 | 6 | private Map convertersByIds_ = new HashMap(); |
| 58 | |
|
| 59 | 6 | private Map convertersByClasses_ = new HashMap(); |
| 60 | |
|
| 61 | 6 | private Map managedBeans_ = new HashMap(); |
| 62 | |
|
| 63 | 6 | private Map renderKits_ = new HashMap(); |
| 64 | |
|
| 65 | 6 | private Map validators_ = new HashMap(); |
| 66 | |
|
| 67 | 6 | public FacesConfigWrapperImpl(List facesConfigs) { |
| 68 | 6 | AssertionUtil.assertNotNull("facesConfig is null.", facesConfigs); |
| 69 | 6 | deployAllFacesConfig(facesConfigs); |
| 70 | 6 | } |
| 71 | |
|
| 72 | |
public void addApplicationElement(ApplicationElement application) { |
| 73 | 0 | applications_.add(application); |
| 74 | 0 | } |
| 75 | |
|
| 76 | |
public void addFactoryElement(FactoryElement factory) { |
| 77 | 0 | factories_.add(factory); |
| 78 | 0 | } |
| 79 | |
|
| 80 | |
public void addComponentElement(ComponentElement component) { |
| 81 | 0 | components_.put(component.getComponentType(), component); |
| 82 | 0 | } |
| 83 | |
|
| 84 | |
public void addConverterElement(ConverterElement converter) { |
| 85 | 0 | if (converter.getConverterId() != null) { |
| 86 | 0 | convertersByIds_.put(converter.getConverterId(), converter); |
| 87 | 0 | } else if (converter.getConverterForClass() != null) { |
| 88 | 0 | convertersByClasses_.put(converter.getConverterForClass(), |
| 89 | |
converter); |
| 90 | |
} |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
public void addManagedBeanElement(ManagedBeanElement managedBean) { |
| 94 | 0 | managedBeans_.put(managedBean.getManagedBeanName(), managedBean); |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
public void addNavigationRuleElement(NavigationRuleElement navigationRule) { |
| 98 | 0 | navigationRules_.add(navigationRule); |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
public void addRenderKitElement(RenderKitElement renderKit) { |
| 102 | 0 | renderKits_.put(renderKit.getRenderKitId(), renderKit); |
| 103 | 0 | } |
| 104 | |
|
| 105 | |
public void addLifecycleElement(LifecycleElement lifecycle) { |
| 106 | 0 | lifecycles_.add(lifecycle); |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
public void addValidatorElement(ValidatorElement validator) { |
| 110 | 0 | validators_.put(validator.getValidatorId(), validator); |
| 111 | 0 | } |
| 112 | |
|
| 113 | |
public void addReferencedBeanElement(ReferencedBeanElement referencedBean) { |
| 114 | 0 | referencedBeans_.add(referencedBean); |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
public List getApplicationElements() { |
| 118 | 1 | return applications_; |
| 119 | |
} |
| 120 | |
|
| 121 | |
public List getFactoryElements() { |
| 122 | 2 | return factories_; |
| 123 | |
} |
| 124 | |
|
| 125 | |
public List getLifecycleElements() { |
| 126 | 0 | return lifecycles_; |
| 127 | |
} |
| 128 | |
|
| 129 | |
public Map getComponentElements() { |
| 130 | 1 | return components_; |
| 131 | |
} |
| 132 | |
|
| 133 | |
public Map getManagedBeanElements() { |
| 134 | 0 | return managedBeans_; |
| 135 | |
} |
| 136 | |
|
| 137 | |
public List getNavigationRuleElements() { |
| 138 | 0 | return navigationRules_; |
| 139 | |
} |
| 140 | |
|
| 141 | |
public Map getRenderKitElements() { |
| 142 | 3 | return renderKits_; |
| 143 | |
} |
| 144 | |
|
| 145 | |
public Map getValidatorElements() { |
| 146 | 1 | return validators_; |
| 147 | |
} |
| 148 | |
|
| 149 | |
public Map getConverterElementsById() { |
| 150 | 1 | return convertersByIds_; |
| 151 | |
} |
| 152 | |
|
| 153 | |
public Map getConverterElementsByClass() { |
| 154 | 1 | return convertersByClasses_; |
| 155 | |
} |
| 156 | |
|
| 157 | |
public List getReferencedBeanElements() { |
| 158 | 1 | return referencedBeans_; |
| 159 | |
} |
| 160 | |
|
| 161 | |
private void deployAllFacesConfig(List facesConfigs) { |
| 162 | 6 | for (Iterator itr = facesConfigs.iterator(); itr.hasNext();) { |
| 163 | 8 | Object o = itr.next(); |
| 164 | 8 | if (o instanceof FacesConfig) { |
| 165 | 8 | FacesConfig config = (FacesConfig) o; |
| 166 | 8 | deployFacesConfig(config); |
| 167 | |
} |
| 168 | |
} |
| 169 | 6 | } |
| 170 | |
|
| 171 | |
private void deployFacesConfig(FacesConfig facesConfig) { |
| 172 | 8 | factories_.addAll(facesConfig.getFactoryElements()); |
| 173 | 8 | applications_.addAll(facesConfig.getApplicationElements()); |
| 174 | 8 | lifecycles_.addAll(facesConfig.getLifecycleElements()); |
| 175 | 8 | referencedBeans_.addAll(facesConfig.getReferencedBeanElements()); |
| 176 | 8 | components_.putAll(facesConfig.getComponentElements()); |
| 177 | 8 | convertersByIds_.putAll(facesConfig.getConverterElementsById()); |
| 178 | 8 | convertersByClasses_.putAll(facesConfig.getConverterElementsByClass()); |
| 179 | 8 | managedBeans_.putAll(facesConfig.getManagedBeanElements()); |
| 180 | 8 | navigationRules_.addAll(facesConfig.getNavigationRuleElements()); |
| 181 | 8 | deployRenderKitElements(facesConfig.getRenderKitElements()); |
| 182 | 8 | validators_.putAll(facesConfig.getValidatorElements()); |
| 183 | 8 | } |
| 184 | |
|
| 185 | |
private void deployRenderKitElements(Map renderKitElements) { |
| 186 | 8 | for (Iterator it = renderKitElements.entrySet().iterator(); it |
| 187 | 12 | .hasNext();) { |
| 188 | 4 | Map.Entry entry = (Entry) it.next(); |
| 189 | 4 | String renderKitId = (String) entry.getKey(); |
| 190 | 4 | RenderKitElement renderKitElement = (RenderKitElement) entry |
| 191 | |
.getValue(); |
| 192 | 4 | RenderKitElement earlier = (RenderKitElement) renderKits_ |
| 193 | |
.get(renderKitId); |
| 194 | 4 | if (earlier != null) { |
| 195 | 1 | mergeRenderKitElement(earlier, renderKitElement); |
| 196 | |
} else { |
| 197 | 3 | renderKits_.put(renderKitId, renderKitElement); |
| 198 | |
} |
| 199 | |
} |
| 200 | 8 | } |
| 201 | |
|
| 202 | |
private void mergeRenderKitElement(RenderKitElement earlier, |
| 203 | |
RenderKitElement renderKitElement) { |
| 204 | 1 | String renderKitClass = renderKitElement.getRenderKitClass(); |
| 205 | 1 | if (renderKitClass != null) { |
| 206 | 1 | earlier.setRenderKitClass(renderKitClass); |
| 207 | |
} |
| 208 | 1 | for (Iterator it = renderKitElement.getRendererElements().iterator(); it |
| 209 | 2 | .hasNext();) { |
| 210 | 1 | RendererElement rendererElement = (RendererElement) it.next(); |
| 211 | 1 | earlier.addRendererElement(rendererElement); |
| 212 | |
} |
| 213 | 1 | } |
| 214 | |
|
| 215 | |
} |