KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > forms > support > MapOrBeanWrapper


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.forms.support;
25
26 import java.util.Map JavaDoc;
27
28 import org.riotfamily.common.beans.MapWrapper;
29 import org.riotfamily.common.beans.ObjectWrapper;
30 import org.riotfamily.common.beans.ProtectedBeanWrapper;
31 import org.springframework.beans.BeansException;
32 import org.springframework.beans.PropertyValue;
33 import org.springframework.beans.PropertyValues;
34
35 public class MapOrBeanWrapper implements ObjectWrapper {
36
37     private ObjectWrapper wrapper;
38
39     public MapOrBeanWrapper(Class JavaDoc objectClass) {
40         if (Map JavaDoc.class.isAssignableFrom(objectClass)) {
41             wrapper = new MapWrapper(objectClass);
42         }
43         else {
44             wrapper = new ProtectedBeanWrapper(objectClass);
45         }
46     }
47
48     /**
49      * @since 6.4
50      */

51     public MapOrBeanWrapper(Object JavaDoc object) {
52         if (object instanceof Map JavaDoc) {
53             wrapper = new MapWrapper((Map JavaDoc) object);
54         }
55         else {
56             wrapper = new ProtectedBeanWrapper(object);
57         }
58     }
59
60     public Class JavaDoc getPropertyType(String JavaDoc propertyName) throws BeansException {
61         return this.wrapper.getPropertyType(propertyName);
62     }
63
64     public Object JavaDoc getPropertyValue(String JavaDoc propertyName) throws BeansException {
65         return this.wrapper.getPropertyValue(propertyName);
66     }
67
68     public Class JavaDoc getObjectClass() {
69         return this.wrapper.getObjectClass();
70     }
71
72     public Object JavaDoc getObject() {
73         return this.wrapper.getObject();
74     }
75
76     public boolean isReadableProperty(String JavaDoc propertyName) throws BeansException {
77         return this.wrapper.isReadableProperty(propertyName);
78     }
79
80     public boolean isWritableProperty(String JavaDoc propertyName) throws BeansException {
81         return this.wrapper.isWritableProperty(propertyName);
82     }
83
84     public void setPropertyValue(PropertyValue pv) throws BeansException {
85         this.wrapper.setPropertyValue(pv);
86     }
87
88     public void setPropertyValue(String JavaDoc propertyName, Object JavaDoc value) throws BeansException {
89         this.wrapper.setPropertyValue(propertyName, value);
90     }
91
92     public void setPropertyValues(Map JavaDoc map) throws BeansException {
93         this.wrapper.setPropertyValues(map);
94     }
95
96     public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown, boolean ignoreInvalid) throws BeansException {
97         this.wrapper.setPropertyValues(pvs, ignoreUnknown, ignoreInvalid);
98     }
99
100     public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown) throws BeansException {
101         this.wrapper.setPropertyValues(pvs, ignoreUnknown);
102     }
103
104     public void setPropertyValues(PropertyValues pvs) throws BeansException {
105         this.wrapper.setPropertyValues(pvs);
106     }
107
108     public void setObject(Object JavaDoc object) {
109         this.wrapper.setObject(object);
110     }
111
112 }
113
Popular Tags