org.springframework.beans.SimpleTypeConverter Java Examples

The following examples show how to use org.springframework.beans.SimpleTypeConverter. 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: DirectFieldAccessor.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new DirectFieldAccessor for the given target object.
 * @param target the target object to access
 */
public DirectFieldAccessor(final Object target) {
	Assert.notNull(target, "Target object must not be null");
	this.target = target;
	ReflectionUtils.doWithFields(this.target.getClass(), new ReflectionUtils.FieldCallback() {
		public void doWith(Field field) {
			// jlm - FIX SPR-8398: avoid to overwrite shadowed fileds
			if (!fieldMap.containsKey(field.getName())) {
				fieldMap.put(field.getName(), field);
			}
		}
	});
	this.typeConverterDelegate = new SimpleTypeConverter();
	registerDefaultEditors();
	setExtractOldValueForEditor(true);
}
 
Example #2
Source File: BindConverter.java    From spring-cloud-gray with Apache License 2.0 6 votes vote down vote up
private PropertyEditor getPropertyEditor(Class<?> type) {
    SimpleTypeConverter typeConverter = this.typeConverter;
    if (type == null || type == Object.class
            || Collection.class.isAssignableFrom(type)
            || Map.class.isAssignableFrom(type)) {
        return null;
    }
    PropertyEditor editor = typeConverter.getDefaultEditor(type);
    if (editor == null) {
        editor = typeConverter.findCustomEditor(type, null);
    }
    if (editor == null && String.class != type) {
        editor = BeanUtils.findEditorByConvention(type);
    }
    if (editor == null || EXCLUDED_EDITORS.contains(editor.getClass())) {
        return null;
    }
    return editor;
}
 
Example #3
Source File: AbstractEndpointConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
/**
 * Gets properly typed method argument.
 * @param parameterType
 * @param value
 * @return
 */
private <T> T getMethodArgument(Class<T> parameterType, Object value) {
    if (parameterType.isInstance(value)) {
        return parameterType.cast(value);
    }

    try {
        return new SimpleTypeConverter().convertIfNecessary(value, parameterType);
    } catch (ConversionNotSupportedException e) {
        if (String.class.equals(parameterType)) {
            return (T) String.valueOf(value);
        }

        throw new ApplicationRuntimeException("Unable to convert method argument type", e);
    }
}
 
Example #4
Source File: AbstractTestActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
/**
 * Gets properly typed method argument.
 * @param parameterType
 * @param value
 * @return
 */
private <T> T getMethodArgument(Class<T> parameterType, Object value) {
    if (parameterType.isInstance(value)) {
        return parameterType.cast(value);
    }

    try {
        return new SimpleTypeConverter().convertIfNecessary(value, parameterType);
    } catch (ConversionNotSupportedException e) {
        if (String.class.equals(parameterType)) {
            return (T) String.valueOf(value);
        }

        throw new ApplicationRuntimeException("Unable to convert method argument type", e);
    }
}
 
Example #5
Source File: QualifierAnnotationAutowireCandidateResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Match the given qualifier annotations against the candidate bean definition.
 */
protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) {
	if (ObjectUtils.isEmpty(annotationsToSearch)) {
		return true;
	}
	SimpleTypeConverter typeConverter = new SimpleTypeConverter();
	for (Annotation annotation : annotationsToSearch) {
		Class<? extends Annotation> type = annotation.annotationType();
		boolean checkMeta = true;
		boolean fallbackToMeta = false;
		if (isQualifier(type)) {
			if (!checkQualifier(bdHolder, annotation, typeConverter)) {
				fallbackToMeta = true;
			}
			else {
				checkMeta = false;
			}
		}
		if (checkMeta) {
			boolean foundMeta = false;
			for (Annotation metaAnn : type.getAnnotations()) {
				Class<? extends Annotation> metaType = metaAnn.annotationType();
				if (isQualifier(metaType)) {
					foundMeta = true;
					// Only accept fallback match if @Qualifier annotation has a value...
					// Otherwise it is just a marker for a custom qualifier annotation.
					if ((fallbackToMeta && StringUtils.isEmpty(AnnotationUtils.getValue(metaAnn))) ||
							!checkQualifier(bdHolder, metaAnn, typeConverter)) {
						return false;
					}
				}
			}
			if (fallbackToMeta && !foundMeta) {
				return false;
			}
		}
	}
	return true;
}
 
