public static Object convertProperty()

in src/main/java/com/vmware/vim25/mo/util/PropertyCollectorUtil.java [149:184]


    public static Object convertProperty(Object dynaPropVal) {
        Object propertyValue = null;
        if (dynaPropVal == null) {
            throw new IllegalArgumentException("Unable to convertProperty on null object.");
        }
        Class<?> propClass = dynaPropVal.getClass();
        String propName = propClass.getName();
        //Check the dynamic propery for ArrayOfXXX object
        if (propName.contains("ArrayOf")) {
            String methodName = propName.substring(propName.indexOf("ArrayOf") + "ArrayOf".length());
            // If object is ArrayOfXXX object, then get the XXX[] by invoking getXXX() on the object. For Ex:
            // ArrayOfManagedObjectReference.getManagedObjectReference() returns ManagedObjectReference[] array.
            try {
                Method getMethod;
                try {
                    getMethod = propClass.getMethod("get" + methodName, (Class[]) null);
                }
                catch (NoSuchMethodException ignore) {
                    getMethod = propClass.getMethod("get_" + methodName.toLowerCase(), (Class[]) null);
                }
                propertyValue = getMethod.invoke(dynaPropVal, (Object[]) null);
            }
            catch (Exception e) {
                log.error("Exception caught trying to convertProperty", e);
            }
        }
        //Handle the case of an unwrapped array being deserialized.
        else if (dynaPropVal.getClass().isArray()) {
            propertyValue = dynaPropVal;
        }
        else {
            propertyValue = dynaPropVal;
        }

        return propertyValue;
    }