コード例 #1
0
  /**
   * Removes the type converter.
   *
   * @param tc
   */
  public void removeConverter(TypeConverter tc) {
    if (tc.getSupportedTypes() == null) untypedTypeEncoders.remove(tc);
    else
      for (List<TypeConverter> tcList : tcMap.values()) if (tcList.contains(tc)) tcList.remove(tc);

    registeredConverterClasses.remove(tc.getClass());
  }
コード例 #2
0
  /**
   * Add a type converter. If it is a duplicate for an existing type, it will override that type.
   *
   * @param tc
   */
  public TypeConverter addConverter(TypeConverter tc) {
    if (tc.getSupportedTypes() != null)
      for (Class c : tc.getSupportedTypes()) addTypedConverter(c, tc);
    else untypedTypeEncoders.add(tc);

    tc.setMapper(mapr);

    registeredConverterClasses.add(tc.getClass());
    return tc;
  }
コード例 #3
0
 public void fromDBObject(final DBObject dbObj, final MappedField mf, final Object targetEntity) {
   Object object = mf.getDbObjectValue(dbObj);
   if (object == null) {
     processMissingField(mf);
   } else {
     TypeConverter enc = getEncoder(mf);
     Object decodedValue = enc.decode(mf.getType(), object, mf);
     try {
       mf.setFieldValue(targetEntity, decodedValue);
     } catch (IllegalArgumentException e) {
       throw new MappingException(
           "Error setting value from converter ("
               + enc.getClass().getSimpleName()
               + ") for "
               + mf.getFullName()
               + " to "
               + decodedValue);
     }
   }
 }