Extract a single property value from a Property object

Defer any varying data type extractions to child classes

@param $int_type
@param object $obj_property
@return mixed
@throws \Exception
175712
protected function extractPropertyValue($int_type, $obj_property)
    {
        switch ($int_type) {
            case Schema::PROPERTY_STRING:
                return isset($obj_property->stringValue) ? $obj_property->stringValue : null;

            case Schema::PROPERTY_INTEGER:
                return isset($obj_property->integerValue) ? $obj_property->integerValue : null;

            case Schema::PROPERTY_DATETIME:
                return isset($obj_property->timestampValue) ? $this->extractDatetimeValue($obj_property) : null;

            case Schema::PROPERTY_DOUBLE:
            case Schema::PROPERTY_FLOAT:
                return isset($obj_property->doubleValue) ? $obj_property->doubleValue : null;

            case Schema::PROPERTY_BOOLEAN:
                return isset($obj_property->booleanValue) ? $obj_property->booleanValue : null;

            case Schema::PROPERTY_GEOPOINT:
                return isset($obj_property->geoPointValue) ? $this->extractGeopointValue($obj_property) : null;

            case Schema::PROPERTY_STRING_LIST:
                return $this->extractStringListValue($obj_property);

            case Schema::PROPERTY_DETECT:
                return $this->extractAutoDetectValue($obj_property);

        }
        throw new \Exception('Unsupported field type: ' . $int_type);
    }
1137050
public static function extractValueFromEntity($entity, $property)
    {
        $getter = self::createGetter($entity, $property);

        return $entity->$getter();
    }
1194467
Object getPropertyValue(final String propName, final Interpreter interp)
            throws UtilEvalError {
        String accessorName = Reflect.accessorName(Reflect.GET_PREFIX, propName);
        final Class<?>[] classArray = Reflect.ZERO_TYPES;
        BshMethod m = this.getMethod(accessorName, classArray);
        try {
            if (m != null)
                return m.invoke((Object[]) null, interp);
            accessorName = Reflect.accessorName(Reflect.IS_PREFIX, propName);
            m = this.getMethod(accessorName, classArray);
            if (m != null && m.getReturnType() == Boolean.TYPE)
                return m.invoke((Object[]) null, interp);
            return Primitive.VOID;
        } catch (final EvalError ee) {
            throw new UtilEvalError("'This' property accessor threw exception: "
                    + ee.getMessage(), ee);
        }
    }
317299
public function getProperty(int $object, string $property)
    {
        $this->protocol->propertyAccessBegin($object, $property);
        $this->protocol->propertyAccessEnd();

        return $this->getResult();
    }
625641
public function pegaAtributosDoObjeto($obj)
    {
        $properties      = [];
        $reflectionClass = new ReflectionClass($obj);
        $propriedades    = $reflectionClass->getProperties(
            ReflectionProperty::IS_PUBLIC |
            ReflectionProperty::IS_PROTECTED | 
            ReflectionProperty::IS_PRIVATE
        );
     
        $iterator = 0;
        $limit    = count($propriedades);
        for ($iterator = 0; $iterator < $limit; $iterator++) {
            $properties[$iterator] = $propriedades[$iterator]->name;
        }

        return $properties;
    }
244608
@SuppressWarnings("deprecation")
	@Override
	public JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfo info) {
		JexlPropertyGet get = getJadeGetExecutor(obj, identifier);
		if (get == null && obj != null && identifier != null) {
			get = getIndexedGet(obj, identifier.toString());
			if (get == null) {
				Field field = getField(obj, identifier.toString(), info);
				if (field != null) {
					return new FieldPropertyGet(field);
				}
			}
		}
		return get;
	}
394248
@SuppressWarnings("unchecked")
    private <T> List<T> getListValue(Class<T> type, String propertyName, EDBObject object) {
        List<T> temp = new ArrayList<>();
        for (int i = 0;; i++) {
            String property = getEntryNameForList(propertyName, i);
            Object obj = object.getObject(property);
            if (obj == null) {
                break;
            }
            if (OpenEngSBModel.class.isAssignableFrom(type)) {
                obj = convertEDBObjectToUncheckedModel(type, edbService.getObject(object.getString(property)));
            }
            temp.add((T) obj);
            object.remove(property);
        }
        return temp;
    }
646212
public function getValue($object = null)
    {
        if (!is_object($object)) {
            throw new Exception('$object is of type ' . gettype($object) . ', instance of class ' . $this->class . ' expected.', 1210859212);
        }
        if ($this->isPublic()) {
            return parent::getValue($object);
        }

        parent::setAccessible(true);
        return parent::getValue($object);
    }
