View Javadoc

1   /*
2    * Copyright 2004-2005, 2007-2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
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  }