Java Code Examples for org.springframework.beans.PropertyValue#getValue()

The following examples show how to use org.springframework.beans.PropertyValue#getValue() . 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: BeanComponentDefinition.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Create a new BeanComponentDefinition for the given bean.
 * @param beanDefinitionHolder the BeanDefinitionHolder encapsulating
 * the bean definition as well as the name of the bean
 */
public BeanComponentDefinition(BeanDefinitionHolder beanDefinitionHolder) {
	super(beanDefinitionHolder);

	List<BeanDefinition> innerBeans = new ArrayList<>();
	List<BeanReference> references = new ArrayList<>();
	PropertyValues propertyValues = beanDefinitionHolder.getBeanDefinition().getPropertyValues();
	for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
		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[0]);
	this.beanReferences = references.toArray(new BeanReference[0]);
}
 
Example 2
Source File: BeanComponentDefinition.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create a new BeanComponentDefinition for the given bean.
 * @param beanDefinitionHolder the BeanDefinitionHolder encapsulating
 * the bean definition as well as the name of the bean
 */
public BeanComponentDefinition(BeanDefinitionHolder beanDefinitionHolder) {
	super(beanDefinitionHolder);

	List<BeanDefinition> innerBeans = new ArrayList<>();
	List<BeanReference> references = new ArrayList<>();
	PropertyValues propertyValues = beanDefinitionHolder.getBeanDefinition().getPropertyValues();
	for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
		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[0]);
	this.beanReferences = references.toArray(new BeanReference[0]);
}
 
Example 3
Source File: UifBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Retrieves the expression graph map set on the bean with given name. If the bean has not been processed
 * by the bean factory post processor, that is done before retrieving the map
 *
 * @param parentBeanName name of the parent bean to retrieve map for (if empty a new map will be returned)
 * @param beanFactory bean factory to retrieve bean definition from
 * @param processedBeanNames set of bean names that have been processed so far
 * @return expression graph map from parent or new instance
 */
protected Map<String, String> getExpressionGraphFromParent(String parentBeanName,
        ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) {
    Map<String, String> expressionGraph = new HashMap<String, String>();
    if (StringUtils.isBlank(parentBeanName) || !beanFactory.containsBeanDefinition(parentBeanName)) {
        return expressionGraph;
    }

    BeanDefinition beanDefinition = beanFactory.getBeanDefinition(parentBeanName);
    if (!processedBeanNames.contains(parentBeanName)) {
        processBeanDefinition(parentBeanName, beanDefinition, beanFactory, processedBeanNames);
    }

    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    PropertyValue propertyExpressionsPV = pvs.getPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH);
    if (propertyExpressionsPV != null) {
        Object value = propertyExpressionsPV.getValue();
        if ((value != null) && (value instanceof ManagedMap)) {
            expressionGraph.putAll((ManagedMap) value);
        }
    }

    return expressionGraph;
}
 
Example 4
Source File: BeanComponentDefinition.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
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()]);
}
 
Example 5
Source File: MessageBeanProcessor.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Attempts to find a property value for the given property name within the bean definition, if the property
 * does not exist in the bean and there is a parent, the parent is checked for containing the property. This
 * continues until a property value is found or all the parents have been traversed
 *
 * @param beanDefinition bean definition to find property value in
 * @param propertyName name of the property to find the value for
 * @return String value for property in the bean definition or null if the property was not found
 */
protected String findPropertyValueInBeanDefinition(BeanDefinition beanDefinition, String propertyName) {
    String beanPropertyValue = null;

    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    if (pvs.contains(propertyName)) {
        PropertyValue propertyValue = pvs.getPropertyValue(propertyName);
        if (propertyValue.getValue() != null) {
            beanPropertyValue = propertyValue.getValue().toString();
        }
    } else {
        if (StringUtils.isNotBlank(beanDefinition.getParentName())) {
            BeanDefinition parentBeanDefinition = beanFactory.getBeanDefinition(beanDefinition.getParentName());

            beanPropertyValue = findPropertyValueInBeanDefinition(parentBeanDefinition, propertyName);
        }
    }

    return beanPropertyValue;
}
 
