| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.mock; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.Collection; |
| 20 | |
import java.util.Collections; |
| 21 | |
import java.util.HashMap; |
| 22 | |
import java.util.Iterator; |
| 23 | |
import java.util.Locale; |
| 24 | |
import java.util.Map; |
| 25 | |
|
| 26 | |
import javax.faces.FacesException; |
| 27 | |
import javax.faces.application.NavigationHandler; |
| 28 | |
import javax.faces.application.StateManager; |
| 29 | |
import javax.faces.application.ViewHandler; |
| 30 | |
import javax.faces.component.UIComponent; |
| 31 | |
import javax.faces.context.FacesContext; |
| 32 | |
import javax.faces.convert.Converter; |
| 33 | |
import javax.faces.el.MethodBinding; |
| 34 | |
import javax.faces.el.PropertyResolver; |
| 35 | |
import javax.faces.el.ReferenceSyntaxException; |
| 36 | |
import javax.faces.el.ValueBinding; |
| 37 | |
import javax.faces.el.VariableResolver; |
| 38 | |
import javax.faces.event.ActionListener; |
| 39 | |
import javax.faces.validator.Validator; |
| 40 | |
|
| 41 | |
import org.seasar.framework.util.ClassUtil; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public class MockApplicationImpl extends MockApplication { |
| 47 | |
|
| 48 | |
private String bundle_; |
| 49 | |
|
| 50 | |
private ActionListener actionListener_; |
| 51 | |
|
| 52 | |
private Locale defaultLocale_; |
| 53 | |
|
| 54 | |
private Collection locales_; |
| 55 | |
|
| 56 | |
private VariableResolver variableResolver_; |
| 57 | |
|
| 58 | |
private PropertyResolver propertyResolver_; |
| 59 | |
|
| 60 | |
private NavigationHandler navigationHandler_; |
| 61 | |
|
| 62 | |
private ViewHandler viewHandler_; |
| 63 | |
|
| 64 | |
private StateManager stateManager_; |
| 65 | |
|
| 66 | |
private String defaultRenderKitId_; |
| 67 | |
|
| 68 | 3155 | private Map componentClassMap_ = new HashMap(); |
| 69 | |
|
| 70 | 3155 | private Map convertersById_ = new HashMap(); |
| 71 | |
|
| 72 | 3155 | private Map convertersByClass_ = new HashMap(); |
| 73 | |
|
| 74 | 3155 | private Map validators_ = new HashMap(); |
| 75 | |
|
| 76 | |
private ValueBinding vb_; |
| 77 | |
|
| 78 | 3155 | public MockApplicationImpl() { |
| 79 | 3155 | } |
| 80 | |
|
| 81 | |
public ActionListener getActionListener() { |
| 82 | 24 | return actionListener_; |
| 83 | |
} |
| 84 | |
|
| 85 | |
public void setActionListener(ActionListener actionListener) { |
| 86 | 18 | actionListener_ = actionListener; |
| 87 | 18 | } |
| 88 | |
|
| 89 | |
public Locale getDefaultLocale() { |
| 90 | 7 | return defaultLocale_; |
| 91 | |
} |
| 92 | |
|
| 93 | |
public void setDefaultLocale(Locale locale) { |
| 94 | 10 | defaultLocale_ = locale; |
| 95 | 10 | } |
| 96 | |
|
| 97 | |
public String getDefaultRenderKitId() { |
| 98 | 8 | return defaultRenderKitId_; |
| 99 | |
} |
| 100 | |
|
| 101 | |
public void setDefaultRenderKitId(String renderKitId) { |
| 102 | 6 | defaultRenderKitId_ = renderKitId; |
| 103 | 6 | } |
| 104 | |
|
| 105 | |
public String getMessageBundle() { |
| 106 | 103 | return bundle_; |
| 107 | |
} |
| 108 | |
|
| 109 | |
public void setMessageBundle(String bundle) { |
| 110 | 29 | bundle_ = bundle; |
| 111 | 29 | } |
| 112 | |
|
| 113 | |
public Iterator getSupportedLocales() { |
| 114 | 7 | return (locales_ != null) ? locales_.iterator() |
| 115 | |
: Collections.EMPTY_LIST.iterator(); |
| 116 | |
} |
| 117 | |
|
| 118 | |
public void setSupportedLocales(Collection locales) { |
| 119 | 5 | locales_ = locales; |
| 120 | 5 | } |
| 121 | |
|
| 122 | |
public NavigationHandler getNavigationHandler() { |
| 123 | 12 | return navigationHandler_; |
| 124 | |
} |
| 125 | |
|
| 126 | |
public void setNavigationHandler(NavigationHandler handler) { |
| 127 | 1345 | navigationHandler_ = handler; |
| 128 | 1345 | } |
| 129 | |
|
| 130 | |
public PropertyResolver getPropertyResolver() { |
| 131 | 62 | if (propertyResolver_ == null) { |
| 132 | 3 | propertyResolver_ = new MockPropertyResolver(); |
| 133 | |
} |
| 134 | 62 | return propertyResolver_; |
| 135 | |
} |
| 136 | |
|
| 137 | |
public void setPropertyResolver(PropertyResolver resolver) { |
| 138 | 1350 | propertyResolver_ = resolver; |
| 139 | 1350 | } |
| 140 | |
|
| 141 | |
public VariableResolver getVariableResolver() { |
| 142 | 115 | if (variableResolver_ == null) { |
| 143 | 9 | variableResolver_ = new MockVariableResolver(); |
| 144 | |
} |
| 145 | 115 | return variableResolver_; |
| 146 | |
} |
| 147 | |
|
| 148 | |
public void setVariableResolver(VariableResolver resolver) { |
| 149 | 1707 | variableResolver_ = resolver; |
| 150 | 1707 | } |
| 151 | |
|
| 152 | |
public ViewHandler getViewHandler() { |
| 153 | 64 | if (viewHandler_ == null) { |
| 154 | 21 | viewHandler_ = new MockViewHandlerImpl(); |
| 155 | |
} |
| 156 | 64 | return viewHandler_; |
| 157 | |
} |
| 158 | |
|
| 159 | |
public void setViewHandler(ViewHandler handler) { |
| 160 | 1354 | viewHandler_ = handler; |
| 161 | 1354 | } |
| 162 | |
|
| 163 | |
public StateManager getStateManager() { |
| 164 | 29 | return stateManager_; |
| 165 | |
} |
| 166 | |
|
| 167 | |
public void setStateManager(StateManager manager) { |
| 168 | 1345 | stateManager_ = manager; |
| 169 | 1345 | } |
| 170 | |
|
| 171 | |
public void addComponent(String componentType, String componentClassName) { |
| 172 | 4 | Class clazz = ClassUtil.forName(componentClassName); |
| 173 | 4 | componentClassMap_.put(componentType, clazz); |
| 174 | 4 | } |
| 175 | |
|
| 176 | |
public UIComponent createComponent(String componentType) |
| 177 | |
throws FacesException { |
| 178 | 3 | Class componentClass = (Class) componentClassMap_.get(componentType); |
| 179 | 3 | if (componentClass == null) { |
| 180 | 0 | throw new FacesException(); |
| 181 | |
} |
| 182 | 3 | return (UIComponent) ClassUtil.newInstance(componentClass); |
| 183 | |
} |
| 184 | |
|
| 185 | |
public UIComponent createComponent(ValueBinding vb, FacesContext context, |
| 186 | |
String componentType) throws FacesException { |
| 187 | 0 | Object obj = vb.getValue(context); |
| 188 | 0 | if (obj instanceof UIComponent) { |
| 189 | 0 | return (UIComponent) obj; |
| 190 | |
} else { |
| 191 | 0 | UIComponent component = createComponent(componentType); |
| 192 | 0 | vb.setValue(context, component); |
| 193 | 0 | return component; |
| 194 | |
} |
| 195 | |
} |
| 196 | |
|
| 197 | |
public void addConverter(String converterId, String converterClass) { |
| 198 | 22 | if (converterId == null || converterClass == null) { |
| 199 | 0 | throw new IllegalArgumentException(); |
| 200 | |
} |
| 201 | 22 | convertersById_.put(converterId, converterClass); |
| 202 | 22 | } |
| 203 | |
|
| 204 | |
public void addConverter(Class targetClass, String converterClass) { |
| 205 | 4 | if (targetClass == null || converterClass == null) { |
| 206 | 0 | throw new IllegalArgumentException(); |
| 207 | |
} |
| 208 | 4 | convertersByClass_.put(targetClass, converterClass); |
| 209 | 4 | } |
| 210 | |
|
| 211 | |
public Converter createConverter(String converterId) { |
| 212 | 22 | Converter converter = null; |
| 213 | 22 | if (convertersById_.containsKey(converterId)) { |
| 214 | 21 | String className = (String) convertersById_.get(converterId); |
| 215 | 21 | converter = (Converter) ClassUtil.newInstance(className); |
| 216 | |
} |
| 217 | 22 | return converter; |
| 218 | |
} |
| 219 | |
|
| 220 | |
public Converter createConverter(Class targetClass) { |
| 221 | 3 | Converter converter = null; |
| 222 | 3 | if (convertersByClass_.containsKey(targetClass)) { |
| 223 | 3 | String className = (String) convertersByClass_.get(targetClass); |
| 224 | 3 | converter = (Converter) ClassUtil.newInstance(className); |
| 225 | |
} |
| 226 | 3 | return converter; |
| 227 | |
} |
| 228 | |
|
| 229 | |
public void addValidator(String validatorId, String validatorClass) { |
| 230 | 30 | validators_.put(validatorId, validatorClass); |
| 231 | 30 | } |
| 232 | |
|
| 233 | |
public Validator createValidator(String validatorId) throws FacesException { |
| 234 | 22 | String validatorClass = (String) validators_.get(validatorId); |
| 235 | 22 | Validator v = null; |
| 236 | 22 | if (validatorClass != null) { |
| 237 | 19 | v = (Validator) ClassUtil.newInstance(validatorClass); |
| 238 | |
} |
| 239 | 22 | return v; |
| 240 | |
} |
| 241 | |
|
| 242 | |
public Iterator getComponentTypes() { |
| 243 | 0 | return null; |
| 244 | |
} |
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
public Iterator getConverterIds() { |
| 251 | 0 | return null; |
| 252 | |
} |
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
public Iterator getConverterTypes() { |
| 259 | 0 | return null; |
| 260 | |
} |
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
public MethodBinding createMethodBinding(String ref, Class[] params) |
| 267 | |
throws ReferenceSyntaxException { |
| 268 | 26 | return new MockMethodBinding(ref); |
| 269 | |
} |
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
public Iterator getValidatorIds() { |
| 276 | 0 | return null; |
| 277 | |
} |
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
public ValueBinding createValueBinding(String ref) |
| 284 | |
throws ReferenceSyntaxException { |
| 285 | 20 | if (vb_ != null) { |
| 286 | 18 | return vb_; |
| 287 | |
} |
| 288 | |
|
| 289 | 2 | return new MockValueBinding(ref); |
| 290 | |
} |
| 291 | |
|
| 292 | |
public void addSupportedLocale(Locale locale) { |
| 293 | 2 | if (locales_ != null) { |
| 294 | 0 | locales_.add(locale); |
| 295 | |
} else { |
| 296 | 2 | locales_ = new ArrayList(); |
| 297 | 2 | locales_.add(locale); |
| 298 | |
} |
| 299 | 2 | } |
| 300 | |
|
| 301 | |
public void setValueBinding(ValueBinding vb) { |
| 302 | 18 | vb_ = vb; |
| 303 | 18 | } |
| 304 | |
|
| 305 | |
} |