78853
public static int getInt(Object obj, String fieldName) {
        try {
            return getField(obj.getClass(), fieldName).getInt(obj);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
1287328
@SuppressWarnings("unchecked")
	public static <T> T cast(Object obj, Class<T> type){
		if(obj == null){
			return null;
		}
		if(obj.getClass() == type){
			return (T) obj;
		}
		if(isNativeNumberType(obj.getClass()) && isNativeNumberType(type)){
			return castToNativeNumber((Number)obj, type);
		}
		return type.cast(obj);
	}
1166485
public function mapOneFromResult($obj_result)
    {
        // Key & Ancestry
        list($obj_gds_entity, $bol_schema_match) = $this->createEntityWithKey($obj_result);

        // Properties
        $arr_property_definitions = $this->obj_schema->getProperties();
        foreach($obj_result->getEntity()->getPropertyList() as $obj_property) {
            /* @var $obj_property \google\appengine\datastore\v4\Property */
            $str_field = $obj_property->getName();
            if ($bol_schema_match && isset($arr_property_definitions[$str_field])) {
                $obj_gds_entity->__set($str_field, $this->extractPropertyValue($arr_property_definitions[$str_field]['type'], $obj_property->getValue()));
            } else {
                $obj_gds_entity->__set($str_field, $this->extractPropertyValue(Schema::PROPERTY_DETECT, $obj_property->getValue()));
            }
        }
        return $obj_gds_entity;
    }
957348
public static Object callGetter(Object obj, String prop) throws PageException {
	try {
	    return getGetter(obj.getClass(), prop).invoke(obj);
	}
	catch (InvocationTargetException e) {
	    Throwable target = e.getTargetException();
	    if (target instanceof PageException) throw (PageException) target;
	    throw Caster.toPageException(e.getTargetException());
	}
	catch (Exception e) {
	    throw Caster.toPageException(e);
	}
    }
920843
public byte[] getProperty(int objIndex, int pid, int start, int elements)
		throws KNXTimeoutException, KNXRemoteException, KNXConnectionClosedException
	{
		if (closed)
			throw new KNXIllegalStateException("adapter closed");
		conn.send(new CEMIDevMgmt(CEMIDevMgmt.MC_PROPREAD_REQ, getObjectType(objIndex),
			1, pid, start, elements), KNXnetIPConnection.WAIT_FOR_CON);
		return findFrame(CEMIDevMgmt.MC_PROPREAD_CON);
	}
300221
private static String readArrayValue(String ref, TypeDef source, Property property) {
        TypeRef typeRef = property.getTypeRef();
        if (typeRef instanceof ClassRef) {
            //TODO: This needs further breakdown, to cover edge cases.
            return readObjectArrayValue(ref, source, property);
        }

        if (typeRef instanceof PrimitiveRef) {
            return readPrimitiveArrayValue(ref, source, property);
        }
        throw new IllegalStateException("Property should be either an object or a primitive.");
    }
1121775
def extract_object_properties(self, o, limit_size=False):
        
        try:
            prop_str = repr(o)[:512]
        except:
            prop_str = "Error while extracting value"

        _logger.e_debug("extract_object_properties(%s)", prop_str)
        var_list = []
        if isinstance(o, dict):
            a_var_name = None
            a_var_value = None
            for a_var_name in o:
                a_var_value = o[a_var_name]
                children_count = self.object_properties_count(a_var_value)
                v_name, v_value, v_type = self.extract_name_value_type(a_var_name, 
                                                                       a_var_value, 
                                                                       limit_size=limit_size)
                a_var_info = {
                    'id': id(a_var_value),
                    'name': v_name,
                    'type': "%s%s" % (v_type, " [%s]" % children_count if children_count else '',),
                    'value': v_value,
                    'children_count': children_count,
                }
                var_list.append(a_var_info)
                
        elif type(o) in (list, tuple, set,):
            MAX_CHILDREN_TO_RETURN = 256
            MAX_CHILDREN_MESSAGE = "Truncated by ikpdb (don't hot change me !)."
            a_var_name = None
            a_var_value = None
            do_truncate = len(o) > MAX_CHILDREN_TO_RETURN
            for idx, a_var_value in enumerate(o):
                children_count = self.object_properties_count(a_var_value)
                v_name, v_value, v_type = self.extract_name_value_type(idx, 
                                                                       a_var_value, 
                                                                       limit_size=limit_size)
                var_list.append({
                    'id': id(a_var_value),
                    'name': v_name,
                    'type': "%s%s" % (v_type, " [%s]" % children_count if children_count else '',),
                    'value': v_value,
                    'children_count': children_count,
                })
                if do_truncate and idx==MAX_CHILDREN_TO_RETURN-1:
                    var_list.append({
                        'id': None,
                        'name': str(MAX_CHILDREN_TO_RETURN),
                        'type': '',
                        'value': MAX_CHILDREN_MESSAGE,
                        'children_count': 0,
                    })
                    break
        else:
            a_var_name = None
            a_var_value = None
            if hasattr(o, '__dict__'):
                for a_var_name, a_var_value in o.__dict__.items():
                    if (not a_var_name.startswith('__') 
                        and not type(a_var_value) in (types.ModuleType, 
                                                      types.MethodType, 
                                                      types.FunctionType,)):
                        children_count = self.object_properties_count(a_var_value)
                        v_name, v_value, v_type = self.extract_name_value_type(a_var_name,
                                                                               a_var_value, 
                                                                               limit_size=limit_size)
                        var_list.append({
                            'id': id(a_var_value),
                            'name': v_name,
                            'type': "%s%s" % (v_type, " [%s]" % children_count if children_count else '',),
                            'value': v_value,
                            'children_count': children_count,
                        })
        return var_list
951549
Object getValue(Object obj, String attributePath, Object metadata) throws Exception {
        return getValue(obj, attributePath);
    }
607628
public static Integer getIntegerProperty(Properties properties, String key) {
        String property = getStringProperty(properties, key);
        if (property == null) {
            return null;
        }
        Integer value;
        try {
            value = Integer.parseInt(property);
        } catch (RuntimeException e) {
            throw new ODataClientRuntimeException("Unable to parse property. " + property, e);
        }
        return value;
    }