Example 6
Source File: MapperScannerConfigurer.java    From Mapper with MIT License 6 votes vote down vote up
private String updatePropertyValue(String propertyName, PropertyValues values) {
    PropertyValue property = values.getPropertyValue(propertyName);

    if (property == null) {
        return null;
    }

    Object value = property.getValue();

    if (value == null) {
        return null;
    } else if (value instanceof String) {
        return value.toString();
    } else if (value instanceof TypedStringValue) {
        return ((TypedStringValue) value).getValue();
    } else {
        return null;
    }
}
 
Example 7
Source File: BeanComponentDefinition.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
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()]);
}
 
Example 8
Source File: ZebraMapperScannerConfigurer.java    From Zebra with Apache License 2.0 6 votes vote down vote up
private String updatePropertyValue(String propertyName, PropertyValues values) {
	PropertyValue property = values.getPropertyValue(propertyName);

	if (property == null) {
		return null;
	}

	Object value = property.getValue();

	if (value == null) {
		return null;
	} else if (value instanceof String) {
		return value.toString();
	} else if (value instanceof TypedStringValue) {
		return ((TypedStringValue) value).getValue();
	} else {
		return null;
	}
}
 
Example 9
Source File: DataDictionary.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Returns a property value for the bean with the given name from the dictionary.
 *
 * @param beanName id or name for the bean definition
 * @param propertyName name of the property to retrieve, must be a valid property configured on
 * the bean definition
 * @return Object property value for property
 */
public Object getDictionaryBeanProperty(String beanName, String propertyName) {
    Object bean = ddBeans.getSingleton(beanName);
    if (bean != null) {
        return ObjectPropertyUtils.getPropertyValue(bean, propertyName);
    }

    BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName);

    if (beanDefinition == null) {
        throw new RuntimeException("Unable to get bean for bean name: " + beanName);
    }

    PropertyValues pvs = beanDefinition.getPropertyValues();
    if (pvs.contains(propertyName)) {
        PropertyValue propertyValue = pvs.getPropertyValue(propertyName);

        Object value;
        if (propertyValue.isConverted()) {
            value = propertyValue.getConvertedValue();
        } else if (propertyValue.getValue() instanceof String) {
            String unconvertedValue = (String) propertyValue.getValue();
            Scope scope = ddBeans.getRegisteredScope(beanDefinition.getScope());
            BeanExpressionContext beanExpressionContext = new BeanExpressionContext(ddBeans, scope);

            value = ddBeans.getBeanExpressionResolver().evaluate(unconvertedValue, beanExpressionContext);
        } else {
            value = propertyValue.getValue();
        }

        return value;
    }

    return null;
}
 
Example 10
Source File: MessageBeanProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Applies the text for a given message to the associated bean definition property
 *
 * @param message message instance to apply
 * @param beanDefinition bean definition the message should be applied to
 * @param beanClass class for the bean definition
 */
protected void applyMessageToBean(Message message, BeanDefinition beanDefinition, Class<?> beanClass) {
    String key = message.getKey().trim();

    // if message doesn't start with path indicator, it will be an explicit key that is matched when
    // iterating over the property values, so we will just return in that case
    if (!key.startsWith(KRADConstants.MESSAGE_KEY_PATH_INDICATOR)) {
        return;
    }

    // if here dealing with a path key, strip off indicator and then process as a property path
    key = StringUtils.stripStart(key, KRADConstants.MESSAGE_KEY_PATH_INDICATOR);

    // list factory beans just have the one list property (with no name)
    if (ListFactoryBean.class.isAssignableFrom(beanClass)) {
        MutablePropertyValues pvs = beanDefinition.getPropertyValues();

        PropertyValue propertyValue = pvs.getPropertyValueList().get(0);
        List<?> listValue = (List<?>) propertyValue.getValue();

        applyMessageToNestedListBean(message, listValue, key);
    } else if (StringUtils.contains(key, ".")) {
        applyMessageToNestedBean(message, beanDefinition, key);
    } else {
        applyMessageTextToPropertyValue(key, message.getText(), beanDefinition);
    }
}
 
Example 11
Source File: GrailsDataBinder.java    From AlgoTrader with GNU General Public License v2.0 5 votes vote down vote up
private String getStringValue(PropertyValue yearProperty) {
	Object value = yearProperty.getValue();
	if (value == null)
		return null;

	if (value.getClass().isArray()) {
		return ((String[]) value)[0];
	}

	return (String) value;
}
 