Example #6
Source File: AbstractBeanFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypeConverter getTypeConverter() {
	TypeConverter customConverter = getCustomTypeConverter();
	if (customConverter != null) {
		return customConverter;
	}
	else {
		// Build default TypeConverter, registering custom editors.
		SimpleTypeConverter typeConverter = new SimpleTypeConverter();
		typeConverter.setConversionService(getConversionService());
		registerCustomEditors(typeConverter);
		return typeConverter;
	}
}
 
Example #7
Source File: DataBinder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return this binder's underlying SimpleTypeConverter.
 */
protected SimpleTypeConverter getSimpleTypeConverter() {
	if (this.typeConverter == null) {
		this.typeConverter = new SimpleTypeConverter();
		if (this.conversionService != null) {
			this.typeConverter.setConversionService(this.conversionService);
		}
	}
	return this.typeConverter;
}
 
Example #8
Source File: AbstractFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtain a bean type converter from the BeanFactory that this bean
 * runs in. This is typically a fresh instance for each call,
 * since TypeConverters are usually <i>not</i> thread-safe.
 * <p>Falls back to a SimpleTypeConverter when not running in a BeanFactory.
 * @see ConfigurableBeanFactory#getTypeConverter()
 * @see org.springframework.beans.SimpleTypeConverter
 */
protected TypeConverter getBeanTypeConverter() {
	BeanFactory beanFactory = getBeanFactory();
	if (beanFactory instanceof ConfigurableBeanFactory) {
		return ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
	}
	else {
		return new SimpleTypeConverter();
	}
}
 
Example #9
Source File: QualifierAnnotationAutowireCandidateResolver.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Match the given qualifier annotations against the candidate bean definition.
 */
protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) {
	if (ObjectUtils.isEmpty(annotationsToSearch)) {
		return true;
	}
	SimpleTypeConverter typeConverter = new SimpleTypeConverter();
	for (Annotation annotation : annotationsToSearch) {
		Class<? extends Annotation> type = annotation.annotationType();
		boolean checkMeta = true;
		boolean fallbackToMeta = false;
		if (isQualifier(type)) {
			if (!checkQualifier(bdHolder, annotation, typeConverter)) {
				fallbackToMeta = true;
			}
			else {
				checkMeta = false;
			}
		}
		if (checkMeta) {
			boolean foundMeta = false;
			for (Annotation metaAnn : type.getAnnotations()) {
				Class<? extends Annotation> metaType = metaAnn.annotationType();
				if (isQualifier(metaType)) {
					foundMeta = true;
					// Only accept fallback match if @Qualifier annotation has a value...
					// Otherwise it is just a marker for a custom qualifier annotation.
					if ((fallbackToMeta && StringUtils.isEmpty(AnnotationUtils.getValue(metaAnn))) ||
							!checkQualifier(bdHolder, metaAnn, typeConverter)) {
						return false;
					}
				}
			}
			if (fallbackToMeta && !foundMeta) {
				return false;
			}
		}
	}
	return true;
}
 
Example #10
Source File: AbstractBeanFactory.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
@Override
public TypeConverter getTypeConverter() {
	TypeConverter customConverter = getCustomTypeConverter();
	if (customConverter != null) {
		return customConverter;
	}
	else {
		// Build default TypeConverter, registering custom editors.
		SimpleTypeConverter typeConverter = new SimpleTypeConverter();
		typeConverter.setConversionService(getConversionService());
		registerCustomEditors(typeConverter);
		return typeConverter;
	}
}
 
Example #11
Source File: AbstractFactoryBean.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain a bean type converter from the BeanFactory that this bean
 * runs in. This is typically a fresh instance for each call,
 * since TypeConverters are usually <i>not</i> thread-safe.
 * <p>Falls back to a SimpleTypeConverter when not running in a BeanFactory.
 * @see ConfigurableBeanFactory#getTypeConverter()
 * @see org.springframework.beans.SimpleTypeConverter
 */
protected TypeConverter getBeanTypeConverter() {
	BeanFactory beanFactory = getBeanFactory();
	if (beanFactory instanceof ConfigurableBeanFactory) {
		return ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
	}
	else {
		return new SimpleTypeConverter();
	}
}
 
