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.api.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: import org.sakaiproject.tool.assessment.api.SamigoApiFactory;
34:
35: public class FactoryUtil {
36: private static Log log = LogFactory.getLog(FactoryUtil.class);
37: private static boolean useLocator = false;
38: // private static boolean useLocator = true;
39:
40: private static final String FS = File.separator;
41: private static final String CONFIGURATION = "org" + FS
42: + "sakaiproject" + FS + "spring" + FS + "samigoApi.xml";
43:
44: public static SamigoApiFactory lookup() throws Exception {
45: // the instance is provided by Spring-injection
46: if (useLocator) {
47:
48: SpringBeanLocator locator = SpringBeanLocator.getInstance();
49: return (SamigoApiFactory) locator
50: .getBean("samigoApiFactory");
51: } else // unit testing
52: {
53: Resource res = new ClassPathResource(CONFIGURATION);
54: BeanFactory factory = new XmlBeanFactory(res);
55: return (SamigoApiFactory) factory
56: .getBean("samigoApiFactory");
57: }
58:
59: }
60:
61: public static boolean getUseLocator() {
62: return useLocator;
63: }
64:
65: public static void setUseLocator(boolean use) {
66: useLocator = use;
67: }
68:
69: }
|