Utility method to bind converter instance to concrete value type.

@param valueType concrete value type,
@param converter converter instance able to handle value type.
339346
private void registerConverterInstance(Class<?> valueType, Converter converter)
  {
    if(converters.put(valueType, converter) == null) {
      log.debug("Register converter |%s| for value type |%s|.", converter.getClass(), valueType);
    }
    else {
      log.warn("Override converter |%s| for value type |%s|.", converter.getClass(), valueType);
    }
  }
358089
public static Converter getConverter(FacesContext fc, ValueHolder vh) {
		// explicit converter
		Converter converter = vh.getConverter();

		// try to find implicit converter
		if (converter == null) {
			ValueExpression expr = ((UIComponent) vh).getValueExpression("value");
			if (expr != null) {
				Class<?> valueType = expr.getType(fc.getELContext());
				if (valueType != null) {
					converter = fc.getApplication().createConverter(valueType);
				}
			}
		}

		return converter;
	}
915927
public <T> T convert(Object value, Class<T> type) {
		return converter.convert(value, type);
	}
831914
private static Converter<List<String>, Object> createStringConstructorConverter(Class<?> resultClass) {
    try {
      final Constructor<?> constructor = resultClass.getConstructor(String.class);
      return new BasicConverter(defaultValue(resultClass)) {
        @Override
        protected Object convert(String value) throws Exception {
          return constructor.newInstance(value);
        }
      };
    } catch (Exception e) {
      return null;
    }
  }
1255611
public PriorityConverter getConverter(Type type) {
        PriorityConverter converter = converters.get(type);
        return converter;
    }
1122021
public static Object convertToUIInputValue(final ConverterFactory converterFactory,
            final InputComponent<?, ?> input, final Object value)
   {
      final Object result;
      Class<Object> sourceType = (Class<Object>) value.getClass();
      Class<Object> targetType = (Class<Object>) input.getValueType();
      if (!targetType.isAssignableFrom(sourceType))
      {
         if (input instanceof SelectComponent)
         {
            SelectComponent<?, Object> selectComponent = (SelectComponent<?, Object>) input;
            Iterable<Object> valueChoices = selectComponent.getValueChoices();
            final Converter<Object, ?> selectConverter;
            if (String.class.isAssignableFrom(sourceType))
            {
               selectConverter = getItemLabelConverter(converterFactory, selectComponent);
            }
            else
            {
               selectConverter = converterFactory.getConverter(targetType, sourceType);
            }
            Object chosenObj = null;
            if (valueChoices != null)
            {
               for (Object valueChoice : valueChoices)
               {
                  Object convertedObj = selectConverter.convert(valueChoice);
                  if (convertedObj.equals(value))
                  {
                     chosenObj = valueChoice;
                     break;
                  }
               }
            }
            result = chosenObj;
         }
         else
         {

            Converter<String, Object> valueConverter = (Converter<String, Object>) input.getValueConverter();
            if (valueConverter != null)
            {
               if (value instanceof String)
               {
                  result = valueConverter.convert((String) value);
               }
               else
               {
                  Converter<Object, String> stringConverter = converterFactory.getConverter(sourceType, String.class);
                  CompositeConverter compositeConverter = new CompositeConverter(stringConverter, valueConverter);
                  result = compositeConverter.convert(value);
               }

            }
            else
            {
               Converter<Object, Object> converter = converterFactory.getConverter(sourceType, targetType);
               result = converter.convert(value);
            }
         }
      }
      else
      {

         Converter<String, Object> valueConverter = (Converter<String, Object>) input.getValueConverter();
         if (valueConverter != null && value instanceof String)
         {
            result = valueConverter.convert((String) value);
         }
         else
         {
            // FORGE-2493: By setting the system property 'org.jboss.forge.ui.select_one_lenient_value' to true will
            // allow UISelectOne to set values outside of its value choices. (pre-2.20.0.Final behavior)
            if (input instanceof SelectComponent && !Boolean.getBoolean("org.jboss.forge.ui.select_one_lenient_value"))
            {
               SelectComponent<?, Object> selectComponent = (SelectComponent<?, Object>) input;
               Set<Object> valueChoices = Sets.toSet(selectComponent.getValueChoices());
               // Check if the value is contained in the valueChoices set
               if (valueChoices != null && valueChoices.contains(value))
               {
                  result = value;
               }
               else
               {
                  // equals()/hashCode may not have been implemented. Trying to compare from the String representation
                  Object chosenObj = null;
                  if (valueChoices != null)
                  {
                     Converter<Object, String> selectConverter = getItemLabelConverter(converterFactory,
                              selectComponent);
                     String valueLabel = selectConverter.convert(value);
                     for (Object valueChoice : valueChoices)
                     {
                        String convertedObj = selectConverter.convert(valueChoice);
                        if (convertedObj.equals(valueLabel))
                        {
                           chosenObj = valueChoice;
                           break;
                        }
                     }
                  }
                  result = chosenObj;
               }
            }
            else
            {
               result = value;
            }
         }
      }
      return result;
   }
