getGraphCodec method

RdfGraphCodec getGraphCodec(
  1. String? mimeType
)

Retrieves a codec instance by MIME type

This method retrieves the appropriate codec for processing RDF data in the format specified by the given MIME type.

The mimeType parameter is the MIME type for which to retrieve a codec. Can be null.

Returns the appropriate RdfGraphCodec for the given MIME type. If mimeType is null, returns a special codec that auto-detects the format for decoding, but encodes to the format of the first registered codec.

Throws CodecNotSupportedException if no codec is found for the given MIME type or if no codecs are registered.

Implementation

RdfGraphCodec getGraphCodec(String? mimeType) {
  RdfGraphCodec? result;
  if (mimeType != null) {
    result = _graphCodecsByMimeType[_normalizeMimeType(mimeType)];
    if (result == null) {
      throw CodecNotSupportedException(
        'No codec registered for MIME type: $mimeType',
      );
    }
    return result;
  }

  // Use the first registered codec as default encoder
  if (_graphCodecs.isEmpty) {
    throw CodecNotSupportedException('No codecs registered');
  }

  // If no codec found, return a special detecting codec
  return AutoDetectingGraphCodec(
    defaultCodec: _graphCodecs.first,
    registry: this,
  );
}