GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / src / commons / org / codehaus / groovy / grails / commons / GrailsResourceLoaderFactoryBean.java
blob8aa5dc981714452881594d6e448c74dec87bcbb6
1 /* Copyright 2006-2007 Graeme Rocher
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.commons;
17 import org.codehaus.groovy.grails.compiler.support.GrailsResourceLoaderHolder;
18 import org.codehaus.groovy.grails.compiler.support.GrailsResourceLoader;
19 import org.springframework.beans.factory.FactoryBean;
20 import org.springframework.beans.factory.InitializingBean;
21 import org.springframework.util.Assert;
23 /**
24 * A factory bean that constructs the Grails ResourceLoader used to load Grails classes
26 * @author Graeme Rocher
27 * @since 0.4
28 * <p/>
29 * Created: Jul 27, 2007
30 * Time: 12:34:33 PM
32 public class GrailsResourceLoaderFactoryBean implements FactoryBean, InitializingBean {
34 private org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder grailsResourceHolder;
35 private GrailsResourceLoader resourceLoader;
37 public void setGrailsResourceHolder(org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder grailsResourceHolder) {
38 this.grailsResourceHolder = grailsResourceHolder;
41 public Object getObject() throws Exception {
42 return this.resourceLoader;
45 public Class getObjectType() {
46 return GrailsResourceLoader.class;
49 public boolean isSingleton() {
50 return true;
53 public void afterPropertiesSet() throws Exception {
54 Assert.notNull(grailsResourceHolder, "Property [grailsResourceHolder] must be set!");
56 this.resourceLoader = GrailsResourceLoaderHolder.getResourceLoader();
57 if(resourceLoader == null) {
58 this.resourceLoader = new GrailsResourceLoader(grailsResourceHolder.getResources());
59 GrailsResourceLoaderHolder.setResourceLoader(this.resourceLoader);