Example #12
Source File: DataBinder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return this binder's underlying SimpleTypeConverter.
 */
protected SimpleTypeConverter getSimpleTypeConverter() {
	if (this.typeConverter == null) {
		this.typeConverter = new SimpleTypeConverter();
		if (this.conversionService != null) {
			this.typeConverter.setConversionService(this.conversionService);
		}
	}
	return this.typeConverter;
}
 
Example #13
Source File: JndiObjectFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Look up the JNDI object and store it.
 */
@Override
public void afterPropertiesSet() throws IllegalArgumentException, NamingException {
	super.afterPropertiesSet();

	if (this.proxyInterfaces != null || !this.lookupOnStartup || !this.cache || this.exposeAccessContext) {
		// We need to create a proxy for this...
		if (this.defaultObject != null) {
			throw new IllegalArgumentException(
					"'defaultObject' is not supported in combination with 'proxyInterface'");
		}
		// We need a proxy and a JndiObjectTargetSource.
		this.jndiObject = JndiObjectProxyFactory.createJndiObjectProxy(this);
	}
	else {
		if (this.defaultObject != null && getExpectedType() != null &&
				!getExpectedType().isInstance(this.defaultObject)) {
			TypeConverter converter = (this.beanFactory != null ?
					this.beanFactory.getTypeConverter() : new SimpleTypeConverter());
			try {
				this.defaultObject = converter.convertIfNecessary(this.defaultObject, getExpectedType());
			}
			catch (TypeMismatchException ex) {
				throw new IllegalArgumentException("Default object [" + this.defaultObject + "] of type [" +
						this.defaultObject.getClass().getName() + "] is not of expected type [" +
						getExpectedType().getName() + "] and cannot be converted either", ex);
			}
		}
		// Locate specified JNDI object.
		this.jndiObject = lookupWithFallback();
	}
}
 
Example #14
Source File: BeanFactoryTypeConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
	if (beanFactory instanceof ConfigurableBeanFactory) {
		Object typeConverter = ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
		if (typeConverter instanceof SimpleTypeConverter) {
			delegate = (SimpleTypeConverter) typeConverter;
		}
	}
}
 
Example #15
Source File: QualifierAnnotationAutowireCandidateResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Match the given qualifier annotations against the candidate bean definition.
 */
protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) {
	if (ObjectUtils.isEmpty(annotationsToSearch)) {
		return true;
	}
	SimpleTypeConverter typeConverter = new SimpleTypeConverter();
	for (Annotation annotation : annotationsToSearch) {
		Class<? extends Annotation> type = annotation.annotationType();
		boolean checkMeta = true;
		boolean fallbackToMeta = false;
		if (isQualifier(type)) {
			if (!checkQualifier(bdHolder, annotation, typeConverter)) {
				fallbackToMeta = true;
			}
			else {
				checkMeta = false;
			}
		}
		if (checkMeta) {
			boolean foundMeta = false;
			for (Annotation metaAnn : type.getAnnotations()) {
				Class<? extends Annotation> metaType = metaAnn.annotationType();
				if (isQualifier(metaType)) {
					foundMeta = true;
					// Only accept fallback match if @Qualifier annotation has a value...
					// Otherwise it is just a marker for a custom qualifier annotation.
					if ((fallbackToMeta && StringUtils.isEmpty(AnnotationUtils.getValue(metaAnn))) ||
							!checkQualifier(bdHolder, metaAnn, typeConverter)) {
						return false;
					}
				}
			}
			if (fallbackToMeta && !foundMeta) {
				return false;
			}
		}
	}
	return true;
}
 
Example #16
Source File: AbstractBeanFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public TypeConverter getTypeConverter() {
	TypeConverter customConverter = getCustomTypeConverter();
	if (customConverter != null) {
		return customConverter;
	}
	else {
		// Build default TypeConverter, registering custom editors.
		SimpleTypeConverter typeConverter = new SimpleTypeConverter();
		typeConverter.setConversionService(getConversionService());
		registerCustomEditors(typeConverter);
		return typeConverter;
	}
}
 
