Class MapBeanProxy

java.lang.Object
net.solarnetwork.util.MapBeanProxy
All Implemented Interfaces:
InvocationHandler

public class MapBeanProxy extends Object implements InvocationHandler
Proxy InvocationHandler that treats keys in a Map as JavaBean getter/setter methods.
Since:
1.71
Version:
1.0
Author:
matt
  • Field Details

    • GETTER_REGEX

      public static final Pattern GETTER_REGEX
      A pattern used to match a JavaBean style getter method name.
    • SETTER_REGEX

      public static final Pattern SETTER_REGEX
      A pattern used to match a JavaBean style setter method name.
  • Constructor Details

    • MapBeanProxy

      public MapBeanProxy(Map<String,?> data)
      Constructor.
      Parameters:
      data - the map data; a new map instance will be created if null
    • MapBeanProxy

      public MapBeanProxy(Map<String,?> data, boolean readOnly)
      Constructor.
      Parameters:
      data - the map data; a new map instance will be created if null
      readOnly - true to disallow setter method invocation to the data map
  • Method Details

    • createProxy

      public static <T> T createProxy(MapBeanProxy bean, Class<?>... interfaces)
      Create a new proxy instance.
      Type Parameters:
      T - the type to cast the result to
      Parameters:
      bean - the bean to proxy
      interfaces - specific interfaces to implement, or null to extract all interfaces from bean
      Returns:
      the proxy, which will implement all interfaces defined by interfaces or bean
    • createProxy

      public static <T> T createProxy(MapBeanProxy bean, ClassLoader classLoader, Class<?>... interfaces)
      Create a new proxy instance.
      Type Parameters:
      T - the type to cast the result to
      Parameters:
      bean - the bean to proxy
      classLoader - the class loader to use, or null to use the class loader of bean
      interfaces - specific interfaces to implement, or null to extract all interfaces from bean
      Returns:
      the proxy, which will implement all interfaces defined by interfaces or bean
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable
    • getData

      public Map<String,?> getData()
      Get the data map.
      Returns:
      the data