org.springframework.beans.Mergeable Java Examples

The following examples show how to use org.springframework.beans.Mergeable. 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: ConstructorArgumentValues.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Add a generic argument value, merging the new value (typically a collection)
 * with the current value if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeGenericArgumentValue(ValueHolder newValue) {
	if (newValue.getName() != null) {
		for (Iterator<ValueHolder> it = this.genericArgumentValues.iterator(); it.hasNext();) {
			ValueHolder currentValue = it.next();
			if (newValue.getName().equals(currentValue.getName())) {
				if (newValue.getValue() instanceof Mergeable) {
					Mergeable mergeable = (Mergeable) newValue.getValue();
					if (mergeable.isMergeEnabled()) {
						newValue.setValue(mergeable.merge(currentValue.getValue()));
					}
				}
				it.remove();
			}
		}
	}
	this.genericArgumentValues.add(newValue);
}
 
Example #2
Source File: ConstructorArgumentValues.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Add a generic argument value, merging the new value (typically a collection)
 * with the current value if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeGenericArgumentValue(ValueHolder newValue) {
	if (newValue.getName() != null) {
		for (Iterator<ValueHolder> it = this.genericArgumentValues.iterator(); it.hasNext();) {
			ValueHolder currentValue = it.next();
			if (newValue.getName().equals(currentValue.getName())) {
				if (newValue.getValue() instanceof Mergeable) {
					Mergeable mergeable = (Mergeable) newValue.getValue();
					if (mergeable.isMergeEnabled()) {
						newValue.setValue(mergeable.merge(currentValue.getValue()));
					}
				}
				it.remove();
			}
		}
	}
	this.genericArgumentValues.add(newValue);
}
 
Example #3
Source File: ConstructorArgumentValues.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add a generic argument value, merging the new value (typically a collection)
 * with the current value if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeGenericArgumentValue(ValueHolder newValue) {
	if (newValue.getName() != null) {
		for (Iterator<ValueHolder> it = this.genericArgumentValues.iterator(); it.hasNext();) {
			ValueHolder currentValue = it.next();
			if (newValue.getName().equals(currentValue.getName())) {
				if (newValue.getValue() instanceof Mergeable) {
					Mergeable mergeable = (Mergeable) newValue.getValue();
					if (mergeable.isMergeEnabled()) {
						newValue.setValue(mergeable.merge(currentValue.getValue()));
					}
				}
				it.remove();
			}
		}
	}
	this.genericArgumentValues.add(newValue);
}
 
Example #4
Source File: ConstructorArgumentValues.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
/**
 * Add a generic argument value, merging the new value (typically a collection)
 * with the current value if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeGenericArgumentValue(ValueHolder newValue) {
	if (newValue.getName() != null) {
		for (Iterator<ValueHolder> it = this.genericArgumentValues.iterator(); it.hasNext();) {
			ValueHolder currentValue = it.next();
			if (newValue.getName().equals(currentValue.getName())) {
				if (newValue.getValue() instanceof Mergeable) {
					Mergeable mergeable = (Mergeable) newValue.getValue();
					if (mergeable.isMergeEnabled()) {
						newValue.setValue(mergeable.merge(currentValue.getValue()));
					}
				}
				it.remove();
			}
		}
	}
	this.genericArgumentValues.add(newValue);
}
 
Example #5
Source File: ConstructorArgumentValues.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Add a generic argument value, merging the new value (typically a collection)
 * with the current value if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeGenericArgumentValue(ValueHolder newValue) {
	if (newValue.getName() != null) {
		for (Iterator<ValueHolder> it = this.genericArgumentValues.iterator(); it.hasNext();) {
			ValueHolder currentValue = it.next();
			if (newValue.getName().equals(currentValue.getName())) {
				if (newValue.getValue() instanceof Mergeable) {
					Mergeable mergeable = (Mergeable) newValue.getValue();
					if (mergeable.isMergeEnabled()) {
						newValue.setValue(mergeable.merge(currentValue.getValue()));
					}
				}
				it.remove();
			}
		}
	}
	this.genericArgumentValues.add(newValue);
}
 
Example #6
Source File: ConstructorArgumentValues.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Add an argument value for the given index in the constructor argument list,
 * merging the new value (typically a collection) with the current value
 * if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param key the index in the constructor argument list
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeIndexedArgumentValue(Integer key, ValueHolder newValue) {
	ValueHolder currentValue = this.indexedArgumentValues.get(key);
	if (currentValue != null && newValue.getValue() instanceof Mergeable) {
		Mergeable mergeable = (Mergeable) newValue.getValue();
		if (mergeable.isMergeEnabled()) {
			newValue.setValue(mergeable.merge(currentValue.getValue()));
		}
	}
	this.indexedArgumentValues.put(key, newValue);
}
 
Example #7
Source File: ConstructorArgumentValues.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Add an argument value for the given index in the constructor argument list,
 * merging the new value (typically a collection) with the current value
 * if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param key the index in the constructor argument list
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeIndexedArgumentValue(Integer key, ValueHolder newValue) {
	ValueHolder currentValue = this.indexedArgumentValues.get(key);
	if (currentValue != null && newValue.getValue() instanceof Mergeable) {
		Mergeable mergeable = (Mergeable) newValue.getValue();
		if (mergeable.isMergeEnabled()) {
			newValue.setValue(mergeable.merge(currentValue.getValue()));
		}
	}
	this.indexedArgumentValues.put(key, newValue);
}
 
Example #8
Source File: ConstructorArgumentValues.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add an argument value for the given index in the constructor argument list,
 * merging the new value (typically a collection) with the current value
 * if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param key the index in the constructor argument list
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeIndexedArgumentValue(Integer key, ValueHolder newValue) {
	ValueHolder currentValue = this.indexedArgumentValues.get(key);
	if (currentValue != null && newValue.getValue() instanceof Mergeable) {
		Mergeable mergeable = (Mergeable) newValue.getValue();
		if (mergeable.isMergeEnabled()) {
			newValue.setValue(mergeable.merge(currentValue.getValue()));
		}
	}
	this.indexedArgumentValues.put(key, newValue);
}
 
Example #9
Source File: ConstructorArgumentValues.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Add an argument value for the given index in the constructor argument list,
 * merging the new value (typically a collection) with the current value
 * if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param key the index in the constructor argument list
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeIndexedArgumentValue(Integer key, ValueHolder newValue) {
	ValueHolder currentValue = this.indexedArgumentValues.get(key);
	if (currentValue != null && newValue.getValue() instanceof Mergeable) {
		Mergeable mergeable = (Mergeable) newValue.getValue();
		if (mergeable.isMergeEnabled()) {
			newValue.setValue(mergeable.merge(currentValue.getValue()));
		}
	}
	this.indexedArgumentValues.put(key, newValue);
}
 
Example #10
Source File: ConstructorArgumentValues.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Add an argument value for the given index in the constructor argument list,
 * merging the new value (typically a collection) with the current value
 * if demanded: see {@link org.springframework.beans.Mergeable}.
 * @param key the index in the constructor argument list
 * @param newValue the argument value in the form of a ValueHolder
 */
