本文整理匯總了Java中org.springframework.beans.PropertyValue類的典型用法代碼示例。如果您正苦於以下問題:Java PropertyValue類的具體用法?Java PropertyValue怎麽用?Java PropertyValue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PropertyValue類屬於org.springframework.beans包,在下文中一共展示了PropertyValue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getInterfaces
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
private String[] getInterfaces(PropertyValue pv) {
if (pv == null)
return new String[0];
Object value = pv.getValue();
if (value instanceof Collection) {
Collection collection = (Collection) value;
String[] strs = new String[collection.size()];
int index = 0;
for (Object obj : collection) {
if (value instanceof TypedStringValue) {
strs[index] = ((TypedStringValue) value).getValue();
} else {
strs[index] = value.toString();
}
index++;
}
return strs;
} else {
return new String[] { value.toString() };
}
}
示例2: getBeanProperties
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
static List<BeanProperty> getBeanProperties(BeanDefinition definition) {
List<BeanProperty> temp;
List<PropertyValue> pvs = definition.getPropertyValues().getPropertyValueList();
if (pvs.isEmpty()) {
return Collections.<BeanProperty> emptyList();
} else {
temp = new ArrayList<BeanProperty>(pvs.size());
}
for (PropertyValue propertyValue : pvs) {
temp.add(new SimpleBeanProperty(propertyValue));
}
return Collections.unmodifiableList(temp);
}
示例3: parsePropertyElement
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
private void parsePropertyElement(Element ele, BeanDefinition bd) {
String propertyName = ele.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
if (!StringUtils.hasLength(propertyName)) {
error("Tag 'property' must have a 'name' attribute", ele);
return;
}
this.parseState.push(new PropertyEntry(propertyName));
try {
if (bd.getPropertyValues().contains(propertyName)) {
error("Multiple 'property' definitions for property '" + propertyName + "'", ele);
return;
}
Object val = parsePropertyValue(ele, bd, propertyName);
PropertyValue pv = new PropertyValue(propertyName, val);
pv.setSource(parserContext.extractSource(ele));
bd.getPropertyValues().addPropertyValue(pv);
} finally {
this.parseState.pop();
}
}
示例4: checkFieldDefaults
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
/**
* Check the given property values for field defaults,
* i.e. for fields that start with the field default prefix.
* <p>The existence of a field defaults indicates that the specified
* value should be used if the field is otherwise not present.
* @param mpvs the property values to be bound (can be modified)
* @see #getFieldDefaultPrefix
*/
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
if (getFieldDefaultPrefix() != null) {
String fieldDefaultPrefix = getFieldDefaultPrefix();
PropertyValue[] pvArray = mpvs.getPropertyValues();
for (PropertyValue pv : pvArray) {
if (pv.getName().startsWith(fieldDefaultPrefix)) {
String field = pv.getName().substring(fieldDefaultPrefix.length());
if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
mpvs.add(field, pv.getValue());
}
mpvs.removePropertyValue(pv);
}
}
}
}
示例5: checkFieldMarkers
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
/**
* Check the given property values for field markers,
* i.e. for fields that start with the field marker prefix.
* <p>The existence of a field marker indicates that the specified
* field existed in the form. If the property values do not contain
* a corresponding field value, the field will be considered as empty
* and will be reset appropriately.
* @param mpvs the property values to be bound (can be modified)
* @see #getFieldMarkerPrefix
* @see #getEmptyValue(String, Class)
*/
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
if (getFieldMarkerPrefix() != null) {
String fieldMarkerPrefix = getFieldMarkerPrefix();
PropertyValue[] pvArray = mpvs.getPropertyValues();
for (PropertyValue pv : pvArray) {
if (pv.getName().startsWith(fieldMarkerPrefix)) {
String field = pv.getName().substring(fieldMarkerPrefix.length());
if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
mpvs.add(field, getEmptyValue(field, fieldType));
}
mpvs.removePropertyValue(pv);
}
}
}
}
示例6: FilterConfigPropertyValues
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
/**
* Create new FilterConfigPropertyValues.
* @param config FilterConfig we'll use to take PropertyValues from
* @param requiredProperties set of property names we need, where
* we can't accept default values
* @throws ServletException if any required properties are missing
*/
public FilterConfigPropertyValues(FilterConfig config, Set<String> requiredProperties)
throws ServletException {
Set<String> missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ?
new HashSet<String>(requiredProperties) : null;
Enumeration<?> en = config.getInitParameterNames();
while (en.hasMoreElements()) {
String property = (String) en.nextElement();
Object value = config.getInitParameter(property);
addPropertyValue(new PropertyValue(property, value));
if (missingProps != null) {
missingProps.remove(property);
}
}
// Fail if we are still missing properties.
if (missingProps != null && missingProps.size() > 0) {
throw new ServletException(
"Initialization from FilterConfig for filter '" + config.getFilterName() +
"' failed; the following required properties were missing: " +
StringUtils.collectionToDelimitedString(missingProps, ", "));
}
}
示例7: parsePropertyElement
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
/**
* Parse a property element.
*/
public void parsePropertyElement(Element ele, BeanDefinition bd) {
String propertyName = ele.getAttribute(NAME_ATTRIBUTE);
if (!StringUtils.hasLength(propertyName)) {
error("Tag 'property' must have a 'name' attribute", ele);
return;
}
this.parseState.push(new PropertyEntry(propertyName));
try {
if (bd.getPropertyValues().contains(propertyName)) {
error("Multiple 'property' definitions for property '" + propertyName + "'", ele);
return;
}
Object val = parsePropertyValue(ele, bd, propertyName);
PropertyValue pv = new PropertyValue(propertyName, val);
parseMetaElements(ele, pv);
pv.setSource(extractSource(ele));
bd.getPropertyValues().addPropertyValue(pv);
}
finally {
this.parseState.pop();
}
}
示例8: findInnerBeanDefinitionsAndBeanReferences
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>();
List<BeanReference> references = new ArrayList<BeanReference>();
PropertyValues propertyValues = beanDefinition.getPropertyValues();
for (int i = 0; i < propertyValues.getPropertyValues().length; i++) {
PropertyValue propertyValue = propertyValues.getPropertyValues()[i];
Object value = propertyValue.getValue();
if (value instanceof BeanDefinitionHolder) {
innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
}
else if (value instanceof BeanDefinition) {
innerBeans.add((BeanDefinition) value);
}
else if (value instanceof BeanReference) {
references.add((BeanReference) value);
}
}
this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
示例9: postProcessBeanFactory
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public void postProcessBeanFactory(
ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
String[] igniteConfigNames = configurableListableBeanFactory.getBeanNamesForType(IgniteConfiguration.class);
if (igniteConfigNames.length != 1) {
throw new IllegalArgumentException("Spring config must contain exactly one ignite configuration!");
}
String[] activeStoreConfigNames = configurableListableBeanFactory.getBeanNamesForType(BaseActiveStoreConfiguration.class);
if (activeStoreConfigNames.length != 1) {
throw new IllegalArgumentException("Spring config must contain exactly one active store configuration!");
}
BeanDefinition igniteConfigDef = configurableListableBeanFactory.getBeanDefinition(igniteConfigNames[0]);
MutablePropertyValues propertyValues = igniteConfigDef.getPropertyValues();
if (!propertyValues.contains(USER_ATTRS_PROP_NAME)) {
propertyValues.add(USER_ATTRS_PROP_NAME, new ManagedMap());
}
PropertyValue propertyValue = propertyValues.getPropertyValue(USER_ATTRS_PROP_NAME);
Map userAttrs = (Map)propertyValue.getValue();
TypedStringValue key = new TypedStringValue(CONFIG_USER_ATTR);
RuntimeBeanReference value = new RuntimeBeanReference(beanName);
userAttrs.put(key, value);
}
示例10: doParse
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
private synchronized void doParse(Element element, ParserContext parserContext) {
String[] basePackages = StringUtils.tokenizeToStringArray(element.getAttribute("base-package"), ",; \t\n");
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);
if (!parserContext.getRegistry().containsBeanDefinition(CacheAdvisor.CACHE_ADVISOR_BEAN_NAME)) {
Object eleSource = parserContext.extractSource(element);
RootBeanDefinition configMapDef = new RootBeanDefinition(ConcurrentHashMap.class);
configMapDef.setSource(eleSource);
configMapDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
String configMapName = parserContext.getReaderContext().registerWithGeneratedName(configMapDef);
RootBeanDefinition interceptorDef = new RootBeanDefinition(JetCacheInterceptor.class);
interceptorDef.setSource(eleSource);
interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
interceptorDef.getPropertyValues().addPropertyValue(new PropertyValue("cacheConfigMap", new RuntimeBeanReference(configMapName)));
String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);
RootBeanDefinition advisorDef = new RootBeanDefinition(CacheAdvisor.class);
advisorDef.setSource(eleSource);
advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("adviceBeanName", interceptorName));
advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("cacheConfigMap", new RuntimeBeanReference(configMapName)));
advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("basePackages", basePackages));
parserContext.getRegistry().registerBeanDefinition(CacheAdvisor.CACHE_ADVISOR_BEAN_NAME, advisorDef);
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
eleSource);
compositeDef.addNestedComponent(new BeanComponentDefinition(configMapDef, configMapName));
compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheAdvisor.CACHE_ADVISOR_BEAN_NAME));
parserContext.registerComponent(compositeDef);
}
}
示例11: PortletConfigPropertyValues
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
/**
* Create new PortletConfigPropertyValues.
* @param config PortletConfig we'll use to take PropertyValues from
* @param requiredProperties set of property names we need, where
* we can't accept default values
* @throws PortletException if any required properties are missing
*/
private PortletConfigPropertyValues(PortletConfig config, Set<String> requiredProperties)
throws PortletException {
Set<String> missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ?
new HashSet<String>(requiredProperties) : null;
Enumeration<String> en = config.getInitParameterNames();
while (en.hasMoreElements()) {
String property = en.nextElement();
Object value = config.getInitParameter(property);
addPropertyValue(new PropertyValue(property, value));
if (missingProps != null) {
missingProps.remove(property);
}
}
// fail if we are still missing properties
if (missingProps != null && missingProps.size() > 0) {
throw new PortletException(
"Initialization from PortletConfig for portlet '" + config.getPortletName() +
"' failed; the following required properties were missing: " +
StringUtils.collectionToDelimitedString(missingProps, ", "));
}
}
示例12: bindingNoErrors
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
@Test
public void bindingNoErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
assertTrue(binder.isIgnoreUnknownFields());
binder.initDirectFieldAccess();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
pvs.addPropertyValue(new PropertyValue("age", new Integer(32)));
pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue"));
binder.bind(pvs);
binder.close();
assertTrue("changed name correctly", rod.getName().equals("Rod"));
assertTrue("changed age correctly", rod.getAge() == 32);
Map<?, ?> m = binder.getBindingResult().getModel();
assertTrue("There is one element in map", m.size() == 2);
FieldAccessBean tb = (FieldAccessBean) m.get("person");
assertTrue("Same object", tb.equals(rod));
}
示例13: bindingNoErrorsNotIgnoreUnknown
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
@Test
public void bindingNoErrorsNotIgnoreUnknown() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.initDirectFieldAccess();
binder.setIgnoreUnknownFields(false);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
pvs.addPropertyValue(new PropertyValue("age", new Integer(32)));
pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue"));
try {
binder.bind(pvs);
fail("Should have thrown NotWritablePropertyException");
}
catch (NotWritablePropertyException ex) {
// expected
}
}
示例14: nestedBindingWithDefaultConversionNoErrors
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
@Test
public void nestedBindingWithDefaultConversionNoErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
assertTrue(binder.isIgnoreUnknownFields());
binder.initDirectFieldAccess();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry"));
pvs.addPropertyValue(new PropertyValue("spouse.jedi", "on"));
binder.bind(pvs);
binder.close();
assertEquals("Kerry", rod.getSpouse().getName());
assertTrue((rod.getSpouse()).isJedi());
}
示例15: testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory
import org.springframework.beans.PropertyValue; //導入依賴的package包/類
@Test
public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() {
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
GenericApplicationContext childAc = new GenericApplicationContext(ac);
// Create a child factory with a bean that should be woven
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.getPropertyValues().addPropertyValue(new PropertyValue("name", "Adrian"))
.addPropertyValue(new PropertyValue("age", new Integer(34)));
childAc.registerBeanDefinition("adrian2", bd);
// Register the advisor auto proxy creator with subclass
childAc.registerBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class.getName(), new RootBeanDefinition(
AnnotationAwareAspectJAutoProxyCreator.class));
childAc.refresh();
ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2");
//testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian"));
doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved);
}