Example 12
Source File: GrailsDataBinder.java    From AlgoTrader with GNU General Public License v2.0 5 votes vote down vote up
private void filterNestedParameterMaps(MutablePropertyValues mpvs) {
	for (PropertyValue pv : mpvs.getPropertyValues()) {
		final Object value = pv.getValue();
		if (isNotCandidateForBinding(value)) {
			mpvs.removePropertyValue(pv);
		}
	}
}
 
Example 13
Source File: TransactionConfigDefinitionValidator.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	String[] beanNameArray = beanFactory.getBeanDefinitionNames();
	for (int i = 0; i < beanNameArray.length; i++) {
		String beanName = beanNameArray[i];
		BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
		String beanClassName = beanDef.getBeanClassName();

		if (org.springframework.transaction.interceptor.TransactionProxyFactoryBean.class.getName().equals(beanClassName)) {
			throw new FatalBeanException(String.format(
					"Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).",
					beanName));
		}

		if (org.springframework.transaction.interceptor.TransactionInterceptor.class.getName().equals(beanClassName)) {
			boolean errorExists = true;

			MutablePropertyValues mpv = beanDef.getPropertyValues();
			PropertyValue pv = mpv.getPropertyValue("transactionAttributeSource");
			Object value = pv == null ? null : pv.getValue();
			if (value != null && RuntimeBeanReference.class.isInstance(value)) {
				RuntimeBeanReference reference = (RuntimeBeanReference) value;
				BeanDefinition refBeanDef = beanFactory.getBeanDefinition(reference.getBeanName());
				String refBeanClassName = refBeanDef.getBeanClassName();
				errorExists = AnnotationTransactionAttributeSource.class.getName().equals(refBeanClassName) == false;
			}

			if (errorExists) {
				throw new FatalBeanException(String.format(
						"Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).",
						beanName));
			} // end-if (errorExists)
		}

	} // end-for (int i = 0; i < beanNameArray.length; i++)
}
 
Example 14
Source File: SpringValueDefinitionProcessor.java    From apollo with Apache License 2.0 5 votes vote down vote up
private void processPropertyValues(BeanDefinitionRegistry beanRegistry) {
  if (!PROPERTY_VALUES_PROCESSED_BEAN_FACTORIES.add(beanRegistry)) {
    // already initialized
    return;
  }

  if (!beanName2SpringValueDefinitions.containsKey(beanRegistry)) {
    beanName2SpringValueDefinitions.put(beanRegistry, LinkedListMultimap.<String, SpringValueDefinition>create());
  }

  Multimap<String, SpringValueDefinition> springValueDefinitions = beanName2SpringValueDefinitions.get(beanRegistry);

  String[] beanNames = beanRegistry.getBeanDefinitionNames();
  for (String beanName : beanNames) {
    BeanDefinition beanDefinition = beanRegistry.getBeanDefinition(beanName);
    MutablePropertyValues mutablePropertyValues = beanDefinition.getPropertyValues();
    List<PropertyValue> propertyValues = mutablePropertyValues.getPropertyValueList();
    for (PropertyValue propertyValue : propertyValues) {
      Object value = propertyValue.getValue();
      if (!(value instanceof TypedStringValue)) {
        continue;
      }
      String placeholder = ((TypedStringValue) value).getValue();
      Set<String> keys = placeholderHelper.extractPlaceholderKeys(placeholder);

      if (keys.isEmpty()) {
        continue;
      }

      for (String key : keys) {
        springValueDefinitions.put(beanName, new SpringValueDefinition(key, placeholder, propertyValue.getName()));
      }
    }
  }
}
 
