1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.morph.context.contexts;
17
18 import net.sf.morph.Defaults;
19 import net.sf.morph.context.Context;
20 import net.sf.morph.context.ContextException;
21 import net.sf.morph.context.DecoratedContext;
22 import net.sf.morph.transform.Converter;
23
24 /**
25 * Decorates any context so that it implements
26 * {@link net.sf.morph.lang.DecoratedLanguage}.
27 *
28 * @author Matt Sgarlata
29 * @since Dec 5, 2004
30 */
31 public class ContextDecorator extends BaseContext implements Context, DecoratedContext {
32
33 private Converter converter;
34 private Context context;
35
36 public ContextDecorator() {
37 super();
38 this.converter = Defaults.createConverter();
39 }
40
41 public ContextDecorator(Context context) {
42 this();
43 this.context = context;
44 }
45
46 protected void checkInitialization() {
47
48 }
49
50 public String[] getPropertyNamesImpl() throws ContextException {
51 checkInitialization();
52 return context.getPropertyNames();
53 }
54
55 public Object getImpl(String propertyName) throws Exception {
56 return getLanguage().get(context, propertyName);
57 }
58
59 public void setImpl(String propertyName, Object propertyValue)
60 throws ContextException {
61 getLanguage().set(context, propertyName, propertyValue);
62 }
63
64 /**
65 * @return Returns the context.
66 */
67 public Context getContext() {
68 return context;
69 }
70 /**
71 * @param context The context to set.
72 */
73 public void setContext(Context context) {
74 this.context = context;
75 }
76 /**
77 * @return Returns the converter.
78 */
79 public Converter getConverter() {
80 if (converter == null) {
81 setConverter(Defaults.createConverter());
82 }
83 return converter;
84 }
85 /**
86 * @param converter The converter to set.
87 */
88 public void setConverter(Converter converter) {
89 this.converter = converter;
90 }
91
92 }