1 /* Copyright 2004-2005 the original author or authors.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 package org
.codehaus
.groovy
.grails
.validation
.metaclass
;
17 import org
.codehaus
.groovy
.grails
.commons
.GrailsApplication
;
18 import org
.codehaus
.groovy
.grails
.commons
.GrailsDomainClass
;
19 import org
.codehaus
.groovy
.grails
.commons
.DomainClassArtefactHandler
;
20 import org
.codehaus
.groovy
.grails
.commons
.metaclass
.AbstractDynamicProperty
;
22 * This is a dynamic property that instead of returning the closure sets a new proxy meta class for the scope
23 * of the call and invokes the closure itself which builds up a list of ConstrainedProperty instances
25 * @author Graeme Rocher
28 public class ConstraintsDynamicProperty
extends AbstractDynamicProperty
{
29 public static final String PROPERTY_NAME
= "constraints";
31 private GrailsApplication application
;
33 public ConstraintsDynamicProperty(GrailsApplication application
) {
35 this.application
= application
;
38 public Object
get(Object object
) {
39 GrailsDomainClass domainClass
= (GrailsDomainClass
) application
.getArtefact(DomainClassArtefactHandler
.TYPE
,
40 object
.getClass().getName());
41 return domainClass
.getConstrainedProperties();
44 public void set(Object object
, Object newValue
) {
45 throw new UnsupportedOperationException("Cannot set read-only property ["+PROPERTY_NAME
+"]");