Example 15
Source File: GrailsDataBinder.java    From AlgoTrader with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void bindCollectionAssociation(MutablePropertyValues mpvs, PropertyValue pv) {
	Object v = pv.getValue();

	Collection collection = (Collection) this.bean.getPropertyValue(pv.getName());
	collection.clear();
	final Class associatedType = getReferencedTypeForCollection(pv.getName(), getTarget());
	final boolean isArray = v != null && v.getClass().isArray();
	final PropertyEditor propertyEditor = findCustomEditor(collection.getClass(), pv.getName());
	if (propertyEditor == null) {
		if (isDomainAssociation(associatedType)) {
			if (isArray) {
				Object[] identifiers = (Object[]) v;
				for (Object id : identifiers) {
					if (id != null) {
						associateObjectForId(pv, id, associatedType);
					}
				}
				mpvs.removePropertyValue(pv);
			} else if (v != null && (v instanceof String)) {
				associateObjectForId(pv, v, associatedType);
				mpvs.removePropertyValue(pv);
			}
		} else if (GrailsDomainConfigurationUtil.isBasicType(associatedType)) {
			if (isArray) {
				Object[] values = (Object[]) v;
				List list = collection instanceof List ? (List) collection : null;
				for (int i = 0; i < values.length; i++) {
					Object value = values[i];
					try {
						Object newValue = getTypeConverter().convertIfNecessary(value, associatedType);
						if (list != null) {
							if (i > list.size() - 1) {
								list.add(i, newValue);
							} else {
								list.set(i, newValue);
							}
						} else {
							collection.add(newValue);
						}
					} catch (TypeMismatchException e) {
						// ignore
					}
				}
			}
		}
	}
}
 
Example 16
Source File: OriginCapablePropertyValue.java    From canal with Apache License 2.0 4 votes vote down vote up
OriginCapablePropertyValue(PropertyValue propertyValue){
    this(propertyValue.getName(),
        propertyValue.getValue(),
        (PropertyOrigin) propertyValue.getAttribute(ATTRIBUTE_PROPERTY_ORIGIN));
}
 
Example 17
Source File: TransactionBeanConfigValidator.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void validateReferenceConfig(String beanName, BeanDefinition beanDef) throws BeansException {
	MutablePropertyValues mpv = beanDef.getPropertyValues();
	PropertyValue group = mpv.getPropertyValue("group");
	PropertyValue retries = mpv.getPropertyValue("retries");
	PropertyValue loadbalance = mpv.getPropertyValue("loadbalance");
	PropertyValue cluster = mpv.getPropertyValue("cluster");
	PropertyValue filter = mpv.getPropertyValue("filter");

	String filterValue = filter == null || filter.getValue() == null ? null : String.valueOf(filter.getValue());
	String[] filterArray = filter == null ? new String[0] : filterValue.split("\\s*,\\s*");

	if (group == null || group.getValue() == null //
			|| ("x-bytejta".equals(group.getValue())
					|| String.valueOf(group.getValue()).startsWith("x-bytejta-")) == false) {
		throw new FatalBeanException(String.format(
				"The value of attr 'group'(beanId= %s) should be 'x-bytejta' or starts with 'x-bytejta-'.", beanName));
	} else if (retries == null || retries.getValue() == null || "-1".equals(retries.getValue()) == false) {
		throw new FatalBeanException(String.format("The value of attr 'retries'(beanId= %s) should be '-1'.", beanName));
	} else if (loadbalance == null || loadbalance.getValue() == null || "bytejta".equals(loadbalance.getValue()) == false) {
		throw new FatalBeanException(
				String.format("The value of attr 'loadbalance'(beanId= %s) should be 'bytejta'.", beanName));
	} else if (cluster == null || cluster.getValue() == null || "failfast".equals(cluster.getValue()) == false) {
		throw new FatalBeanException(
				String.format("The value of attribute 'cluster' (beanId= %s) must be 'failfast'.", beanName));
	} else if (filter == null || filter.getValue() == null || String.class.isInstance(filter.getValue()) == false) {
		throw new FatalBeanException(String
				.format("The value of attr 'filter'(beanId= %s) must be java.lang.String and cannot be null.", beanName));
	} else if (StringUtils.equalsIgnoreCase(filterArray[filterArray.length - 1], "bytejta") == false) {
		throw new FatalBeanException(
				String.format("The last value of attr 'filter'(beanId= %s) should be 'bytejta'.", beanName));
	}

	PropertyValue pv = mpv.getPropertyValue("interface");
	String clazzName = String.valueOf(pv.getValue());
	ClassLoader cl = Thread.currentThread().getContextClassLoader();

	Class<?> clazz = null;
	try {
		clazz = cl.loadClass(clazzName);
	} catch (Exception ex) {
		throw new FatalBeanException(String.format("Cannot load class %s.", clazzName));
	}

	Method[] methodArray = clazz.getMethods();
	for (int i = 0; i < methodArray.length; i++) {
		Method method = methodArray[i];
		boolean declared = false;
		Class<?>[] exceptionTypeArray = method.getExceptionTypes();
		for (int j = 0; j < exceptionTypeArray.length; j++) {
			Class<?> exceptionType = exceptionTypeArray[j];
			if (RemotingException.class.isAssignableFrom(exceptionType)) {
				declared = true;
				break;
			}
		}

		if (declared == false) {
			logger.warn("The remote call method({}) should be declared to throw a remote exception: {}!", method,
					RemotingException.class.getName());
		}

	}

}
 
