Class PropertyReflector

java.lang.Object
org.pipservices3.commons.reflect.PropertyReflector

public class PropertyReflector extends Object
Helper class to perform property introspection and dynamic reading and writing.

This class has symmetric implementation across all languages supported by Pip.Services toolkit and used to support dynamic data processing.

Because all languages have different casing and case sensitivity rules, this PropertyReflector treats all property names as case insensitive.

### Example ###

 
 MyObject myObj = new MyObject();

 List<String> properties = PropertyReflector.getPropertyNames();
 PropertyReflector.hasProperty(myObj, "myProperty");
 Object value = PropertyReflector.getProperty(myObj, "myProperty");
 PropertyReflector.setProperty(myObj, "myProperty", 123);
 
 
  • Constructor Details

    • PropertyReflector

      public PropertyReflector()
  • Method Details

    • hasProperty

      public static boolean hasProperty(Object obj, String name)
      Checks if object has a property with specified name..
      Parameters:
      obj - an object to introspect.
      name - a name of the property to check.
      Returns:
      true if the object has the property and false if it doesn't.
    • getProperty

      public static Object getProperty(Object obj, String name)
      Gets value of object property specified by its name.
      Parameters:
      obj - an object to read property from.
      name - a name of the property to get.
      Returns:
      the property value or null if property doesn't exist or introspection failed.
    • getPropertyNames

      public static List<String> getPropertyNames(Object obj)
      Gets names of all properties implemented in specified object.
      Parameters:
      obj - an objec to introspect.
      Returns:
      a list with property names.
    • getProperties

      public static Map<String,Object> getProperties(Object obj)
      Get values of all properties in specified object and returns them as a map.
      Parameters:
      obj - an object to get properties from.
      Returns:
      a map, containing the names of the object's properties and their values.
    • setProperty

      public static void setProperty(Object obj, String name, Object value)
      Sets value of object property specified by its name.

      If the property does not exist or introspection fails this method doesn't do anything and doesn't any throw errors.

      Parameters:
      obj - an object to write property to.
      name - a name of the property to set.
      value - a new value for the property to set.
    • setProperties

      public static void setProperties(Object obj, Map<String,Object> values)
      Sets values of some (all) object properties.

      If some properties do not exist or introspection fails they are just silently skipped and no errors thrown.

      Parameters:
      obj - an object to write properties to.
      values - a map, containing property names and their values.
      See Also: