Java Reference
In-Depth Information
40. public NumberFormat getNumberFormat(){
41. return currency.getNumberFormat();
42. }
43. public String getPhonePrefix(){
44. return PhoneNumber.getSelectedInterPrefix();
45. }
46. public String getProperty(String key){
47. return propertyFile.getProperty(key);
48. }
49. public String getProperty(String key, String defaultValue){
50. return propertyFile.getProperty(key, defaultValue);
51. }
52. }
Note that the InternationalizationWizard has a number of get methods, which it delegates to its associated
objects. It also has a method setNation , used to change the nation used by the client.
Although the Facade manages the internationalized settings for a number of objects in this example, it is still
possible to manage each object individually. This is one of the benefits of this pattern—it allows a group of
objects to be managed collectively in some situations, but still provides the freedom to individually manage the
components as well.
Calling the setNation method in this class sets the current nation. That makes the wizard alter the Currency
setting, the PhoneNumber , and a set of localized language strings, InternationalizedText .
Example 3.21 Currency.java
1. import java.text.NumberFormat;
2. public class Currency{
3. private char currencySymbol;
4. private NumberFormat numberFormat;
5.
6. public void setCurrencySymbol(char newCurrencySymbol){ currencySymbol =
newCurrencySymbol; }
7. public void setNumberFormat(NumberFormat newNumberFormat){ numberFormat =
newNumberFormat; }
8.
9. public char getCurrencySymbol(){ return currencySymbol; }
10. public NumberFormat getNumberFormat(){ return numberFormat; }
11. }
Example 3.22 InternationalizedText.java
1. import java.util.Properties;
2. import java.io.File;
3. import java.io.IOException;
4. import java.io.FileInputStream;
5. public class InternationalizedText{
6. private static final String DEFAULT_FILE_NAME = "";
7. private Properties textProperties = new Properties();
8.
9. public InternationalizedText(){
10. this(DEFAULT_FILE_NAME);
11. }
12. public InternationalizedText(String fileName){
13. loadProperties(fileName);
14. }
15.
16. public void setFileName(String newFileName){
17. if (newFileName != null){
18. loadProperties(newFileName);
19. }
20. }
21. public String getProperty(String key){
22. return getProperty(key, "");
23. }
24. public String getProperty(String key, String defaultValue){
25. return textProperties.getProperty(key, defaultValue);
26. }
27.
28. private void loadProperties(String fileName){
29. try{
30. FileInputStream input = new FileInputStream(fileName);
31. textProperties.load(input);
32. }
33. catch (IOException exc){
Search WWH ::




Custom Search