use of org.springframework.beans.factory.config.RuntimeBeanReference in project hudson-2.x by hudson.
the class BeanBuilder method manageListIfNecessary.
/**
* Checks whether there are any runtime refs inside the list and
* converts it to a ManagedList if necessary
*
* @param value The object that represents the list
* @return Either a new list or a managed one
*/
private Object manageListIfNecessary(Object value) {
List list = (List) value;
boolean containsRuntimeRefs = false;
for (ListIterator i = list.listIterator(); i.hasNext(); ) {
Object e = i.next();
if (e instanceof RuntimeBeanReference) {
containsRuntimeRefs = true;
}
if (e instanceof BeanConfiguration) {
BeanConfiguration c = (BeanConfiguration) e;
i.set(c.getBeanDefinition());
containsRuntimeRefs = true;
}
}
if (containsRuntimeRefs) {
List tmp = new ManagedList();
tmp.addAll((List) value);
value = tmp;
}
return value;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project grails-core by grails.
the class ChainedTransactionManagerPostProcessor method createTransactionManagerBeanReferences.
protected ManagedList<RuntimeBeanReference> createTransactionManagerBeanReferences(BeanDefinition chainedTransactionManagerBeanDefinition) {
ManagedList<RuntimeBeanReference> transactionManagerRefs = new ManagedList<RuntimeBeanReference>();
ConstructorArgumentValues constructorValues = chainedTransactionManagerBeanDefinition.getConstructorArgumentValues();
constructorValues.addIndexedArgumentValue(0, transactionManagerRefs);
transactionManagerRefs.add(new RuntimeBeanReference(PRIMARY_TRANSACTION_MANAGER));
return transactionManagerRefs;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project grails-core by grails.
the class BeanBuilder method manageMapIfNecessary.
/**
* Checks whether there are any runtime refs inside a Map and converts
* it to a ManagedMap if necessary.
*
* @param value The current map
* @return A ManagedMap or a normal map
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object manageMapIfNecessary(Object value) {
Map map = (Map) value;
boolean containsRuntimeRefs = false;
for (Object e : map.values()) {
if (e instanceof RuntimeBeanReference) {
containsRuntimeRefs = true;
break;
}
}
if (containsRuntimeRefs) {
Map managedMap = new ManagedMap();
managedMap.putAll(map);
return managedMap;
}
return value;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project grails-core by grails.
the class BeanBuilder method invokeMethod.
/**
* Overrides method invocation to create beans for each method name that takes a class argument.
*/
@Override
public Object invokeMethod(String name, Object arg) {
Object[] args = (Object[]) arg;
if (CREATE_APPCTX.equals(name)) {
return createApplicationContext();
}
if (REGISTER_BEANS.equals(name) && args.length == 1 && args[0] instanceof GenericApplicationContext) {
registerBeans((GenericApplicationContext) args[0]);
return null;
}
if (BEANS.equals(name) && args.length == 1 && args[0] instanceof Closure) {
return beans((Closure<?>) args[0]);
}
if (REF.equals(name)) {
String refName;
Assert.notNull(args[0], "Argument to ref() is not a valid bean or was not found");
if (args[0] instanceof RuntimeBeanReference) {
refName = ((RuntimeBeanReference) args[0]).getBeanName();
} else {
refName = args[0].toString();
}
boolean parentRef = false;
if (args.length > 1) {
if (args[1] instanceof Boolean) {
parentRef = (Boolean) args[1];
}
}
return new RuntimeBeanReference(refName, parentRef);
}
if (namespaceHandlers.containsKey(name) && args.length > 0 && (args[0] instanceof Closure)) {
createDynamicElementReader(name, true).invokeMethod("doCall", args);
return this;
}
if (args.length > 0 && args[0] instanceof Closure) {
// abstract bean definition
return invokeBeanDefiningMethod(name, args);
}
if (args.length > 0 && args[0] instanceof Class || args.length > 0 && args[0] instanceof RuntimeBeanReference || args.length > 0 && args[0] instanceof Map) {
return invokeBeanDefiningMethod(name, args);
}
if (args.length > 1 && args[args.length - 1] instanceof Closure) {
return invokeBeanDefiningMethod(name, args);
}
ApplicationContext 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 redisson by redisson.
the class RedissonRPCServerDefinitionParser method parseNested.
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
Class<?> apiClass;
try {
apiClass = Class.forName(helper.getAttribute(element, RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE));
} catch (ClassNotFoundException ex) {
throw new IllegalArgumentException("The class [" + helper.getAttribute(element, RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE) + "] specified in \"" + RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE + "\" attribute has not " + "found. Please check the class path.", ex);
}
builder.addPropertyValue("targetObject", new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.REMOTE_SERVICE_REF_ATTRIBUTE)));
builder.addPropertyValue("targetMethod", "register");
ManagedList args = new ManagedList();
args.add(apiClass);
args.add(new RuntimeBeanReference(helper.getAttribute(element, BeanDefinitionParserDelegate.BEAN_REF_ATTRIBUTE)));
String workers = null;
if (helper.hasAttribute(element, RedissonNamespaceParserSupport.CONCURRENT_WORKERS_ATTRIBUTE)) {
workers = helper.getAttribute(element, RedissonNamespaceParserSupport.CONCURRENT_WORKERS_ATTRIBUTE);
}
if (StringUtils.hasText(workers)) {
args.add(Integer.parseInt(workers));
}
if (helper.hasAttribute(element, RedissonNamespaceParserSupport.EXECUTOR_REF_ATTRIBUTE)) {
Assert.state(helper.hasAttribute(element, RedissonNamespaceParserSupport.CONCURRENT_WORKERS_ATTRIBUTE), "The \"" + RedissonNamespaceParserSupport.CONCURRENT_WORKERS_ATTRIBUTE + "\" attribute in \"" + RedissonNamespaceParserSupport.RPC_SERVER_ELEMENT + "\" element is required when \"" + RedissonNamespaceParserSupport.EXECUTOR_REF_ATTRIBUTE + "\" attribute is specified.");
args.add(new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.EXECUTOR_REF_ATTRIBUTE)));
}
builder.addPropertyValue("arguments", args);
}
Aggregations