use of org.springframework.beans.factory.config.RuntimeBeanReference in project hudson-2.x by hudson.
the class BeanBuilder method methodMissing.
/**
* This method is invoked by Groovy when a method that's not defined in Java is invoked.
* We use that as a syntax for bean definition.
*/
public Object methodMissing(String name, Object arg) {
Object[] args = (Object[]) arg;
if (args.length == 0)
throw new MissingMethodException(name, getClass(), args);
if (args[0] instanceof Closure) {
// abstract bean definition
return invokeBeanDefiningMethod(name, args);
} else if (args[0] instanceof Class || args[0] instanceof RuntimeBeanReference || args[0] instanceof Map) {
return invokeBeanDefiningMethod(name, args);
} else if (args.length > 1 && args[args.length - 1] instanceof Closure) {
return invokeBeanDefiningMethod(name, args);
}
WebApplicationContext ctx = springConfig.getUnrefreshedApplicationContext();
MetaClass mc = DefaultGroovyMethods.getMetaClass(ctx);
if (!mc.respondsTo(ctx, name, args).isEmpty()) {
return mc.invokeMethod(ctx, name, args);
}
return this;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project motan by weibocom.
the class MotanBeanDefinitionParser method parseProperties.
private static void parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) {
if (nodeList != null && nodeList.getLength() > 0) {
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
if ("property".equals(node.getNodeName()) || "property".equals(node.getLocalName())) {
String name = ((Element) node).getAttribute("name");
if (name != null && name.length() > 0) {
String value = ((Element) node).getAttribute("value");
String ref = ((Element) node).getAttribute("ref");
if (value != null && value.length() > 0) {
beanDefinition.getPropertyValues().addPropertyValue(name, value);
} else if (ref != null && ref.length() > 0) {
beanDefinition.getPropertyValues().addPropertyValue(name, new RuntimeBeanReference(ref));
} else {
throw new UnsupportedOperationException("Unsupported <property name=\"" + name + "\"> sub tag, Only supported <property name=\"" + name + "\" ref=\"...\" /> or <property name=\"" + name + "\" value=\"...\" />");
}
}
}
}
}
}
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class AnnotationDrivenBeanDefinitionParser method getConversionService.
private RuntimeBeanReference getConversionService(Element element, Object source, ParserContext parserContext) {
RuntimeBeanReference conversionServiceRef;
if (element.hasAttribute("conversion-service")) {
conversionServiceRef = new RuntimeBeanReference(element.getAttribute("conversion-service"));
} else {
RootBeanDefinition conversionDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
conversionDef.setSource(source);
conversionDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
String conversionName = parserContext.getReaderContext().registerWithGeneratedName(conversionDef);
parserContext.registerComponent(new BeanComponentDefinition(conversionDef, conversionName));
conversionServiceRef = new RuntimeBeanReference(conversionName);
}
return conversionServiceRef;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class AnnotationDrivenBeanDefinitionParser method extractBeanRefSubElements.
private ManagedList<BeanReference> extractBeanRefSubElements(Element parentElement, ParserContext parserContext) {
ManagedList<BeanReference> list = new ManagedList<>();
list.setSource(parserContext.extractSource(parentElement));
for (Element refElement : DomUtils.getChildElementsByTagName(parentElement, "ref")) {
BeanReference reference;
if (StringUtils.hasText("bean")) {
reference = new RuntimeBeanReference(refElement.getAttribute("bean"), false);
list.add(reference);
} else if (StringUtils.hasText("parent")) {
reference = new RuntimeBeanReference(refElement.getAttribute("parent"), true);
list.add(reference);
} else {
parserContext.getReaderContext().error("'bean' or 'parent' attribute is required for <ref> element", parserContext.extractSource(parentElement));
}
}
return list;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class ConfigBeanDefinitionParser method createAdviceDefinition.
/**
* Creates the RootBeanDefinition for a POJO advice bean. Also causes pointcut
* parsing to occur so that the pointcut may be associate with the advice bean.
* This same pointcut is also configured as the pointcut for the enclosing
* Advisor definition using the supplied MutablePropertyValues.
*/
private AbstractBeanDefinition createAdviceDefinition(Element adviceElement, ParserContext parserContext, String aspectName, int order, RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef, List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) {
RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement, parserContext));
adviceDefinition.setSource(parserContext.extractSource(adviceElement));
adviceDefinition.getPropertyValues().add(ASPECT_NAME_PROPERTY, aspectName);
adviceDefinition.getPropertyValues().add(DECLARATION_ORDER_PROPERTY, order);
if (adviceElement.hasAttribute(RETURNING)) {
adviceDefinition.getPropertyValues().add(RETURNING_PROPERTY, adviceElement.getAttribute(RETURNING));
}
if (adviceElement.hasAttribute(THROWING)) {
adviceDefinition.getPropertyValues().add(THROWING_PROPERTY, adviceElement.getAttribute(THROWING));
}
if (adviceElement.hasAttribute(ARG_NAMES)) {
adviceDefinition.getPropertyValues().add(ARG_NAMES_PROPERTY, adviceElement.getAttribute(ARG_NAMES));
}
ConstructorArgumentValues cav = adviceDefinition.getConstructorArgumentValues();
cav.addIndexedArgumentValue(METHOD_INDEX, methodDef);
Object pointcut = parsePointcutProperty(adviceElement, parserContext);
if (pointcut instanceof BeanDefinition) {
cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut);
beanDefinitions.add((BeanDefinition) pointcut);
} else if (pointcut instanceof String) {
RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut);
cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcutRef);
beanReferences.add(pointcutRef);
}
cav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef);
return adviceDefinition;
}
Aggregations