Example 18
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);
}
 
Example 19
Source File: LegacyConfigPostProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Given a bean name (assumed to implement {@link org.springframework.core.io.support.PropertiesLoaderSupport})
 * checks whether it already references the <code>global-properties</code> bean. If not, 'upgrades' the bean by
 * appending all additional resources it mentions in its <code>locations</code> property to
 * <code>globalPropertyLocations</code>, except for those resources mentioned in <code>newLocations</code>. A
 * reference to <code>global-properties</code> will then be added and the resource list in
 * <code>newLocations<code> will then become the new <code>locations</code> list for the bean.
 * 
 * @param beanFactory
 *            the bean factory
 * @param globalPropertyLocations
 *            the list of global property locations to be appended to
 * @param beanName
 *            the bean name
 * @param newLocations
 *            the new locations to be set on the bean
 * @return the mutable property values
 */
@SuppressWarnings("unchecked")
private MutablePropertyValues processLocations(ConfigurableListableBeanFactory beanFactory,
        Collection<Object> globalPropertyLocations, String beanName, String[] newLocations)
{
    // Get the bean an check its existing properties value
    MutablePropertyValues beanProperties = beanFactory.getBeanDefinition(beanName).getPropertyValues();
    PropertyValue pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES);
    Object value;

    // If the properties value already references the global-properties bean, we have nothing else to do. Otherwise,
    // we have to 'upgrade' the bean definition.
    if (pv == null || (value = pv.getValue()) == null || !(value instanceof BeanReference)
            || ((BeanReference) value).getBeanName().equals(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES))
    {
        // Convert the array of new locations to a managed list of type string values, so that it is
        // compatible with a bean definition
        Collection<Object> newLocationList = new ManagedList(newLocations.length);
        if (newLocations != null && newLocations.length > 0)
        {
            for (String preserveLocation : newLocations)
            {
                newLocationList.add(new TypedStringValue(preserveLocation));
            }
        }

        // If there is currently a locations list, process it
        pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
        if (pv != null && (value = pv.getValue()) != null && value instanceof Collection)
        {
            Collection<Object> locations = (Collection<Object>) value;

            // Compute the set of locations that need to be added to globalPropertyLocations (preserving order) and
            // warn about each
            Set<Object> addedLocations = new LinkedHashSet<Object>(locations);
            addedLocations.removeAll(globalPropertyLocations);
            addedLocations.removeAll(newLocationList);

            for (Object location : addedLocations)
            {
                LegacyConfigPostProcessor.logger.warn("Legacy configuration detected: adding "
                        + (location instanceof TypedStringValue ? ((TypedStringValue) location).getValue()
                                : location.toString()) + " to global-properties definition");
                globalPropertyLocations.add(location);
            }

        }
        // Ensure the bean now references global-properties
        beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES, new RuntimeBeanReference(
                LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES));

        // Ensure the new location list is now set on the bean
        if (newLocationList.size() > 0)
        {
            beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS, newLocationList);
        }
        else
        {
            beanProperties.removePropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
        }
    }
    return beanProperties;
}
 
Example 20
Source File: OriginCapablePropertyValue.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
OriginCapablePropertyValue(PropertyValue propertyValue){
    this(propertyValue.getName(),
        propertyValue.getValue(),
        (PropertyOrigin) propertyValue.getAttribute(ATTRIBUTE_PROPERTY_ORIGIN));
}