2 using System
.Collections
;
6 public abstract class RdfWriter
: IDisposable
, StatementSink
{
10 public abstract NamespaceManager Namespaces { get; }
12 public string BaseUri
{
21 protected object GetResourceKey(Resource resource
) {
22 return resource
.GetResourceKey(this);
25 protected void SetResourceKey(Resource resource
, object value) {
26 resource
.SetResourceKey(this, value);
29 internal static TextWriter
GetWriter(string dest
) {
32 return new StreamWriter(dest
);
35 bool StatementSink
.Add(Statement statement
) {
40 public void Add(Statement statement
) {
41 if (statement
.AnyNull
)
42 throw new ArgumentNullException();
44 string s
= getUri(statement
.Subject
);
45 string p
= getUri(statement
.Predicate
);
47 if (statement
.Object
is Literal
) {
48 Literal lit
= (Literal
)statement
.Object
;
49 WriteStatement(s
, p
, lit
);
51 string o
= getUri((Entity
)statement
.Object
);
52 WriteStatement(s
, p
, o
);
56 private string getUri(Entity e
) {
57 if (e
.Uri
!= null) return e
.Uri
;
58 string uri
= (string)GetResourceKey(e
);
59 if (uri
!= null) return uri
;
60 uri
= CreateAnonymousEntity();
61 SetResourceKey(e
, uri
);
65 public abstract void WriteStatement(string subj
, string pred
, string obj
);
67 public abstract void WriteStatement(string subj
, string pred
, Literal literal
);
69 public abstract string CreateAnonymousEntity();
71 public virtual void Close() {
76 void IDisposable
.Dispose() {