01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/utils/mvc/impl/MixedBeanWrapper.java $
03: * $Id: MixedBeanWrapper.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.metaobj.utils.mvc.impl;
21:
22: import org.springframework.beans.BeanWrapperImpl;
23: import org.springframework.beans.BeansException;
24: import org.springframework.beans.NotWritablePropertyException;
25:
26: import java.util.Map;
27:
28: /**
29: * Created by IntelliJ IDEA.
30: * User: John Ellis
31: * Date: Apr 23, 2004
32: * Time: 3:14:04 PM
33: * To change this template use File | Settings | File Templates.
34: */
35: public class MixedBeanWrapper extends BeanWrapperBase {
36: public MixedBeanWrapper() {
37: }
38:
39: /**
40: * Create new BeanWrapperImpl for the given object.
41: *
42: * @param object object wrapped by this BeanWrapper.
43: * @throws org.springframework.beans.BeansException
44: * if the object cannot be wrapped by a BeanWrapper
45: */
46: public MixedBeanWrapper(Object object) throws BeansException {
47: super (object);
48: }
49:
50: /**
51: * Create new BeanWrapperImpl for the given object,
52: * registering a nested path that the object is in.
53: *
54: * @param object object wrapped by this BeanWrapper.
55: * @param nestedPath the nested path of the object
56: * @param rootObject the root object at the top of the path
57: * @throws org.springframework.beans.BeansException
58: * if the object cannot be wrapped by a BeanWrapper
59: */
60: public MixedBeanWrapper(Object object, String nestedPath,
61: Object rootObject) throws BeansException {
62: super (object, nestedPath, rootObject);
63: }
64:
65: protected BeanWrapperImpl createNestedWrapper(String parentPath,
66: String nestedProperty) {
67: Class type = getPropertyType(nestedProperty);
68:
69: if (type == null) {
70: throw new NotWritablePropertyException(String.class,
71: nestedProperty);
72: }
73:
74: if (java.util.Map.class.isAssignableFrom(type)) {
75: return new MapWrapper(
76: (Map) getPropertyValue(nestedProperty), parentPath
77: + NESTED_PROPERTY_SEPARATOR
78: + nestedProperty, getWrappedInstance());
79: } else {
80: return super
81: .createNestedWrapper(parentPath, nestedProperty);
82: }
83: }
84:
85: protected BeanWrapperBase constructWrapper(Object propertyValue,
86: String nestedProperty) {
87: return new MixedBeanWrapper(propertyValue, nestedProperty,
88: getWrappedInstance());
89: }
90:
91: }
|