Dataquay 0.8
|
TypeMapping describes a set of relationships between RDF entity and property URIs, and C++ class and QObject property names. More...
#include <TypeMapping.h>
Public Member Functions | |
TypeMapping () | |
Construct a TypeMapping using default URIs throughout. | |
TypeMapping (const TypeMapping &) | |
TypeMapping & | operator= (const TypeMapping &) |
~TypeMapping () | |
void | setObjectTypePrefix (Uri prefix) |
Set the prefix for synthetic type URIs. | |
Uri | getObjectTypePrefix () const |
Retrieve the prefix for synthetic type URIs. | |
void | setPropertyPrefix (Uri prefix) |
Set the prefix for synthetic property URIs. | |
Uri | getPropertyPrefix () const |
Retrieve the prefix for synthetic property URIs. | |
void | setRelationshipPrefix (Uri prefix) |
Set the prefix for ObjectMapper-specific property URIs. | |
Uri | getRelationshipPrefix () const |
Retrieve the prefix for ObjectMapper-specific property URIs. | |
void | addTypeMapping (QString className, Uri uri) |
Add a specific mapping from class name to entity URI. | |
bool | getTypeUriForClass (QString className, Uri &uri) const |
Retrieve the URI that has been set for the given class name using addTypeMapping, returning it in uri. | |
bool | getClassForTypeUri (Uri uri, QString &className) const |
Retrieve the C++ class name that has been set for the given entity URI using addTypeMapping, returning it in className. | |
Uri | synthesiseTypeUriForClass (QString className) const |
Return a URI for the RDF entity type corresponding to the given C++ class. | |
QString | synthesiseClassForTypeUri (Uri uri) const |
Return a C++ class name corresponding to the given RDF entity type URI. | |
void | addTypeUriPrefixMapping (QString className, Uri prefix) |
Add a mapping between class name and the common parts of any URIs that are automatically generated when storing instances of that class that have no URI property defined. | |
bool | getUriPrefixForClass (QString className, Uri &prefix) const |
Retrieve the URI prefix set for the given className using addTypeUriPrefixMapping, if any, returning it in prefix. | |
void | addPropertyMapping (QString className, QString propertyName, Uri uri) |
Add a specific mapping for the given QObject property in the given C++ class, to an RDF property URI. | |
bool | getPropertyUri (QString className, QString propertyName, Uri &uri) const |
Retrieve the URI that has been set for the given property in the given class using addPropertyMapping, returning it in uri. | |
bool | getPropertyName (QString className, Uri propertyUri, QString &propertyName) const |
Retrieve the name of the property for which the given URI has been set in the given class using addPropertyMapping, returning it in propertyName. | |
TypeMapping describes a set of relationships between RDF entity and property URIs, and C++ class and QObject property names.
The TypeMapping is referred to by ObjectMapper, ObjectStorer and ObjectLoader when mapping between RDF entities and C++ objects.
For example, say we have a class MyApplication::Person, with a QObject string property called "name". We want the class to be stored as a URI with RDF type foaf:Person, and the property to be stored as a relationship for that URI of type foaf:name. These URIs need to be expanded in order to be used with TypeMapping; we assume here that "store" points to a Store which is aware of the "foaf" prefix and can perform that expansion for us through Store::expand.
Now if objectStorer is used to store an object of class MyApplication::Person, it will do so as a foaf:Person. Similarly, whenever ObjectLoader is asked to load a foaf:Person, it will create a MyApplication::Person object to do so.
TypeMapping is re-entrant, but not thread-safe.
!!! TODO: Review method names
Definition at line 76 of file TypeMapping.h.
Dataquay::TypeMapping::TypeMapping | ( | ) |
Construct a TypeMapping using default URIs throughout.
Dataquay::TypeMapping::TypeMapping | ( | const TypeMapping & | ) |
Dataquay::TypeMapping::~TypeMapping | ( | ) |
TypeMapping & Dataquay::TypeMapping::operator= | ( | const TypeMapping & | ) |
void Dataquay::TypeMapping::setObjectTypePrefix | ( | Uri | prefix | ) |
Set the prefix for synthetic type URIs.
This is the prefix used when asked to generate or convert type URIs for which no specific mapping has been set using setTypeMapping. See also synthesiseTypeUriForClass and synthesiseClassForTypeUri.
Uri Dataquay::TypeMapping::getObjectTypePrefix | ( | ) | const |
Retrieve the prefix for synthetic type URIs.
void Dataquay::TypeMapping::setPropertyPrefix | ( | Uri | prefix | ) |
Set the prefix for synthetic property URIs.
This is the prefix used when generating URIs for QObject properties for which no specific mapping has been set using addPropertyMapping, and when converting such URIs back to QObject properties.
Uri Dataquay::TypeMapping::getPropertyPrefix | ( | ) | const |
Retrieve the prefix for synthetic property URIs.
void Dataquay::TypeMapping::setRelationshipPrefix | ( | Uri | prefix | ) |
Set the prefix for ObjectMapper-specific property URIs.
This is the prefix used for object relationship properties such as "parent" or "follows".
Uri Dataquay::TypeMapping::getRelationshipPrefix | ( | ) | const |
Retrieve the prefix for ObjectMapper-specific property URIs.
void Dataquay::TypeMapping::addTypeMapping | ( | QString | className, |
Uri | uri ) |
Add a specific mapping from class name to entity URI.
bool Dataquay::TypeMapping::getTypeUriForClass | ( | QString | className, |
Uri & | uri ) const |
Retrieve the URI that has been set for the given class name using addTypeMapping, returning it in uri.
Return true if such a URI was found, false otherwise.
bool Dataquay::TypeMapping::getClassForTypeUri | ( | Uri | uri, |
QString & | className ) const |
Retrieve the C++ class name that has been set for the given entity URI using addTypeMapping, returning it in className.
Return true if such a name was found, false otherwise.
Uri Dataquay::TypeMapping::synthesiseTypeUriForClass | ( | QString | className | ) | const |
Return a URI for the RDF entity type corresponding to the given C++ class.
If a specific URI has been set for this class name using addTypeMapping (i.e. if getTypeUriForClass would return a result for this class name), the result will be that URI.
Otherwise, the result will consist of the synthetic type URI prefix (set using setObjectTypePrefix, or the default synthetic type URI prefix if none has been set) followed by the class name, with all namespace separators ("::") replaced by slashes ("/").
QString Dataquay::TypeMapping::synthesiseClassForTypeUri | ( | Uri | uri | ) | const |
Return a C++ class name corresponding to the given RDF entity type URI.
If a specific class name has been set for this URI using addTypeMapping (i.e. if getClassForTypeUri would return a result for this URI), the result will be that class name.
Otherwise, the result will consist of the URI with the synthetic type URI prefix (set using setObjectTypePrefix, or the default synthetic type URI prefix if none has been set) stripped off the beginning, and with subsequent slashes ("/") replaced by namespace separators ("::").
Throws UnknownTypeException if no specific class name is available and the URI does not begin with the synthetic type URI prefix.
void Dataquay::TypeMapping::addTypeUriPrefixMapping | ( | QString | className, |
Uri | prefix ) |
Add a mapping between class name and the common parts of any URIs that are automatically generated when storing instances of that class that have no URI property defined.
For example, a mapping from "MyNamespace::MyClass" to "http://mydomain.com/resource/" would ensure that automatically generated "unique" URIs for instances that class all started with that URI prefix. Note that the prefix itself is also subject to namespace prefix expansion when stored.
(If no prefix mapping was given for this example, its generated URIs would start with ":mynamespace_myclass_".)
Generated URIs are only checked for uniqueness within the store being exported to and cannot be guaranteed to be globally unique. For this reason, caution should be exercised in the use of this function.
Note that in principle the object mapper could use this when loading, to infer class types for URIs in the store that have no rdf:type. In practice that does not happen – the object mapper will not generate a class for URIs without rdf:type.
bool Dataquay::TypeMapping::getUriPrefixForClass | ( | QString | className, |
Uri & | prefix ) const |
Retrieve the URI prefix set for the given className using addTypeUriPrefixMapping, if any, returning it in prefix.
Return true if such a prefix was found, false otherwise.
void Dataquay::TypeMapping::addPropertyMapping | ( | QString | className, |
QString | propertyName, | ||
Uri | uri ) |
Add a specific mapping for the given QObject property in the given C++ class, to an RDF property URI.
Note that distinct properties of the same class must map to distinct URIs. If two properties of a class map to the same URI, ObjectLoader will not be able to distinguish between them (it does not attempt to resolve ambiguities using the type of the argument, for example).
bool Dataquay::TypeMapping::getPropertyUri | ( | QString | className, |
QString | propertyName, | ||
Uri & | uri ) const |
Retrieve the URI that has been set for the given property in the given class using addPropertyMapping, returning it in uri.
Return true if such a URI was found, false otherwise.
bool Dataquay::TypeMapping::getPropertyName | ( | QString | className, |
Uri | propertyUri, | ||
QString & | propertyName ) const |
Retrieve the name of the property for which the given URI has been set in the given class using addPropertyMapping, returning it in propertyName.
Return true if such a property was found, false otherwise.