779923
private <T> Converter<T> lookupConverter(Type targetType)
    {
        // Try with complete type
        Converter<T> converter = getConverter(targetType);

        // Try with simple class
        if (converter == null && targetType instanceof ParameterizedType) {
            Class<?> targetClass = ReflectionUtils.getTypeClass(targetType);
            converter = getConverter(targetClass);
        }

        if (converter == null) {
            if (targetType instanceof Class && Enum.class.isAssignableFrom((Class<?>) targetType)) {
                // It's an Enum
                converter = (Converter<T>) this.enumConverter;
            } else {
                // Fallback on default converter

                this.logger.debug("Using the default Converter for type [{}]", targetType);

                converter = this.defaultConverter;
            }
        }

        return converter;
    }
429657
public void init(Converter converter, int iBitNumber, boolean trueIfMatch, boolean bTrueIfNull)
    {
        super.init(converter);
        m_iBitNumber = iBitNumber;
        m_bTrueIfMatch = trueIfMatch;
        m_bTrueIfNull = bTrueIfNull;
    }
1187128
public TypeConverter addConverter(final TypeConverter tc) {
        if (tc.getSupportedTypes() != null) {
            for (final Class c : tc.getSupportedTypes()) {
                addTypedConverter(c, tc);
            }
        } else {
            untypedTypeEncoders.add(tc);
        }

        registeredConverterClasses.add(tc.getClass());
        tc.setMapper(mapper);

        return tc;
    }
1139460
public <T> void register(Class<T> type, Converter<T> converter) {
        addConverter(type, converter);
    }
249285
public static void setDefaultValueFor(final ConverterFactory converterFactory,
            final InputComponent<?, Object> component,
            final Object value)
   {
      if (component instanceof SingleValued)
      {
         setSingleInputValue(converterFactory, component, value, true);
      }
      else if (component instanceof ManyValued)
      {
         setManyInputValue(converterFactory, component, value, true);
      }
   }
469648
public <FT> CsvProcessor<T> withConverter(Class<FT> clazz, Converter<FT, ?> converter) {
		converterMap.put(clazz, converter);
		return this;
	}
182009
public ConverterRegistry putCustom(Type type, Class<? extends Converter<?>> converterClass) {
		return putCustom(type, ReflectUtil.newInstance(converterClass));
	}
891546
@Override
    public <T> ConfigBuilder withConverter(Class<T> type, int priority, Converter<T> converter) {
        synchronized (this) {
            UserConverter<?> userConverter = UserConverter.newInstance(type, priority, converter);
            addUserConverter(userConverter);
        }
        return this;
    }
482595
public static Object convertValue(final Object value, final Class<?> convertType) {
        if (null == value) {
            return convertNullValue(convertType);
        } 
        if (value.getClass() == convertType) {
            return value;
        }
        if (value instanceof Number) {
            return convertNumberValue(value, convertType);
        }
        if (value instanceof Date) {
            return convertDateValue(value, convertType);
        }
        if (String.class.equals(convertType)) {
            return value.toString();
        } else {
            return value;
        }
    }
161019
protected void setTypeConversions(List<Pair<String, String>> typeConversions, boolean notifyController) {
		this.conversions.clear();
		if (typeConversions != null) {
			for (final Pair<String, String> entry : typeConversions) {
				this.conversions.add(new ConversionMapping(entry.getKey(), entry.getValue()));
			}
		}
		this.list.setInput(this.conversions);
		refreshListUI();
		if (notifyController) {
			preferenceValueChanged();
		}
	}
160031
public Binder convert(Class<?> returnType, Class<?>... argTypes) {
        return new Binder(this, new Convert(type()), MethodType.methodType(returnType, argTypes));
    }