
org.ow2.bonita.pvm.internal.spring.SpringEnvironmentContext Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.ow2.bonita.pvm.internal.spring;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.ow2.bonita.pvm.env.Context;
import org.ow2.bonita.pvm.internal.util.ReflectUtil;
import org.springframework.context.ApplicationContext;
/**
* @author Tom Baeyens
*/
public class SpringEnvironmentContext implements Context {
// TODO pull up the common behaviour between this class and the
// SpringEnvironmentFactory
ApplicationContext applicationContext;
Map cache = new HashMap();
public SpringEnvironmentContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
public boolean has(String key) {
return applicationContext.isPrototype(key);
}
public Object get(String key) {
if (cache.containsKey(key)) {
return cache.get(key);
}
if (has(key)) {
Object bean = applicationContext.getBean(key);
// cache.put(key, bean);
return bean;
}
return null;
}
public T get(Class type) {
String name = ReflectUtil.getUnqualifiedClassName(type);
name = name.substring(0, 1).toLowerCase() + name.substring(1);
return (T) get(name);
}
public Set keys() {
HashSet keys = new HashSet();
for (String key : applicationContext.getBeanDefinitionNames()) {
if (has(key)) {
keys.add(key);
}
}
return keys;
}
public ApplicationContext getApplicationContext() {
return applicationContext;
}
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
public String getName() {
return null;
}
public Object set(String key, Object value) {
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy