org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder Java Examples
The following examples show how to use
org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BusWiringBeanFactoryPostProcessor.java From cxf with Apache License 2.0 | 6 votes |
/** * Insert the given value as the first constructor argument in the given set. To do this, we clear the * argument set, then re-insert all its generic arguments, then re-insert all its indexed arguments with * their indices incremented by 1, and finally set the first indexed argument (at index 0) to the given * value. * * @param constructorArgs the argument definition to modify. * @param valueToInsert the value to insert as the first argument. */ private void insertConstructorArg(ConstructorArgumentValues constructorArgs, Object valueToInsert) { List<ValueHolder> genericArgs = new ArrayList<>(CastUtils .<ValueHolder> cast(constructorArgs.getGenericArgumentValues())); Map<Integer, ValueHolder> indexedArgs = new HashMap<>(CastUtils .<Integer, ValueHolder> cast(constructorArgs.getIndexedArgumentValues())); constructorArgs.clear(); for (ValueHolder genericValue : genericArgs) { constructorArgs.addGenericArgumentValue(genericValue); } for (Map.Entry<Integer, ValueHolder> entry : indexedArgs.entrySet()) { constructorArgs.addIndexedArgumentValue(entry.getKey() + 1, entry.getValue()); } constructorArgs.addIndexedArgumentValue(0, valueToInsert); }
Example #2
Source File: SimpleConstructorNamespaceHandler.java From spring-analysis-note with MIT License | 5 votes |
private boolean checkName(String name, Collection<ValueHolder> values) { for (ValueHolder holder : values) { if (name.equals(holder.getName())) { return true; } } return false; }
Example #3
Source File: SimpleConstructorNamespaceHandler.java From java-technology-stack with MIT License | 5 votes |
private boolean checkName(String name, Collection<ValueHolder> values) { for (ValueHolder holder : values) { if (name.equals(holder.getName())) { return true; } } return false; }
Example #4
Source File: SimpleConstructorNamespaceHandler.java From lams with GNU General Public License v2.0 | 5 votes |
private boolean checkName(String name, Collection<ValueHolder> values) { for (ValueHolder holder : values) { if (name.equals(holder.getName())) { return true; } } return false; }
Example #5
Source File: SimpleConstructorNamespaceHandler.java From blog_demos with Apache License 2.0 | 5 votes |
private boolean checkName(String name, Collection<ValueHolder> values) { for (ValueHolder holder : values) { if (name.equals(holder.getName())) { return true; } } return false; }
Example #6
Source File: SimpleConstructorNamespaceHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
private boolean checkName(String name, Collection<ValueHolder> values) { for (ValueHolder holder : values) { if (name.equals(holder.getName())) { return true; } } return false; }
Example #7
Source File: DefaultRiptideConfigurer.java From riptide with MIT License | 5 votes |
private void replaceRefs(final ValueHolder holder, final Map<String, BeanMetadataElement> replacements) { Optional.ofNullable(holder.getValue()) .filter(String.class::isInstance) .map(String.class::cast) .map(replacements::get) .ifPresent(holder::setValue); }
Example #8
Source File: SimpleConstructorNamespaceHandler.java From spring-analysis-note with MIT License | 4 votes |
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { if (node instanceof Attr) { Attr attr = (Attr) node; String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr)); String argValue = StringUtils.trimWhitespace(attr.getValue()); ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues(); boolean ref = false; // handle -ref arguments if (argName.endsWith(REF_SUFFIX)) { ref = true; argName = argName.substring(0, argName.length() - REF_SUFFIX.length()); } ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue); valueHolder.setSource(parserContext.getReaderContext().extractSource(attr)); // handle "escaped"/"_" arguments if (argName.startsWith(DELIMITER_PREFIX)) { String arg = argName.substring(1).trim(); // fast default check if (!StringUtils.hasText(arg)) { cvs.addGenericArgumentValue(valueHolder); } // assume an index otherwise else { int index = -1; try { index = Integer.parseInt(arg); } catch (NumberFormatException ex) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies an invalid integer", attr); } if (index < 0) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies a negative index", attr); } if (cvs.hasIndexedArgumentValue(index)) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } cvs.addIndexedArgumentValue(index, valueHolder); } } // no escaping -> ctr name else { String name = Conventions.attributeNameToPropertyName(argName); if (containsArgWithName(name, cvs)) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } valueHolder.setName(Conventions.attributeNameToPropertyName(argName)); cvs.addGenericArgumentValue(valueHolder); } } return definition; }
Example #9
Source File: SimpleConstructorNamespaceHandler.java From java-technology-stack with MIT License | 4 votes |
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { if (node instanceof Attr) { Attr attr = (Attr) node; String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr)); String argValue = StringUtils.trimWhitespace(attr.getValue()); ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues(); boolean ref = false; // handle -ref arguments if (argName.endsWith(REF_SUFFIX)) { ref = true; argName = argName.substring(0, argName.length() - REF_SUFFIX.length()); } ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue); valueHolder.setSource(parserContext.getReaderContext().extractSource(attr)); // handle "escaped"/"_" arguments if (argName.startsWith(DELIMITER_PREFIX)) { String arg = argName.substring(1).trim(); // fast default check if (!StringUtils.hasText(arg)) { cvs.addGenericArgumentValue(valueHolder); } // assume an index otherwise else { int index = -1; try { index = Integer.parseInt(arg); } catch (NumberFormatException ex) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies an invalid integer", attr); } if (index < 0) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies a negative index", attr); } if (cvs.hasIndexedArgumentValue(index)) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } cvs.addIndexedArgumentValue(index, valueHolder); } } // no escaping -> ctr name else { String name = Conventions.attributeNameToPropertyName(argName); if (containsArgWithName(name, cvs)) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } valueHolder.setName(Conventions.attributeNameToPropertyName(argName)); cvs.addGenericArgumentValue(valueHolder); } } return definition; }
Example #10
Source File: SimpleConstructorNamespaceHandler.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { if (node instanceof Attr) { Attr attr = (Attr) node; String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr)); String argValue = StringUtils.trimWhitespace(attr.getValue()); ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues(); boolean ref = false; // handle -ref arguments if (argName.endsWith(REF_SUFFIX)) { ref = true; argName = argName.substring(0, argName.length() - REF_SUFFIX.length()); } ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue); valueHolder.setSource(parserContext.getReaderContext().extractSource(attr)); // handle "escaped"/"_" arguments if (argName.startsWith(DELIMITER_PREFIX)) { String arg = argName.substring(1).trim(); // fast default check if (!StringUtils.hasText(arg)) { cvs.addGenericArgumentValue(valueHolder); } // assume an index otherwise else { int index = -1; try { index = Integer.parseInt(arg); } catch (NumberFormatException ex) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies an invalid integer", attr); } if (index < 0) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies a negative index", attr); } if (cvs.hasIndexedArgumentValue(index)){ parserContext.getReaderContext().error( "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } cvs.addIndexedArgumentValue(index, valueHolder); } } // no escaping -> ctr name else { String name = Conventions.attributeNameToPropertyName(argName); if (containsArgWithName(name, cvs)){ parserContext.getReaderContext().error( "Constructor argument '" + argName + "' already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } valueHolder.setName(Conventions.attributeNameToPropertyName(argName)); cvs.addGenericArgumentValue(valueHolder); } } return definition; }
Example #11
Source File: SimpleConstructorNamespaceHandler.java From blog_demos with Apache License 2.0 | 4 votes |
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { if (node instanceof Attr) { Attr attr = (Attr) node; String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr)); String argValue = StringUtils.trimWhitespace(attr.getValue()); ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues(); boolean ref = false; // handle -ref arguments if (argName.endsWith(REF_SUFFIX)) { ref = true; argName = argName.substring(0, argName.length() - REF_SUFFIX.length()); } ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue); valueHolder.setSource(parserContext.getReaderContext().extractSource(attr)); // handle "escaped"/"_" arguments if (argName.startsWith(DELIMITER_PREFIX)) { String arg = argName.substring(1).trim(); // fast default check if (!StringUtils.hasText(arg)) { cvs.addGenericArgumentValue(valueHolder); } // assume an index otherwise else { int index = -1; try { index = Integer.parseInt(arg); } catch (NumberFormatException ex) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies an invalid integer", attr); } if (index < 0) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies a negative index", attr); } if (cvs.hasIndexedArgumentValue(index)){ parserContext.getReaderContext().error( "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } cvs.addIndexedArgumentValue(index, valueHolder); } } // no escaping -> ctr name else { String name = Conventions.attributeNameToPropertyName(argName); if (containsArgWithName(name, cvs)){ parserContext.getReaderContext().error( "Constructor argument '" + argName + "' already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } valueHolder.setName(Conventions.attributeNameToPropertyName(argName)); cvs.addGenericArgumentValue(valueHolder); } } return definition; }
Example #12
Source File: SimpleConstructorNamespaceHandler.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { if (node instanceof Attr) { Attr attr = (Attr) node; String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr)); String argValue = StringUtils.trimWhitespace(attr.getValue()); ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues(); boolean ref = false; // handle -ref arguments if (argName.endsWith(REF_SUFFIX)) { ref = true; argName = argName.substring(0, argName.length() - REF_SUFFIX.length()); } ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue); valueHolder.setSource(parserContext.getReaderContext().extractSource(attr)); // handle "escaped"/"_" arguments if (argName.startsWith(DELIMITER_PREFIX)) { String arg = argName.substring(1).trim(); // fast default check if (!StringUtils.hasText(arg)) { cvs.addGenericArgumentValue(valueHolder); } // assume an index otherwise else { int index = -1; try { index = Integer.parseInt(arg); } catch (NumberFormatException ex) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies an invalid integer", attr); } if (index < 0) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies a negative index", attr); } if (cvs.hasIndexedArgumentValue(index)){ parserContext.getReaderContext().error( "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } cvs.addIndexedArgumentValue(index, valueHolder); } } // no escaping -> ctr name else { String name = Conventions.attributeNameToPropertyName(argName); if (containsArgWithName(name, cvs)){ parserContext.getReaderContext().error( "Constructor argument '" + argName + "' already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } valueHolder.setName(Conventions.attributeNameToPropertyName(argName)); cvs.addGenericArgumentValue(valueHolder); } } return definition; }
Example #13
Source File: JettyHTTPServerEngineBeanDefinitionParser.java From cxf with Apache License 2.0 | 4 votes |
public void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { String portStr = element.getAttribute("port"); bean.addPropertyValue("port", portStr); String hostStr = element.getAttribute("host"); if (hostStr != null && !"".equals(hostStr.trim())) { bean.addPropertyValue("host", hostStr); } String continuationsStr = element.getAttribute("continuationsEnabled"); if (continuationsStr != null && continuationsStr.length() > 0) { bean.addPropertyValue("continuationsEnabled", continuationsStr); } String maxIdleTimeStr = element.getAttribute("maxIdleTime"); if (maxIdleTimeStr != null && !"".equals(maxIdleTimeStr.trim())) { bean.addPropertyValue("maxIdleTime", maxIdleTimeStr); } String sendServerVersionStr = element.getAttribute("sendServerVersion"); if (sendServerVersionStr != null && sendServerVersionStr.length() > 0) { bean.addPropertyValue("sendServerVersion", sendServerVersionStr); } ValueHolder busValue = ctx.getContainingBeanDefinition() .getConstructorArgumentValues().getArgumentValue(0, Bus.class); bean.addPropertyValue("bus", busValue.getValue()); try { Element elem = DOMUtils.getFirstElement(element); while (elem != null) { String name = elem.getLocalName(); if ("tlsServerParameters".equals(name)) { mapTLSServerParameters(elem, bean); } else if ("threadingParameters".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "threadingParameters", ThreadingParametersType.class, JettyHTTPServerEngineBeanDefinitionParser.class, "createThreadingParameters"); } else if ("tlsServerParametersRef".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "tlsServerParametersRef", TLSServerParametersIdentifiedType.class, JettyHTTPServerEngineBeanDefinitionParser.class, "createTLSServerParametersConfigRef"); } else if ("threadingParametersRef".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "threadingParametersRef", ThreadingParametersIdentifiedType.class, JettyHTTPServerEngineBeanDefinitionParser.class, "createThreadingParametersRef" ); } else if ("connector".equals(name)) { // only deal with the one connector here List<?> list = ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition()); bean.addPropertyValue("connector", list.get(0)); } else if ("handlers".equals(name)) { List<?> handlers = ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition()); bean.addPropertyValue("handlers", handlers); } else if ("sessionTimeout".equals(name) || "sessionSupport".equals(name) || "reuseAddress".equals(name)) { String text = elem.getTextContent(); bean.addPropertyValue(name, text); } elem = org.apache.cxf.helpers.DOMUtils.getNextElement(elem); } } catch (Exception e) { throw new RuntimeException("Could not process configuration.", e); } bean.setLazyInit(false); }
Example #14
Source File: UndertowHTTPServerEngineBeanDefinitionParser.java From cxf with Apache License 2.0 | 4 votes |
public void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { String portStr = element.getAttribute("port"); bean.addPropertyValue("port", portStr); String hostStr = element.getAttribute("host"); if (hostStr != null && !"".equals(hostStr.trim())) { bean.addPropertyValue("host", hostStr); } String continuationsStr = element.getAttribute("continuationsEnabled"); if (continuationsStr != null && continuationsStr.length() > 0) { bean.addPropertyValue("continuationsEnabled", continuationsStr); } String maxIdleTimeStr = element.getAttribute("maxIdleTime"); if (maxIdleTimeStr != null && !"".equals(maxIdleTimeStr.trim())) { bean.addPropertyValue("maxIdleTime", maxIdleTimeStr); } ValueHolder busValue = ctx.getContainingBeanDefinition() .getConstructorArgumentValues().getArgumentValue(0, Bus.class); bean.addPropertyValue("bus", busValue.getValue()); try { Element elem = DOMUtils.getFirstElement(element); while (elem != null) { String name = elem.getLocalName(); if ("tlsServerParameters".equals(name)) { mapTLSServerParameters(elem, bean); } else if ("threadingParameters".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "threadingParameters", ThreadingParametersType.class, UndertowHTTPServerEngineBeanDefinitionParser.class, "createThreadingParameters"); } else if ("tlsServerParametersRef".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "tlsServerParametersRef", TLSServerParametersIdentifiedType.class, UndertowHTTPServerEngineBeanDefinitionParser.class, "createTLSServerParametersConfigRef"); } else if ("threadingParametersRef".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "threadingParametersRef", ThreadingParametersIdentifiedType.class, UndertowHTTPServerEngineBeanDefinitionParser.class, "createThreadingParametersRef" ); } else if ("handlers".equals(name)) { List<?> handlers = ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition()); bean.addPropertyValue("handlers", handlers); } elem = org.apache.cxf.helpers.DOMUtils.getNextElement(elem); } } catch (Exception e) { throw new RuntimeException("Could not process configuration.", e); } bean.setLazyInit(false); }
Example #15
Source File: NettyHttpServerEngineBeanDefinitionParser.java From cxf with Apache License 2.0 | 4 votes |
public void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { String portStr = element.getAttribute("port"); bean.addPropertyValue("port", portStr); String hostStr = element.getAttribute("host"); if (hostStr != null && !"".equals(hostStr.trim())) { bean.addPropertyValue("host", hostStr); } String readIdleTimeStr = element.getAttribute("readIdleTime"); if (readIdleTimeStr != null && !"".equals(readIdleTimeStr.trim())) { bean.addPropertyValue("readIdleTime", readIdleTimeStr); } String writeIdleTimeStr = element.getAttribute("writeIdleTime"); if (writeIdleTimeStr != null && !"".equals(writeIdleTimeStr.trim())) { bean.addPropertyValue("writeIdleTime", writeIdleTimeStr); } String maxChunkContentSizeStr = element.getAttribute("maxChunkContentSize"); if (maxChunkContentSizeStr != null && !"".equals(maxChunkContentSizeStr.trim())) { bean.addPropertyValue("maxChunkContentSize", maxChunkContentSizeStr); } ValueHolder busValue = ctx.getContainingBeanDefinition() .getConstructorArgumentValues().getArgumentValue(0, Bus.class); bean.addPropertyValue("bus", busValue.getValue()); try { Element elem = DOMUtils.getFirstElement(element); while (elem != null) { String name = elem.getLocalName(); if ("tlsServerParameters".equals(name)) { mapTLSServerParameters(elem, bean); } else if ("tlsServerParametersRef".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "tlsServerParametersRef", TLSServerParametersIdentifiedType.class, NettyHttpServerEngineBeanDefinitionParser.class, "createTLSServerParametersConfigRef"); } else if ("threadingParameters".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "threadingParameters", ThreadingParametersType.class, NettyHttpServerEngineBeanDefinitionParser.class, "createThreadingParameters"); } else if ("threadingParametersRef".equals(name)) { mapElementToJaxbPropertyFactory(elem, bean, "threadingParametersRef", ThreadingParametersIdentifiedType.class, NettyHttpServerEngineBeanDefinitionParser.class, "createThreadingParametersRef" ); } else if ("sessionSupport".equals(name) || "reuseAddress".equals(name)) { String text = elem.getTextContent(); bean.addPropertyValue(name, text); } elem = org.apache.cxf.helpers.DOMUtils.getNextElement(elem); } } catch (Exception e) { throw new RuntimeException("Could not process configuration.", e); } bean.setLazyInit(false); }