public synchronized void registerConverter(String className, TypeConverter converter) { converterHolder.addDefaultMapping(className, converter); }
public synchronized void registerConverterNotFound(String className) { converterHolder.addUnknownMapping(className); }
if (converterHolder.containsUnknownMapping(className) && !converterHolder.containsDefaultMapping(className)) { return null; TypeConverter result = converterHolder.getDefaultMapping(className);
if ((property != null) && !converterHolder.containsNoMapping(clazz)) { try { Map<String, Object> mapping = converterHolder.getMapping(clazz); LOG.debug("Got exception trying to resolve convert for class [#0] and property [#1]", t, clazz, property); converterHolder.addNoMapping(clazz);
/** * Recurses through a class' interfaces and class hierarchy looking for a TypeConverter in the default mapping that * can handle the specified class. * * @param clazz the class the TypeConverter must handle * @return a TypeConverter to handle the specified class or null if none can be found */ TypeConverter lookupSuper(Class clazz) { TypeConverter result = null; if (clazz != null) { result = converterHolder.getDefaultMapping(clazz.getName()); if (result == null) { // Looks for direct interfaces (depth = 1 ) Class[] interfaces = clazz.getInterfaces(); for (Class anInterface : interfaces) { if (converterHolder.containsDefaultMapping(anInterface.getName())) { result = converterHolder.getDefaultMapping(anInterface.getName()); break; } } if (result == null) { // Looks for the superclass // If 'clazz' is the Object class, an interface, a primitive type or void then clazz.getSuperClass() returns null result = lookupSuper(clazz.getSuperclass()); } } } return result; }
/** * Looks for converter mappings for the specified class, traversing up its class hierarchy and interfaces and adding * any additional mappings it may find. Mappings lower in the hierarchy have priority over those higher in the * hierarcy. * * @param clazz the class to look for converter mappings for * @return the converter mappings */ protected Map<String, Object> buildConverterMapping(Class clazz) throws Exception { Map<String, Object> mapping = new HashMap<String, Object>(); // check for conversion mapping associated with super classes and any implemented interfaces Class curClazz = clazz; while (!curClazz.equals(Object.class)) { // add current class' mappings addConverterMapping(mapping, curClazz); // check interfaces' mappings Class[] interfaces = curClazz.getInterfaces(); for (Class anInterface : interfaces) { addConverterMapping(mapping, anInterface); } curClazz = curClazz.getSuperclass(); } if (mapping.size() > 0) { converterHolder.addMapping(clazz, mapping); } else { converterHolder.addNoMapping(clazz); } return mapping; }
LOG.debug("\t" + key + ":" + entry.getValue() + " [treated as TypeConverter " + _typeConverter + "]"); converterHolder.addDefaultMapping(key, _typeConverter); } catch (Exception e) { LOG.error("Conversion registration error", e);
converterHolder.addDefaultMapping(key, converterCreator.createTypeConverter(tc.converter())); } else { if (tc.rule() == ConversionRule.KEY_PROPERTY || tc.rule() == ConversionRule.CREATE_IF_NULL) {