/** * Coerces this map to the given type, using the map's keys as the public * method names, and values as the implementation. Typically the value * would be a closure which behaves like the method implementation. * * @param map this map * @param clazz the target type * @return a Proxy of the given type, which defers calls to this map's elements. * @since 1.0 */ @SuppressWarnings("unchecked") public static <T> T asType(Map map, Class<T> clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface() && !Traits.isTrait(clazz)) { return (T) Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return (T) ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
@Override public Object invokeCustom(Object proxy, Method method, Object[] args) throws Throwable { Map m = (Map) getDelegate(); Closure cl = (Closure) m.get(method.getName()); if(cl == null && "toString".equals(method.getName())) { return m.toString(); } if (cl == null) { throw new UnsupportedOperationException(); } return cl.call(args); }
@Override protected boolean checkMethod(Method method) { return isCoreObjectMethod(method); }
@Override public String toString() { return DefaultGroovyMethods.toString(getDelegate()); }
/** * Coerces this map to the given type, using the map's keys as the public * method names, and values as the implementation. Typically the value * would be a closure which behaves like the method implementation. * * @param map this map * @param clazz the target type * @return a Proxy of the given type, which defers calls to this map's elements. */ public static Object asType(Map map, Class clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface()) { return Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
protected boolean checkMethod(Method method) { return isCoreObjectMethod(method); }
public Object invokeCustom(Object proxy, Method method, Object[] args) throws Throwable { Map m = (Map) getDelegate(); Closure cl = (Closure) m.get(method.getName()); if(cl == null) { throw new UnsupportedOperationException(); } return cl.call(args); }
/** * Coerces this map to the given type, using the map's keys as the public * method names, and values as the implementation. Typically the value * would be a closure which behaves like the method implementation. * * @param map this map * @param clazz the target type * @return a Proxy of the given type, which defers calls to this map's elements. * @since 1.0 */ public static Object asType(Map map, Class clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface()) { return Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
protected boolean checkMethod(Method method) { return isCoreObjectMethod(method); }
public Object invokeCustom(Object proxy, Method method, Object[] args) throws Throwable { Map m = (Map) getDelegate(); Closure cl = (Closure) m.get(method.getName()); if(cl == null) { throw new UnsupportedOperationException(); } return cl.call(args); }
/** * Coerces this map to the given type, using the map's keys as the public * method names, and values as the implementation. Typically the value * would be a closure which behaves like the method implementation. * * @param map this map * @param clazz the target type * @return a Proxy of the given type, which defers calls to this map's elements. * @since 1.0 */ public static Object asType(Map map, Class clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface()) { return Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
public Object invokeCustom(Object proxy, Method method, Object[] args) throws Throwable { Map m = (Map) getDelegate(); Closure cl = (Closure) m.get(method.getName()); if(cl == null) { throw new UnsupportedOperationException(); } return cl.call(args); }
/** * Coerces this map to the given type, using the map's keys as the public * method names, and values as the implementation. Typically the value * would be a closure which behaves like the method implementation. * * @param map this map * @param clazz the target type * @return a Proxy of the given type, which defers calls to this map's elements. * @since 1.0 */ @SuppressWarnings("unchecked") public static <T> T asType(Map map, Class<T> clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface()) { return (T) Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return (T) ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
public Object invokeCustom(Object proxy, Method method, Object[] args) throws Throwable { Map m = (Map) getDelegate(); Closure cl = (Closure) m.get(method.getName()); if(cl == null && "toString".equals(method.getName())) { return m.toString(); } if (cl == null) { throw new UnsupportedOperationException(); } return cl.call(args); }
public String toString() { return DefaultGroovyMethods.toString((Map) getDelegate()); } }
public String toString() { return DefaultGroovyMethods.toString((Map) getDelegate()); } }
public String toString() { return DefaultGroovyMethods.toString(getDelegate()); }
public String toString() { return DefaultGroovyMethods.toString((Map) getDelegate()); }