use of org.springframework.beans.factory.config.BeanDefinition in project apollo by ctripcorp.
the class BeanRegistrationUtil method registerBeanDefinitionIfNotExists.
public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, String beanName, Class<?> beanClass) {
if (registry.containsBeanDefinition(beanName)) {
return false;
}
String[] candidates = registry.getBeanDefinitionNames();
for (String candidate : candidates) {
BeanDefinition beanDefinition = registry.getBeanDefinition(candidate);
if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) {
return false;
}
}
BeanDefinition annotationProcessor = BeanDefinitionBuilder.genericBeanDefinition(beanClass).getBeanDefinition();
registry.registerBeanDefinition(beanName, annotationProcessor);
return true;
}
use of org.springframework.beans.factory.config.BeanDefinition in project opennms by OpenNMS.
the class JaxbUtils method getClassForElement.
public static Class<?> getClassForElement(final String elementName) {
if (elementName == null)
return null;
final Class<?> existing = m_elementClasses.get(elementName);
if (existing != null)
return existing;
final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(XmlRootElement.class));
for (final BeanDefinition bd : scanner.findCandidateComponents("org.opennms")) {
final String className = bd.getBeanClassName();
try {
final Class<?> clazz = Class.forName(className);
final XmlRootElement annotation = clazz.getAnnotation(XmlRootElement.class);
if (annotation == null) {
LOG.warn("Somehow found class {} but it has no @XmlRootElement annotation! Skipping.", className);
continue;
}
if (elementName.equalsIgnoreCase(annotation.name())) {
LOG.trace("Found class {} for element name {}", className, elementName);
m_elementClasses.put(elementName, clazz);
return clazz;
}
} catch (final ClassNotFoundException e) {
LOG.warn("Unable to get class object from class name {}. Skipping.", className, e);
}
}
return null;
}
use of org.springframework.beans.factory.config.BeanDefinition in project opennms by OpenNMS.
the class Upgrade method getUpgradeObjects.
/**
* Gets the upgrade objects.
*
* @return the upgrade objects
* @throws OnmsUpgradeException the OpenNMS upgrade exception
*/
protected List<OnmsUpgrade> getUpgradeObjects() throws OnmsUpgradeException {
List<OnmsUpgrade> upgrades = new ArrayList<>();
try {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
provider.addIncludeFilter(new AssignableTypeFilter(OnmsUpgrade.class));
Set<BeanDefinition> components = provider.findCandidateComponents(getClassScope());
for (BeanDefinition component : components) {
if (component.isAbstract()) {
continue;
}
Class<?> cls = Class.forName(component.getBeanClassName());
if (cls.getAnnotation(Ignore.class) != null) {
continue;
}
OnmsUpgrade upgrade = (OnmsUpgrade) cls.newInstance();
upgrades.add(upgrade);
log("Found upgrade task %s\n", upgrade.getId());
}
Collections.sort(upgrades, new OnmsUpgradeComparator());
} catch (Exception e) {
throw new OnmsUpgradeException(" Can't find the upgrade classes because: " + e.getMessage(), e);
}
return upgrades;
}
use of org.springframework.beans.factory.config.BeanDefinition in project dubbo by alibaba.
the class DubboBeanDefinitionParser method parseMethods.
@SuppressWarnings("unchecked")
private static void parseMethods(String id, NodeList nodeList, RootBeanDefinition beanDefinition, ParserContext parserContext) {
if (nodeList != null && nodeList.getLength() > 0) {
ManagedList methods = null;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
Element element = (Element) node;
if ("method".equals(node.getNodeName()) || "method".equals(node.getLocalName())) {
String methodName = element.getAttribute("name");
if (methodName == null || methodName.length() == 0) {
throw new IllegalStateException("<dubbo:method> name attribute == null");
}
if (methods == null) {
methods = new ManagedList();
}
BeanDefinition methodBeanDefinition = parse(((Element) node), parserContext, MethodConfig.class, false);
String name = id + "." + methodName;
BeanDefinitionHolder methodBeanDefinitionHolder = new BeanDefinitionHolder(methodBeanDefinition, name);
methods.add(methodBeanDefinitionHolder);
}
}
}
if (methods != null) {
beanDefinition.getPropertyValues().addPropertyValue("methods", methods);
}
}
}
use of org.springframework.beans.factory.config.BeanDefinition in project dubbo by alibaba.
the class DubboBeanDefinitionParser method parseArguments.
@SuppressWarnings("unchecked")
private static void parseArguments(String id, NodeList nodeList, RootBeanDefinition beanDefinition, ParserContext parserContext) {
if (nodeList != null && nodeList.getLength() > 0) {
ManagedList arguments = null;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
Element element = (Element) node;
if ("argument".equals(node.getNodeName()) || "argument".equals(node.getLocalName())) {
String argumentIndex = element.getAttribute("index");
if (arguments == null) {
arguments = new ManagedList();
}
BeanDefinition argumentBeanDefinition = parse(((Element) node), parserContext, ArgumentConfig.class, false);
String name = id + "." + argumentIndex;
BeanDefinitionHolder argumentBeanDefinitionHolder = new BeanDefinitionHolder(argumentBeanDefinition, name);
arguments.add(argumentBeanDefinitionHolder);
}
}
}
if (arguments != null) {
beanDefinition.getPropertyValues().addPropertyValue("arguments", arguments);
}
}
}
Aggregations