CellmlFileRdfTripleElement::CellmlFileRdfTripleElement(iface::rdf_api::Node *pRdfNode) :
    mId(QString()),
    mUriReference(QString()),
    mLexicalForm(QString()),
    mLanguage(QString()),
    mDataTypeUri(QString())
{
    // Check which interface is supported by the node and initialise it in case
    // it supports the rdf_api::URIReference, rdf_api::PlainLiteral or
    // rdf_api::TypedLiteral interface

    ObjRef<iface::rdf_api::URIReference> uriReference = QueryInterface(pRdfNode);

    if (uriReference) {
        // The rdf_api::URIReference interface is supported, so initialise the
        // triple element using that interface

        mType = UriReference;

        mUriReference = QString::fromStdWString(uriReference->URI()).trimmed();
    } else {
        ObjRef<iface::rdf_api::PlainLiteral> plainLiteral = QueryInterface(pRdfNode);

        if (plainLiteral) {
            // The rdf_api::PlainLiteral interface is supported, so initialise
            // the triple element using that interface

            mType = PlainLiteral;

            mLexicalForm = QString::fromStdWString(plainLiteral->lexicalForm()).trimmed();
            mLanguage    = QString::fromStdWString(plainLiteral->language()).trimmed();
        } else {
            ObjRef<iface::rdf_api::TypedLiteral> typedLiteral = QueryInterface(pRdfNode);

            if (typedLiteral) {
                // The rdf_api::TypedLiteral interface is supported, so
                // initialise the triple element using that interface

                mType = TypedLiteral;

                mLexicalForm = QString::fromStdWString(typedLiteral->lexicalForm()).trimmed();
                mDataTypeUri = QString::fromStdWString(typedLiteral->datatypeURI()).trimmed();
            } else {
                // The node doesn't support any interface, so initialise the
                // triple element using its id
                // Note: the id returned by the CellML API will look something
                //       like
                //
                //          7EQ?;?Y?A?w???A
                //
                //       This is clearly not user-friendly, so we generate and
                //       use our own id instead...

                static QMap<QString, QString> ids;
                static int counter = 0;

                QString id = QString::fromStdString(pRdfNode->objid()).trimmed();

                mType = Id;

                mId = ids.value(id);

                if (mId == QString()) {
                    // There is no id value for the current id, so generate one
                    // and keep track of it

                    mId = QString("id_%1").arg(++counter, 9, 10, QChar('0'));

                    ids.insert(id, mId);
                }
            }
        }
    }

    // Keep track of the RDF triple element's value as a string, which is based
    // on its type

    switch (mType) {
    case UriReference:
        mAsString = mUriReference;

        break;
    case PlainLiteral:
        mAsString = mLexicalForm+" ["+mLanguage+"]";

        break;
    case TypedLiteral:
        mAsString = mLexicalForm+" ["+mDataTypeUri+"]";

        break;
    default:
        // Id

        mAsString = mId;
    }
}