private void addOrMergeIndexedArgumentValue(Integer key, ValueHolder newValue) {
	ValueHolder currentValue = this.indexedArgumentValues.get(key);
	if (currentValue != null && newValue.getValue() instanceof Mergeable) {
		Mergeable mergeable = (Mergeable) newValue.getValue();
		if (mergeable.isMergeEnabled()) {
			newValue.setValue(mergeable.merge(currentValue.getValue()));
		}
	}
	this.indexedArgumentValues.put(key, newValue);
}
 
Example #11
Source File: MockMvc.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Perform a request and return a type that allows chaining further
 * actions, such as asserting expectations, on the result.
 *
 * @param requestBuilder used to prepare the request to execute;
 * see static factory methods in
 * {@link org.springframework.test.web.servlet.request.MockMvcRequestBuilders}
 *
 * @return an instance of {@link ResultActions}; never {@code null}
 *
 * @see org.springframework.test.web.servlet.request.MockMvcRequestBuilders
 * @see org.springframework.test.web.servlet.result.MockMvcResultMatchers
 */
public ResultActions perform(RequestBuilder requestBuilder) throws Exception {

	if (this.defaultRequestBuilder != null) {
		if (requestBuilder instanceof Mergeable) {
			requestBuilder = (RequestBuilder) ((Mergeable) requestBuilder).merge(this.defaultRequestBuilder);
		}
	}

	MockHttpServletRequest request = requestBuilder.buildRequest(this.servletContext);
	MockHttpServletResponse response = new MockHttpServletResponse();

	if (requestBuilder instanceof SmartRequestBuilder) {
		request = ((SmartRequestBuilder) requestBuilder).postProcessRequest(request);
	}

	final MvcResult mvcResult = new DefaultMvcResult(request, response);
	request.setAttribute(MVC_RESULT_ATTRIBUTE, mvcResult);

	RequestAttributes previousAttributes = RequestContextHolder.getRequestAttributes();
	RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, response));

	MockFilterChain filterChain = new MockFilterChain(this.servlet, this.filters);
	filterChain.doFilter(request, response);

	if (DispatcherType.ASYNC.equals(request.getDispatcherType()) &&
			request.getAsyncContext() != null & !request.isAsyncStarted()) {

		request.getAsyncContext().complete();
	}

	applyDefaultResultActions(mvcResult);

	RequestContextHolder.setRequestAttributes(previousAttributes);

	return new ResultActions() {

		@Override
		public ResultActions andExpect(ResultMatcher matcher) throws Exception {
			matcher.match(mvcResult);
			return this;
		}

		@Override
		public ResultActions andDo(ResultHandler handler) throws Exception {
			handler.handle(mvcResult);
			return this;
		}

		@Override
		public MvcResult andReturn() {
			return mvcResult;
		}
	};
}
 
Example #12
Source File: SpringBeanLocator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public boolean hasConfiguredPropertyValue(String beanName, String propertyName, String searchValue) {
    if (context.containsBean(beanName) && !passThroughs.contains(beanName)) {
        ConfigurableApplicationContext ctxt = (ConfigurableApplicationContext)context;
        BeanDefinition def = ctxt.getBeanFactory().getBeanDefinition(beanName);
        if (!ctxt.getBeanFactory().isSingleton(beanName) || def.isAbstract()) {
            return false;
        }
        Collection<?> ids = null;
        PropertyValue pv = def.getPropertyValues().getPropertyValue(propertyName);

        if (pv != null) {
            Object value = pv.getValue();
            if (!(value instanceof Collection)) {
                throw new RuntimeException("The property " + propertyName + " must be a collection!");
            }

            if (value instanceof Mergeable) {
                if (!((Mergeable)value).isMergeEnabled()) {
                    ids = (Collection<?>)value;
                }
            } else {
                ids = (Collection<?>)value;
            }
        }

        if (ids != null) {
            for (Iterator<?> itr = ids.iterator(); itr.hasNext();) {
                Object o = itr.next();
                if (o instanceof TypedStringValue) {
                    if (searchValue.equals(((TypedStringValue) o).getValue())) {
                        return true;
                    }
                } else {
                    if (searchValue.equals(o)) {
                        return true;
                    }
                }
            }
        }
    }
    return orig.hasConfiguredPropertyValue(beanName, propertyName, searchValue);
}