use of org.springframework.beans.factory.config.RuntimeBeanReference in project redisson by redisson.
the class LocalCachedMapOptionsDecorator method decorate.
@Override
public void decorate(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) {
NodeList list = element.getElementsByTagNameNS(RedissonNamespaceParserSupport.REDISSON_NAMESPACE, RedissonNamespaceParserSupport.LOCAL_CACHED_MAP_OPTIONS_ELEMENT);
Element options = null;
String id;
if (list.getLength() == 1) {
options = (Element) list.item(0);
id = invokeOptions(options, parserContext, helper);
for (int i = 0; i < options.getAttributes().getLength(); i++) {
Attr item = (Attr) options.getAttributes().item(i);
if (helper.isEligibleAttribute(item) && !RedissonNamespaceParserSupport.TIME_TO_LIVE_UNIT_ATTRIBUTE.equals(item.getLocalName()) && !RedissonNamespaceParserSupport.MAX_IDLE_UNIT_ATTRIBUTE.equals(item.getLocalName())) {
helper.invoker(id, helper.getName(item), new Object[] { item.getValue() }, parserContext);
}
}
invokeTimeUnitOptions(options, id, parserContext, helper, RedissonNamespaceParserSupport.TIME_TO_LIVE_ATTRIBUTE, RedissonNamespaceParserSupport.TIME_TO_LIVE_UNIT_ATTRIBUTE);
invokeTimeUnitOptions(options, id, parserContext, helper, RedissonNamespaceParserSupport.MAX_IDLE_ATTRIBUTE, RedissonNamespaceParserSupport.MAX_IDLE_UNIT_ATTRIBUTE);
} else {
id = invokeOptions(options, parserContext, helper);
}
helper.addConstructorArgs(new RuntimeBeanReference(id), LocalCachedMapOptions.class, builder);
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project redisson by redisson.
the class RedissonLiveObjectDefinitionParser method parseNested.
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
Class<?> apiClass;
try {
apiClass = Class.forName(helper.getAttribute(element, RedissonNamespaceParserSupport.CLASS_ATTRIBUTE));
} catch (ClassNotFoundException ex) {
throw new IllegalArgumentException("The class [" + helper.getAttribute(element, RedissonNamespaceParserSupport.CLASS_ATTRIBUTE) + "] specified in \"api-class\" attribute has not " + "found. Please check the class path.", ex);
}
Assert.state(helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE) || helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE), "One of \"" + RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE + "\" or \"" + RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE + "\" attribute is required in the \"" + RedissonNamespaceParserSupport.LIVE_OBJECT_ELEMENT + "\" element.");
builder.addPropertyValue("targetObject", new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.LIVE_OBJECT_SERVICE_REF_ATTRIBUTE)));
builder.addPropertyValue("targetMethod", "get");
ManagedList args = new ManagedList();
args.add(apiClass);
if (helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE)) {
args.add(helper.getAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE));
}
if (helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE)) {
args.add(new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE)));
}
builder.addPropertyValue("arguments", args);
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project redisson by redisson.
the class RedissonMultiLockDefinitionParser method parseNested.
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
bd.setDependsOn(element.getAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
List<Element> childElements = DomUtils.getChildElements(element);
for (Element elt : childElements) {
String localName = elt.getLocalName();
if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(localName)) {
//parsed elsewhere
continue;
}
String id;
if (BeanDefinitionParserDelegate.REF_ELEMENT.equals(localName)) {
id = elt.getAttribute(BeanDefinitionParserDelegate.BEAN_REF_ATTRIBUTE);
} else {
if (!elt.hasAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE)) {
helper.setAttribute(elt, RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE, element.getAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
}
helper.populateIdAttribute(elt, builder, parserContext);
parserContext.getDelegate().parseCustomElement(elt, bd);
id = elt.getAttribute(RedissonNamespaceParserSupport.ID_ATTRIBUTE);
}
ConstructorArgumentValues args = builder.getRawBeanDefinition().getConstructorArgumentValues();
if (args.getArgumentCount() > 0) {
ConstructorArgumentValues.ValueHolder value = args.getIndexedArgumentValues().get(0);
ManagedList list;
if (value.getValue() instanceof ManagedList) {
list = (ManagedList) value.getValue();
} else {
list = new ManagedList();
list.add(value.getValue());
value.setValue(list);
value.setType(ManagedList.class.getName());
}
list.add(new RuntimeBeanReference(id));
} else {
builder.addConstructorArgReference(id);
}
}
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project redisson by redisson.
the class RedissonRPCClientDefinitionParser 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", "get");
builder.addPropertyValue("arguments", new Object[] { apiClass });
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project hudson-2.x by hudson.
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
*/
private Object manageMapIfNecessary(Object value) {
Map<Object, Object> map = (Map) value;
boolean containsRuntimeRefs = false;
for (Entry<Object, Object> e : map.entrySet()) {
Object v = e.getValue();
if (v instanceof RuntimeBeanReference) {
containsRuntimeRefs = true;
}
if (v instanceof BeanConfiguration) {
BeanConfiguration c = (BeanConfiguration) v;
e.setValue(c.getBeanDefinition());
containsRuntimeRefs = true;
}
}
if (containsRuntimeRefs) {
// return new ManagedMap(map);
ManagedMap m = new ManagedMap();
m.putAll(map);
return m;
}
return value;
}
Aggregations