Example #17
Source File: AbstractFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain a bean type converter from the BeanFactory that this bean
 * runs in. This is typically a fresh instance for each call,
 * since TypeConverters are usually <i>not</i> thread-safe.
 * <p>Falls back to a SimpleTypeConverter when not running in a BeanFactory.
 * @see ConfigurableBeanFactory#getTypeConverter()
 * @see org.springframework.beans.SimpleTypeConverter
 */
protected TypeConverter getBeanTypeConverter() {
	BeanFactory beanFactory = getBeanFactory();
	if (beanFactory instanceof ConfigurableBeanFactory) {
		return ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
	}
	else {
		return new SimpleTypeConverter();
	}
}
 
Example #18
Source File: RSQLUtility.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private JpqQueryRSQLVisitor(final Root<T> root, final CriteriaBuilder cb, final Class<A> enumType,
        final VirtualPropertyReplacer virtualPropertyReplacer, final Database database,
        final CriteriaQuery<?> query) {
    this.root = root;
    this.cb = cb;
    this.query = query;
    this.enumType = enumType;
    this.virtualPropertyReplacer = virtualPropertyReplacer;
    this.simpleTypeConverter = new SimpleTypeConverter();
    this.database = database;
    this.joinsNeeded = false;
}
 
Example #19
Source File: GoConfigFieldWriter.java    From gocd with Apache License 2.0 5 votes vote down vote up
public GoConfigFieldWriter(Field declaredField, Object value, SimpleTypeConverter converter, ConfigCache configCache, final ConfigElementImplementationRegistry registry) {
    this.configField = declaredField;
    this.value = value;
    this.configField.setAccessible(true);
    this.typeConverter = converter;
    this.configCache = configCache;
    this.registry = registry;
}
 
Example #20
Source File: ConfigurationParameterFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a value so it can be injected into a UIMA component. UIMA only supports several
 * parameter types. If the value is not of these types, this method can be used to coerce the
 * value into a supported type (typically String). It is also used to convert primitive arrays to
 * object arrays when necessary.
 * 
 * @param param
 *          the configuration parameter.
 * @param aValue
 *          the parameter value.
 * @return the converted value.
 */
protected static Object convertParameterValue(ConfigurationParameter param, Object aValue) {
  Object value = aValue;
  if (value.getClass().isArray()
          && value.getClass().getComponentType().getName().equals("boolean")) {
    value = ArrayUtils.toObject((boolean[]) value);
  } else if (value.getClass().isArray()
          && value.getClass().getComponentType().getName().equals("int")) {
    value = ArrayUtils.toObject((int[]) value);
  } else if (value.getClass().isArray()
          && value.getClass().getComponentType().getName().equals("float")) {
    value = ArrayUtils.toObject((float[]) value);
  } else {
    try {
      if (param.getType().equals(ConfigurationParameter.TYPE_STRING)) {
        SimpleTypeConverter converter = new SimpleTypeConverter();
        PropertyEditorUtil.registerUimaFITEditors(converter);
        if (value.getClass().isArray() || value instanceof Collection) {
          value = converter.convertIfNecessary(value, String[].class);
        } else {
          value = converter.convertIfNecessary(value, String.class);
        }
      }
    } catch (TypeMismatchException e) {
      throw new IllegalArgumentException(e.getMessage(), e);
    }
  }

  return value;
}
 
Example #21
Source File: BeanFactoryTypeConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
	if (beanFactory instanceof ConfigurableBeanFactory) {
		Object typeConverter = ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
		if (typeConverter instanceof SimpleTypeConverter) {
			delegate = (SimpleTypeConverter) typeConverter;
		}
	}
}
 
Example #22
Source File: JndiObjectFactoryBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Look up the JNDI object and store it.
 */
