| From 7a53ed04eeb1c4f6381f535fc090c65368dae9ad Mon Sep 17 00:00:00 2001 |
| From: Kirill Likhodedov <Kirill.Likhodedov@gmail.com> |
| Date: Fri, 21 Oct 2011 18:07:42 +0400 |
| Subject: [PATCH] Let OptionMap.as() accept ClassLoader as the second |
| parameter. Modify BeanTool.proxy to expect classLoader or |
| use Thread#getContextClassLoader (as before) in the case of |
| null |
| |
| --- |
| src/main/java/org/ini4j/BasicOptionMap.java | 9 +++++++-- |
| src/main/java/org/ini4j/OptionMap.java | 2 ++ |
| src/main/java/org/ini4j/spi/BeanTool.java | 10 ++++++---- |
| 3 files changed, 15 insertions(+), 6 deletions(-) |
| |
| diff --git a/src/main/java/org/ini4j/BasicOptionMap.java b/src/main/java/org/ini4j/BasicOptionMap.java |
| index d7e665d..3850bf2 100644 |
| --- a/src/main/java/org/ini4j/BasicOptionMap.java |
| +++ b/src/main/java/org/ini4j/BasicOptionMap.java |
| @@ -76,12 +76,17 @@ public class BasicOptionMap extends CommonMultiMap<String, String> implements Op |
| |
| @Override public <T> T as(Class<T> clazz) |
| { |
| - return BeanTool.getInstance().proxy(clazz, getDefaultBeanAccess()); |
| + return BeanTool.getInstance().proxy(clazz, getDefaultBeanAccess(), null); |
| + } |
| + |
| + @Override public <T> T as(Class<T> clazz, ClassLoader classLoader) |
| + { |
| + return BeanTool.getInstance().proxy(clazz, getDefaultBeanAccess(), classLoader); |
| } |
| |
| @Override public <T> T as(Class<T> clazz, String keyPrefix) |
| { |
| - return BeanTool.getInstance().proxy(clazz, newBeanAccess(keyPrefix)); |
| + return BeanTool.getInstance().proxy(clazz, newBeanAccess(keyPrefix), null); |
| } |
| |
| @Override public String fetch(Object key) |
| diff --git a/src/main/java/org/ini4j/OptionMap.java b/src/main/java/org/ini4j/OptionMap.java |
| index dd48089..c13ac73 100644 |
| --- a/src/main/java/org/ini4j/OptionMap.java |
| +++ b/src/main/java/org/ini4j/OptionMap.java |
| @@ -25,6 +25,8 @@ public interface OptionMap extends MultiMap<String, String>, CommentedMap<String |
| |
| <T> T as(Class<T> clazz); |
| |
| + <T> T as(Class<T> clazz, ClassLoader classLoader); |
| + |
| <T> T as(Class<T> clazz, String keyPrefix); |
| |
| String fetch(Object key); |
| diff --git a/src/main/java/org/ini4j/spi/BeanTool.java b/src/main/java/org/ini4j/spi/BeanTool.java |
| index 05d8be7..7ee22ec 100644 |
| --- a/src/main/java/org/ini4j/spi/BeanTool.java |
| +++ b/src/main/java/org/ini4j/spi/BeanTool.java |
| @@ -156,10 +156,12 @@ public class BeanTool |
| return (T) o; |
| } |
| |
| - public <T> T proxy(Class<T> clazz, BeanAccess props) |
| - { |
| - return clazz.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { clazz }, |
| - new BeanInvocationHandler(props))); |
| + public <T> T proxy(Class<T> clazz, BeanAccess props, ClassLoader classLoader) { |
| + if (classLoader == null) { |
| + classLoader = Thread.currentThread().getContextClassLoader(); |
| + } |
| + return clazz.cast(Proxy.newProxyInstance(classLoader, new Class[]{clazz}, |
| + new BeanInvocationHandler(props))); |
| } |
| |
| @SuppressWarnings("unchecked") |
| -- |
| 1.7.7 |
| |