@Override @SuppressWarnings("rawtypes") public Transform match(Class type) throws Exception { Transform transform = super.match(type); if (transform == null) { if (Type.class.isAssignableFrom(type)) transform = TypeTransform.getInstance(); else if (Throwable.class.isAssignableFrom(type)) transform = SerializableTransform.getInstance(); else if (Charset.class.isAssignableFrom(type)) return super.match(Charset.class); // bind(type, transform); } // LOG.info("Transform " + type + " using " + transform, new Exception()); return transform; }
@Override public Transform<?> match(Class type) throws Exception { if(Condition.class.isAssignableFrom(type)){ return new Transform<Condition>() { @Override public Condition read(String s) throws Exception { return Condition.makeCondition(s); } @Override public String write(Condition condition) throws Exception { return condition.toString(); } }; } return null; }
@SuppressWarnings("rawtypes") @Override public Transform<?> match(Class type) throws Exception { if (type.equals(Coordinate.class)) return new CoordinateTransformer(); else if (type.equals(Coordinates.class)) return new CoordinatesTransformer(); return null; }
public static Persister createPersister(final Account account) { return new Persister(new Matcher() { @Override public Transform match(Class type) throws Exception { if (Date.class.isAssignableFrom(type)) { return new DateTransform(account); } else if (Uri.class.isAssignableFrom(type)) { return new UriTransform(account); } return null; } }); }
@Override public Transform match(Class type) throws Exception { if (type.equals(Integer.class)) { return new IntegerTransformer(); } return null; }
private static void addTransformers(@Nonnull RegistryMatcher matcher, @Nonnull Serializer serializer, @Nonnull Iterable<? extends TransformFactory> factories) { for (TransformFactory factory : factories) { // LOG.info("Factory " + factory); for (Map.Entry<? extends Class<?>, ? extends Transform<?>> e : factory.newTransforms()) { // LOG.info("Register " + e.getKey() + " -> " + e.getValue()); try { matcher.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 Transform<?>>> newTransforms() { return Arrays.asList( Maps.immutableEntry(Type.class, this), Maps.immutableEntry(Class.class, this) ); }
@Override @SuppressWarnings("unchecked") public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Arrays.asList( Maps.immutableEntry(InetAddress.class, this), Maps.immutableEntry(Inet4Address.class, this), Maps.immutableEntry(Inet6Address.class, this)); }
@Nonnull private static RegistryMatcher newRegistryMatcher() { RegistryMatcher matcher = new RegistryMatcher() { @Override public Transform match(Class type) throws Exception { if (Type.class.isAssignableFrom(type)) return TypeTransform.getInstance(); return super.match(type); } }; return matcher; }
@Override public void unUnloaded() { SerializeHelper sh = SerializeHelper.get(); for(Entry<Class<?>, Class<? extends Transform<?>>> entry : matcherMap.entrySet()) { sh.removeTransformMapping(entry.getKey()); } matcherMap.clear(); }
@SuppressWarnings("rawtypes") @Override public Transform match(Class type) throws Exception { if (Date.class.equals(type)) { return new AbcDateTransform(); } return null; }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singletonList(Maps.immutableEntry(InterfaceAddress.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singletonList(Maps.immutableEntry(NetworkAddress.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singletonList(Maps.immutableEntry(HardwareAddress.class, this)); }
@Override public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singleton(Maps.immutableEntry(double[].class, this)); }
@Override public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singleton(Maps.immutableEntry(short[].class, this)); }
@Override public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singleton(Maps.immutableEntry(long[].class, this)); }
@Override public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singleton(Maps.immutableEntry(float[].class, this)); }
@Override @SuppressWarnings("unchecked") // Generic array creation public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singletonList(Maps.immutableEntry(UUID.class, this)); }
@Override public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singleton(Maps.immutableEntry(int[].class, this)); }
@Override public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singleton(Maps.immutableEntry(Serializable.class, this)); }
@Override @SuppressWarnings("unchecked") // Generic array creation public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singletonList(Maps.immutableEntry(URI.class, this)); }
@Override public Iterable<? extends Map.Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singleton(Maps.immutableEntry(Charset.class, this)); }
@Override public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms() { return Collections.singleton(Maps.immutableEntry(byte[].class, this)); }
@Nonnull public Iterable<? extends Entry<? extends Class<?>, ? extends Transform<?>>> newTransforms();
public Transform match(Class type) { if(type == Literal.class) { return new LiteralTransform(); } return null; }
public Transform match(Class type) throws Exception { if(type == Integer.class) { return this; } return null; }
public Transform match(Class type) throws Exception { if(type == String.class) { return this; } return null; }
public Transform match(Class type) throws Exception { if(type == MyEnum.class) { return this; } return null; }
public Transform match(Class type) throws Exception { if(type == DateTime.class) { return new DateTimeTransform(); } return null; }
public void addTransformMapping(Class<?> dataCls, Class<? extends Transform<?>> transformCls) { matcher.bind(dataCls, transformCls); LOG.info("Registered Transform '{}' for '{}'.", transformCls.getSimpleName(), dataCls.getSimpleName()); }
protected void addTransformMapping(Class<?> dataCls, Class<? extends Transform<?>> transformCls) { SerializeHelper.get().addTransformMapping(dataCls, transformCls); matcherMap.put(dataCls, transformCls); }
/** * This is used to match a <code>Transform</code> using the type * specified. If no transform can be acquired then this returns * a null value indicating that no transform could be found. * * @param type this is the type to acquire the transform for * * @return returns a transform for processing the type given */ public Transform getTransform(Class type) throws Exception { return matcher.match(type); }
/** * This method is used to return a null value for the transform. * Returning a null value allows the normal resolution of the * stock transforms to be used when no matcher is specified. * * @param type this is the type that is expecting a transform * * @return this transform will always return a null value */ public Transform match(Class type) throws Exception { return null; }