@Override @SuppressWarnings("rawtypes") public Converter lookup(Class type) throws Exception { Converter converter = super.lookup(type); if (converter == null) { if (Type.class.isAssignableFrom(type)) return TypeConverter.getInstance(); else if (Charset.class.isAssignableFrom(type)) return super.lookup(Charset.class); // This cannot be Serializable because that would cause ArrayList etc to get b0rked. else if (Throwable.class.isAssignableFrom(type)) // Includes Throwable. return super.lookup(Serializable.class); // else if (TBase.class.isAssignableFrom(type)) return super.lookup(TBase.class); // bind(type, converter); } // LOG.info("Convert " + type + " using " + converter, new Exception()); return converter; }
private static void addConverters(@Nonnull Registry registry, @Nonnull Serializer serializer, @Nonnull Iterable<? extends ConverterFactory> factories) { // LOG.info("Loading ConverterFactory instances."); for (ConverterFactory factory : factories) { // LOG.info("Factory " + factory); for (Map.Entry<? extends Class<?>, ? extends Converter<?>> e : factory.newConverters(serializer)) { // LOG.info("Register " + e.getKey() + " -> " + e.getValue()); try { registry.bind(e.getKey(), e.getValue()); } catch (Exception ex) { LOG.error("Failed to bind " + e.getKey() + " to " + e.getValue(), ex); } } } }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Arrays.asList( Maps.immutableEntry(Type.class, this), Maps.immutableEntry(Class.class, this) ); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Arrays.asList( Maps.immutableEntry(InetAddress.class, this), Maps.immutableEntry(Inet4Address.class, this), Maps.immutableEntry(Inet6Address.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(HardwareAddress.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(InterfaceAddress.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(NetworkAddress.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(InetSocketAddress.class, this)); }
@Override @SuppressWarnings("unchecked") // Generic array creation. public Iterable<? extends Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singletonList(Maps.immutableEntry(UUID.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(byte[].class, this)); }
@Override public Iterable<? extends Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(Serializable.class, this)); }
@Override @SuppressWarnings("unchecked") // Generic array creation. public Iterable<? extends Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singletonList(Maps.immutableEntry(URI.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(double[].class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(long[].class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(float[].class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(short[].class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(int[].class, this)); }
@Nonnull public Iterable<? extends Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(@Nonnull Serializer serializer);
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Converter<?>>> newConverters(Serializer serializer) { return Collections.singleton(Maps.immutableEntry(TBase.class, this)); }