Skip to content

Commit

Permalink
Makes factory fully injectable
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Mar 10, 2017
1 parent 6b8272c commit da5da67
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,49 @@
public class TextProviderFactory {

private TextProvider textProvider;
private LocaleProvider localeProvider;

@Inject
public void setTextProvider(TextProvider textProvider) {
this.textProvider = textProvider;
}

public TextProvider createInstance(Class clazz, LocaleProvider provider) {
TextProvider instance = getTextProvider(clazz, provider);
@Inject
public void setLocaleProvider(LocaleProvider localeProvider) {
this.localeProvider = localeProvider;
}

public TextProvider createInstance(Class clazz) {
TextProvider instance = getTextProvider(clazz);
if (instance instanceof ResourceBundleTextProvider) {
((ResourceBundleTextProvider) instance).setClazz(clazz);
((ResourceBundleTextProvider) instance).setLocaleProvider(provider);
((ResourceBundleTextProvider) instance).setLocaleProvider(localeProvider);
}
return instance;
}

public TextProvider createInstance(ResourceBundle bundle, LocaleProvider provider) {
TextProvider instance = getTextProvider(bundle, provider);
public TextProvider createInstance(ResourceBundle bundle) {
TextProvider instance = getTextProvider(bundle);
if (instance instanceof ResourceBundleTextProvider) {
((ResourceBundleTextProvider) instance).setBundle(bundle);
((ResourceBundleTextProvider) instance).setLocaleProvider(provider);
((ResourceBundleTextProvider) instance).setLocaleProvider(localeProvider);
}
return instance;
}

protected TextProvider getTextProvider(Class clazz, LocaleProvider provider) {
protected TextProvider getTextProvider(Class clazz) {
if (this.textProvider == null) {
return new TextProviderSupport(clazz, provider);
return new TextProviderSupport(clazz, localeProvider);
} else {
return textProvider;
}
}

private TextProvider getTextProvider(ResourceBundle bundle, LocaleProvider provider) {
private TextProvider getTextProvider(ResourceBundle bundle) {
if (this.textProvider == null) {
return new TextProviderSupport(bundle, provider);
} else {
return textProvider;
textProvider = new TextProviderSupport(bundle, localeProvider);
}
return textProvider;
}

}

0 comments on commit da5da67

Please sign in to comment.