Dataquay::TypeMapping Class Reference

TypeMapping describes a set of relationships between RDF entity and property URIs, and C++ class and QObject property names. More...

#include <TypeMapping.h>

List of all members.

Public Member Functions

 TypeMapping ()
 Construct a TypeMapping using default URIs throughout.
 TypeMapping (const TypeMapping &)
TypeMappingoperator= (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)
 Retrieve the URI that has been set for the given class name using addTypeMapping, returning it in uri.
bool getClassForTypeUri (Uri uri, QString &className)
 Retrieve the C++ class name that has been set for the given entity URI using addTypeMapping, returning it in className.
Uri synthesiseTypeUriForClass (QString className)
 Return a URI for the RDF entity type corresponding to the given C++ class.
QString synthesiseClassForTypeUri (Uri uri)
 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)
 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)
 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)
 Retrieve the name of the property for which the given URI has been set in the given class using addPropertyMapping, returning it in propertyName.

Detailed Description

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.

 TypeMapping tm;
 tm.addTypeMapping("MyApplication::Person", store->expand("foaf:Person"));
 tm.addPropertyMapping("MyApplication::Person", "name", store->expand("foaf:name"));
 objectStorer->setTypeMapping(tm);

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.


Constructor & Destructor Documentation

Dataquay::TypeMapping::TypeMapping (  ) 

Construct a TypeMapping using default URIs throughout.

Definition at line 181 of file TypeMapping.cpp.

Dataquay::TypeMapping::TypeMapping ( const TypeMapping tm  ) 

Definition at line 186 of file TypeMapping.cpp.

Dataquay::TypeMapping::~TypeMapping (  ) 

Definition at line 201 of file TypeMapping.cpp.


Member Function Documentation

TypeMapping & Dataquay::TypeMapping::operator= ( const TypeMapping tm  ) 

Definition at line 192 of file TypeMapping.cpp.

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.

Definition at line 207 of file TypeMapping.cpp.

Uri Dataquay::TypeMapping::getObjectTypePrefix (  )  const

Retrieve the prefix for synthetic type URIs.

Definition at line 213 of file TypeMapping.cpp.

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.

Definition at line 219 of file TypeMapping.cpp.

Uri Dataquay::TypeMapping::getPropertyPrefix (  )  const

Retrieve the prefix for synthetic property URIs.

Definition at line 225 of file TypeMapping.cpp.

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".

Definition at line 231 of file TypeMapping.cpp.

Uri Dataquay::TypeMapping::getRelationshipPrefix (  )  const

Retrieve the prefix for ObjectMapper-specific property URIs.

Definition at line 237 of file TypeMapping.cpp.

void Dataquay::TypeMapping::addTypeMapping ( QString  className,
Uri  uri 
)

Add a specific mapping from class name to entity URI.

Definition at line 243 of file TypeMapping.cpp.

bool Dataquay::TypeMapping::getTypeUriForClass ( QString  className,
Uri uri 
)

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.

Definition at line 249 of file TypeMapping.cpp.

bool Dataquay::TypeMapping::getClassForTypeUri ( Uri  uri,
QString &  className 
)

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.

Definition at line 255 of file TypeMapping.cpp.

Uri Dataquay::TypeMapping::synthesiseTypeUriForClass ( QString  className  ) 

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 ("/").

Definition at line 261 of file TypeMapping.cpp.

QString Dataquay::TypeMapping::synthesiseClassForTypeUri ( Uri  uri  ) 

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.

Definition at line 267 of file TypeMapping.cpp.

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.

Definition at line 273 of file TypeMapping.cpp.

bool Dataquay::TypeMapping::getUriPrefixForClass ( QString  className,
Uri prefix 
)

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.

Definition at line 279 of file TypeMapping.cpp.

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).

Definition at line 285 of file TypeMapping.cpp.

bool Dataquay::TypeMapping::getPropertyUri ( QString  className,
QString  propertyName,
Uri uri 
)

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.

Definition at line 291 of file TypeMapping.cpp.

bool Dataquay::TypeMapping::getPropertyName ( QString  className,
Uri  propertyUri,
QString &  propertyName 
)

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.

Definition at line 297 of file TypeMapping.cpp.


The documentation for this class was generated from the following files:
Generated on Thu May 17 22:54:21 2012 for Dataquay by  doxygen 1.6.3