1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.morph.lang.languages;
17
18 import net.sf.morph.Defaults;
19 import net.sf.morph.lang.DecoratedLanguage;
20 import net.sf.morph.lang.Language;
21 import net.sf.morph.lang.LanguageException;
22
23 /**
24 * Decorates any language so that it implements
25 * {@link net.sf.morph.lang.DecoratedLanguage}.
26 *
27 * @author Matt Sgarlata
28 * @since Nov 28, 2004
29 */
30 public class LanguageDecorator extends BaseLanguage implements DecoratedLanguage {
31
32 private Language language;
33
34 /**
35 * Create a new LanguageDecorator.
36 */
37 public LanguageDecorator() {
38 super();
39 }
40
41 /**
42 * Create a new LanguageDecorator.
43 * @param language to decorate
44 */
45 public LanguageDecorator(Language language) {
46 this();
47 this.language = language;
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 protected Object getImpl(Object target, String expression) throws LanguageException {
54 return getLanguage().get(target, expression);
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 protected Class getTypeImpl(Object target, String expression)
61 throws LanguageException {
62 return getLanguage().getType(target, expression);
63 }
64
65 /**
66 * {@inheritDoc}
67 */
68 protected void setImpl(Object target, String expression, Object value)
69 throws Exception {
70 getLanguage().set(target, expression, value);
71 }
72
73 /**
74 * {@inheritDoc}
75 */
76 protected boolean isPropertyImpl(String expression) {
77 return getLanguage().isProperty(expression);
78 }
79
80 /**
81 * Get the decorated language.
82 * @return Language
83 */
84 public Language getLanguage() {
85 if (language == null) {
86 setLanguage(Defaults.createLanguage());
87 }
88 return language;
89 }
90
91 /**
92 * Set the decorated language.
93 * @param language to set
94 */
95 public void setLanguage(Language language) {
96 this.language = language;
97 }
98
99 }