@Override
public void afterPropertiesSet() throws IllegalArgumentException, NamingException {
	super.afterPropertiesSet();

	if (this.proxyInterfaces != null || !this.lookupOnStartup || !this.cache || this.exposeAccessContext) {
		// We need to create a proxy for this...
		if (this.defaultObject != null) {
			throw new IllegalArgumentException(
					"'defaultObject' is not supported in combination with 'proxyInterface'");
		}
		// We need a proxy and a JndiObjectTargetSource.
		this.jndiObject = JndiObjectProxyFactory.createJndiObjectProxy(this);
	}
	else {
		if (this.defaultObject != null && getExpectedType() != null &&
				!getExpectedType().isInstance(this.defaultObject)) {
			TypeConverter converter = (this.beanFactory != null ?
					this.beanFactory.getTypeConverter() : new SimpleTypeConverter());
			try {
				this.defaultObject = converter.convertIfNecessary(this.defaultObject, getExpectedType());
			}
			catch (TypeMismatchException ex) {
				throw new IllegalArgumentException("Default object [" + this.defaultObject + "] of type [" +
						this.defaultObject.getClass().getName() + "] is not of expected type [" +
						getExpectedType().getName() + "] and cannot be converted either", ex);
			}
		}
		// Locate specified JNDI object.
		this.jndiObject = lookupWithFallback();
	}
}
 
Example #23
Source File: BeanFactoryTypeConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
	if (beanFactory instanceof ConfigurableBeanFactory) {
		Object typeConverter = ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
		if (typeConverter instanceof SimpleTypeConverter) {
			delegate = (SimpleTypeConverter) typeConverter;
		}
	}
}
 
Example #24
Source File: QualifierAnnotationAutowireCandidateResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Match the given qualifier annotations against the candidate bean definition.
 */
protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) {
	if (ObjectUtils.isEmpty(annotationsToSearch)) {
		return true;
	}
	SimpleTypeConverter typeConverter = new SimpleTypeConverter();
	for (Annotation annotation : annotationsToSearch) {
		Class<? extends Annotation> type = annotation.annotationType();
		boolean checkMeta = true;
		boolean fallbackToMeta = false;
		if (isQualifier(type)) {
			if (!checkQualifier(bdHolder, annotation, typeConverter)) {
				fallbackToMeta = true;
			}
			else {
				checkMeta = false;
			}
		}
		if (checkMeta) {
			boolean foundMeta = false;
			for (Annotation metaAnn : type.getAnnotations()) {
				Class<? extends Annotation> metaType = metaAnn.annotationType();
				if (isQualifier(metaType)) {
					foundMeta = true;
					// Only accept fallback match if @Qualifier annotation has a value...
					// Otherwise it is just a marker for a custom qualifier annotation.
					if ((fallbackToMeta && StringUtils.isEmpty(AnnotationUtils.getValue(metaAnn))) ||
							!checkQualifier(bdHolder, metaAnn, typeConverter)) {
						return false;
					}
				}
			}
			if (fallbackToMeta && !foundMeta) {
				return false;
			}
		}
	}
	return true;
}
 
Example #25
Source File: AbstractBeanFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public TypeConverter getTypeConverter() {
	TypeConverter customConverter = getCustomTypeConverter();
	if (customConverter != null) {
		return customConverter;
	}
	else {
		// Build default TypeConverter, registering custom editors.
		SimpleTypeConverter typeConverter = new SimpleTypeConverter();
		typeConverter.setConversionService(getConversionService());
		registerCustomEditors(typeConverter);
		return typeConverter;
	}
}
 
Example #26
Source File: AbstractFactoryBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Obtain a bean type converter from the BeanFactory that this bean
 * runs in. This is typically a fresh instance for each call,
 * since TypeConverters are usually <i>not</i> thread-safe.
 * <p>Falls back to a SimpleTypeConverter when not running in a BeanFactory.
 * @see ConfigurableBeanFactory#getTypeConverter()
 * @see org.springframework.beans.SimpleTypeConverter
 */
protected TypeConverter getBeanTypeConverter() {
	BeanFactory beanFactory = getBeanFactory();
	if (beanFactory instanceof ConfigurableBeanFactory) {
		return ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
	}
	else {
		return new SimpleTypeConverter();
	}
}
 
Example #27
Source File: DataBinder.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return this binder's underlying SimpleTypeConverter.
 */
protected SimpleTypeConverter getSimpleTypeConverter() {
	if (this.typeConverter == null) {
		this.typeConverter = new SimpleTypeConverter();
		if (this.conversionService != null) {
			this.typeConverter.setConversionService(this.conversionService);
		}
	}
	return this.typeConverter;
}
 
Example #28
Source File: JndiObjectFactoryBean.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Look up the JNDI object and store it.
 */
