01: /**********************************************************************************
02: * $URL$
03: * $Id$
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.tool.assessment.integration.context.spring;
21:
22: import java.io.File;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.springframework.beans.factory.BeanFactory;
27: import org.springframework.beans.factory.xml.XmlBeanFactory;
28: import org.springframework.core.io.ClassPathResource;
29: import org.springframework.core.io.Resource;
30:
31: import org.sakaiproject.tool.assessment.integration.context.IntegrationContextFactory;
32: import org.sakaiproject.spring.SpringBeanLocator;
33:
34: /**
35: * Encapsulates the Spring lookup for this factory.
36: * @author Ed smiley
37: */
38: public class FactoryUtil {
39: private static Log log = LogFactory.getLog(FactoryUtil.class);
40: private static boolean useLocator = false;
41: // private static boolean useLocator = true;
42:
43: private static final String FS = File.separator;
44: private static final String CONFIGURATION = "org" + FS
45: + "sakaiproject" + FS + "spring" + FS
46: + "integrationContext.xml";
47:
48: public static IntegrationContextFactory lookup() throws Exception {
49: // the instance is provided by Spring-injection
50: if (useLocator) {
51:
52: SpringBeanLocator locator = SpringBeanLocator.getInstance();
53: return (IntegrationContextFactory) locator
54: .getBean("integrationContextFactory");
55: } else // unit testing
56: {
57: Resource res = new ClassPathResource(CONFIGURATION);
58: BeanFactory factory = new XmlBeanFactory(res);
59: return (IntegrationContextFactory) factory
60: .getBean("integrationContextFactory");
61: }
62:
63: }
64:
65: public static boolean getUseLocator() {
66: return useLocator;
67: }
68:
69: public static void setUseLocator(boolean use) {
70: useLocator = use;
71: }
72:
73: }
|