com.gwtplatform.dispatch.server.spring.SpringBeanProvider Maven / Gradle / Ivy
/**
* Copyright 2011 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.gwtplatform.dispatch.server.spring;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.context.ApplicationContext;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorLinkerHelper.BeanProvider;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorLinkerHelper.CommonBindingDescriptor;
import com.gwtplatform.dispatch.server.spring.utils.SpringUtils;
/**
* @author Peter Simun
*/
public class SpringBeanProvider implements BeanProvider {
/**
* Adapter for tranforming Guice Binding into BeanProvider implementation.
*
* @author Peter Simun ([email protected])
*/
public static class SpringBindingDescriptorAdapter extends CommonBindingDescriptor {
public SpringBindingDescriptorAdapter(Entry binding) {
super(binding.getValue(), binding.getKey());
}
}
private ApplicationContext applicationContext;
public SpringBeanProvider(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Override
public B getInstance(Class clazz) {
return SpringUtils.getInstance(applicationContext, clazz);
}
@Override
public Iterator> getBindings(Class clazz) {
List> result = new ArrayList>();
Map beansOfType = applicationContext.getBeansOfType(clazz);
for (Entry beans : beansOfType.entrySet()) {
result.add(new SpringBindingDescriptorAdapter(beans));
}
return result.iterator();
}
}