@Override
public void afterPropertiesSet() throws IllegalArgumentException, NamingException {
	super.afterPropertiesSet();

	if (this.proxyInterfaces != null || !this.lookupOnStartup || !this.cache || this.exposeAccessContext) {
		// We need to create a proxy for this...
		if (this.defaultObject != null) {
			throw new IllegalArgumentException(
					"'defaultObject' is not supported in combination with 'proxyInterface'");
		}
		// We need a proxy and a JndiObjectTargetSource.
		this.jndiObject = JndiObjectProxyFactory.createJndiObjectProxy(this);
	}
	else {
		if (this.defaultObject != null && getExpectedType() != null &&
				!getExpectedType().isInstance(this.defaultObject)) {
			TypeConverter converter = (this.beanFactory != null ?
					this.beanFactory.getTypeConverter() : new SimpleTypeConverter());
			try {
				this.defaultObject = converter.convertIfNecessary(this.defaultObject, getExpectedType());
			}
			catch (TypeMismatchException ex) {
				throw new IllegalArgumentException("Default object [" + this.defaultObject + "] of type [" +
						this.defaultObject.getClass().getName() + "] is not of expected type [" +
						getExpectedType().getName() + "] and cannot be converted either", ex);
			}
		}
		// Locate specified JNDI object.
		this.jndiObject = lookupWithFallback();
	}
}
 
Example #29
Source File: JndiObjectFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Look up the JNDI object and store it.
 */
@Override
public void afterPropertiesSet() throws IllegalArgumentException, NamingException {
	super.afterPropertiesSet();

	if (this.proxyInterfaces != null || !this.lookupOnStartup || !this.cache || this.exposeAccessContext) {
		// We need to create a proxy for this...
		if (this.defaultObject != null) {
			throw new IllegalArgumentException(
					"'defaultObject' is not supported in combination with 'proxyInterface'");
		}
		// We need a proxy and a JndiObjectTargetSource.
		this.jndiObject = JndiObjectProxyFactory.createJndiObjectProxy(this);
	}
	else {
		if (this.defaultObject != null && getExpectedType() != null &&
				!getExpectedType().isInstance(this.defaultObject)) {
			TypeConverter converter = (this.beanFactory != null ?
					this.beanFactory.getTypeConverter() : new SimpleTypeConverter());
			try {
				this.defaultObject = converter.convertIfNecessary(this.defaultObject, getExpectedType());
			}
			catch (TypeMismatchException ex) {
				throw new IllegalArgumentException("Default object [" + this.defaultObject + "] of type [" +
						this.defaultObject.getClass().getName() + "] is not of expected type [" +
						getExpectedType().getName() + "] and cannot be converted either", ex);
			}
		}
		// Locate specified JNDI object.
		this.jndiObject = lookupWithFallback();
	}
}
 
Example #30
Source File: QualifierAnnotationAutowireCandidateResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Match the given qualifier annotations against the candidate bean definition.
 */
protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) {
	if (ObjectUtils.isEmpty(annotationsToSearch)) {
		return true;
	}
	SimpleTypeConverter typeConverter = new SimpleTypeConverter();
	for (Annotation annotation : annotationsToSearch) {
		Class<? extends Annotation> type = annotation.annotationType();
		boolean checkMeta = true;
		boolean fallbackToMeta = false;
		if (isQualifier(type)) {
			if (!checkQualifier(bdHolder, annotation, typeConverter)) {
				fallbackToMeta = true;
			}
			else {
				checkMeta = false;
			}
		}
		if (checkMeta) {
			boolean foundMeta = false;
			for (Annotation metaAnn : type.getAnnotations()) {
				Class<? extends Annotation> metaType = metaAnn.annotationType();
				if (isQualifier(metaType)) {
					foundMeta = true;
					// Only accept fallback match if @Qualifier annotation has a value...
					// Otherwise it is just a marker for a custom qualifier annotation.
					if ((fallbackToMeta && StringUtils.isEmpty(AnnotationUtils.getValue(metaAnn))) ||
							!checkQualifier(bdHolder, metaAnn, typeConverter)) {
						return false;
					}
				}
			}
			if (fallbackToMeta && !foundMeta) {
				return false;
			}
		}
	}
	return true;
}