class OpenLRProtoDecoder implements PhysicalDecoder {

    @Override
    public RawLocationReference decodeData(LocationReference data) throws PhysicalFormatException {
        LocationType locationType = data.getLocationType();
        LocationReferenceDecoder locationReferenceDecoder = locationTypeDecoderRegistry.getDecoder(locationType);

        if (locationReferenceDecoder == null) {
            throw new OpenLRProtoException(OpenLRProtoStatusCode.UNSUPPORTED_LOCATION_TYPE);
        }

        Object locationReferenceData = data.getLocationReferenceData();

        if (!(locationReferenceData instanceof LocationReferenceData)) {
            throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_DATA_TYPE);
        }

        return locationReferenceDecoder.decode(data.getID(), (LocationReferenceData) locationReferenceData);
    }

}