com.ocpsoft.rewrite.cdi.CdiServiceLocator Maven / Gradle / Ivy
/*
* Copyright 2011 Lincoln Baxter, III
*
* 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.ocpsoft.rewrite.cdi;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.util.AnnotationLiteral;
import org.jboss.solder.beanManager.BeanManagerAware;
import com.ocpsoft.common.spi.ServiceLocator;
import com.ocpsoft.logging.Logger;
/**
* @author Lincoln Baxter, III
*
*/
public class CdiServiceLocator extends BeanManagerAware implements ServiceLocator
{
Logger log = Logger.getLogger(CdiServiceLocator.class);
@Override
@SuppressWarnings("unchecked")
public Collection> locate(final Class type)
{
List> result = new ArrayList>();
BeanManager manager = getBeanManager();
Set> beans = manager.getBeans(type, new Annotation[] { new AnnotationLiteral() {
private static final long serialVersionUID = -1896831901770051851L;
} });
for (Bean bean : beans) {
result.add((Class) bean.getBeanClass());
}
return result;
}
}