RdfLocalResource class

Marks a Dart class as a local RDF resource (referred to via a blank node).

Local resources represent embedded entities that don't need globally unique identifiers and whose identity depends on the context of their parent resource.

Unlike @RdfGlobalResource, instances with this annotation will be mapped to blank nodes (anonymous resources) rather than resources with IRIs. Instances of the annotated class will be mapped to blank nodes in RDF triples by a corresponding mapper - either a mapper generated automatically from this annotation, or a mapper that you implement manually and register with locorda_rdf_mapper.

With custom (i.e. manually implemented) mappers, the actual RDF triple generation depends on your mapper implementation, regardless of any property annotations.

When using the standard constructor (@RdfLocalResource(classIri)), a mapper is automatically generated based on the property annotations (like @RdfProperty) in your class. By default, this mapper is registered within initRdfMapper (when registerGlobally is true). This generated mapper will create RDF triples with the blank node as the subject for each annotated property.

Set registerGlobally to false if this mapper should not be registered automatically. This is useful when the mapper requires constructor parameters that are only available at runtime and should be provided via @RdfProvides annotations in the parent class.

Use this for value objects or components that only make sense in the context of their parent entity.

You can use this annotation in several ways, depending on your mapping needs:

  1. Standard: With a class IRI (@RdfLocalResource(classIri)) - the mapper is automatically generated and registered within initRdfMapper when registerGlobally is true, which is the default
  2. Named mapper: With @RdfLocalResource.namedMapper() - you must implement the mapper, instantiate it, and provide it to initRdfMapper as a named parameter
  3. Mapper type: With @RdfLocalResource.mapper() - you must implement the mapper, it will be instantiated and registered within initRdfMapper automatically
  4. Mapper instance: With @RdfLocalResource.mapperInstance() - you must implement the mapper, your instance will be registered within initRdfMapper automatically

Example:

@RdfGlobalResource(SchemaBook.classIri, IriStrategy('http://example.org/book/{id}'))
class Book {
  // ...
  @RdfProperty(SchemaBook.hasPart)
  final Iterable<Chapter> chapters;
}

@RdfLocalResource(SchemaChapter.classIri)
class Chapter {
  @RdfProperty(SchemaChapter.name)
  final String title;

  @RdfProperty(SchemaChapter.position)
  final int number;
  // ...
}
Inheritance
Implemented types

Constructors

RdfLocalResource([IriTerm? classIri, bool registerGlobally = true, MapperDirection direction = MapperDirection.both])
Creates an annotation for a class whose instances will be mapped to RDF blank nodes.
const
RdfLocalResource.mapper(Type mapperType, {MapperDirection direction = MapperDirection.both})
Creates a reference to a mapper that will be instantiated from the given type.
const
RdfLocalResource.mapperInstance(LocalResourceMapper instance, {MapperDirection direction = MapperDirection.both})
Creates a reference to a directly provided mapper instance for this local resource.
const
RdfLocalResource.namedMapper(String name, {MapperDirection direction = MapperDirection.both})
Creates a reference to a named mapper for this local resource.
const

Properties

classIri → IriTerm?
The RDF class IRI for this blank node.
final
direction MapperDirection?
Specifies whether this mapper should handle serialization, deserialization, or both.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
mapper MapperRef<LocalResourceMapper>?
Provides a MapperRef if a custom mapper is specified.
no setterinherited
registerGlobally bool
Controls whether the generated mapper should be registered globally in the initRdfMapper function.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited