01: /*
02: * $Id: BeanFactoryInJndiResourceLocator.java 911 2007-02-20 13:53:49Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.org).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.controller.spring;
15:
16: import org.concern.controller.ResourceLocator;
17:
18: import org.concern.controller.Controller;
19: import org.springframework.beans.factory.BeanFactory;
20:
21: import javax.naming.InitialContext;
22: import javax.naming.NamingException;
23:
24: public class BeanFactoryInJndiResourceLocator implements
25: ResourceLocator {
26: public BeanFactoryInJndiResourceLocator() {
27: }
28:
29: public Object lookup(String name) {
30: int pos = name.lastIndexOf('/');
31: String beanFactoryName = name.substring(0, pos);
32: String beanName = name.substring(pos + 1);
33:
34: try {
35: BeanFactory beanFactory = (BeanFactory) new InitialContext()
36: .lookup(beanFactoryName);
37: if ("this".equals(beanName) || beanName.length() == 0)
38: return beanFactory;
39: else
40: return beanFactory.getBean(beanName);
41: } catch (NamingException e) {
42: throw new RuntimeException(e);
43: }
44: }
45:
46: public void setController(Controller controller) {
47: }
48: }
|