2 * Copyright 2004-2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.codehaus
.groovy
.grails
.web
.metaclass
;
18 import groovy
.lang
.MissingPropertyException
;
19 import org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.codehaus
.groovy
.grails
.commons
.metaclass
.AbstractDynamicProperty
;
22 import org
.codehaus
.groovy
.grails
.web
.binding
.DataBindingUtils
;
23 import org
.codehaus
.groovy
.runtime
.DefaultGroovyMethods
;
24 import org
.springframework
.beans
.SimpleTypeConverter
;
25 import org
.springframework
.beans
.TypeConverter
;
26 import org
.springframework
.validation
.BindingResult
;
29 * A dynamic property that uses a Map of OGNL expressions to sets properties on the target object
31 * @author Graeme Rocher
34 public class SetPropertiesDynamicProperty
extends AbstractDynamicProperty
{
36 private static final Log LOG
= LogFactory
.getLog( SetPropertiesDynamicProperty
.class );
38 private static final String PROPERTY_NAME
= "properties";
39 private TypeConverter converter
= new SimpleTypeConverter();
41 public SetPropertiesDynamicProperty() {
46 * @return A org.apache.commons.beanutils.BeanMap instance
48 public Object
get(Object object
) {
49 return DefaultGroovyMethods
.getProperties(object
);
53 * Sets the property on the specified object with the specified value. The
54 * value is expected to be a Map containing OGNL expressions for the keys
55 * and objects for the values.
57 * @param object The target object
58 * @param newValue The value to set
60 public void set(Object object
, Object newValue
) {
64 BindingResult result
= DataBindingUtils
.bindObjectToInstance(object
, newValue
);
66 throw new MissingPropertyException(PROPERTY_NAME
,object
.getClass());