2 |
|
|
3 |
package org.fenfire.impl; |
package org.fenfire.impl; |
4 |
import java.io.StringBufferInputStream; |
import java.io.StringBufferInputStream; |
|
import com.hp.hpl.mesa.rdf.jena.model.*; |
|
5 |
|
|
6 |
import org.nongnu.alph.Enfilade1D; |
import org.nongnu.alph.Enfilade1D; |
7 |
import org.nongnu.alph.xml.SpanReader; |
import org.nongnu.alph.xml.SpanReader; |
9 |
|
|
10 |
import org.fenfire.*; |
import org.fenfire.*; |
11 |
import org.fenfire.vocab.FF; |
import org.fenfire.vocab.FF; |
12 |
import org.fenfire.util.ShortRDF; |
import org.fenfire.swamp.Nodes; |
13 |
|
import org.fenfire.swamp.Literal; |
14 |
|
|
15 |
|
|
16 |
/** A trivial, NON-CACHING node content using FF.content. |
/** A trivial, NON-CACHING node content using FF.content. |
19 |
*/ |
*/ |
20 |
|
|
21 |
public class SimpleNodeContent implements NodeContent { |
public class SimpleNodeContent implements NodeContent { |
22 |
|
public static boolean dbg = true; |
23 |
public static final String rcsid = "$Id$"; |
public static final String rcsid = "$Id$"; |
24 |
private static void pa(String s) { System.out.println("AlphContent: "+s); } |
private static void pa(String s) { System.out.println("AlphContent: "+s); } |
25 |
SpanReader spanReader = new SpanReader(); |
SpanReader spanReader = new SpanReader(); |
28 |
|
|
29 |
Enfilade1D.Maker enfMaker = |
Enfilade1D.Maker enfMaker = |
30 |
new org.nongnu.alph.impl.Enfilade1DImpl.Enfilade1DImplMaker(); |
new org.nongnu.alph.impl.Enfilade1DImpl.Enfilade1DImplMaker(); |
31 |
|
Enfilade1D empty = enfMaker.makeEnfilade(); |
32 |
|
|
33 |
Fen fen; |
Fen fen; |
34 |
|
|
41 |
this.fen = fen; |
this.fen = fen; |
42 |
} |
} |
43 |
|
|
44 |
public org.nongnu.alph.Enfilade1D get(RDFNode node) { |
public NodeContent _getObserved(Fen obsFen, |
45 |
|
Obs obs) { |
46 |
|
// We don't need to use obs since the graph will do it for us. |
47 |
|
return new SimpleNodeContent(obsFen); |
48 |
|
} |
49 |
|
public void _close() { } |
50 |
|
|
51 |
|
public org.nongnu.alph.Enfilade1D get(Object node) { |
52 |
|
return get(node, null); |
53 |
|
} |
54 |
|
|
55 |
|
public org.nongnu.alph.Enfilade1D get(Object node, Obs o) { |
56 |
|
Object c = fen.constgraph.find1_11X(node, FF.content, o); |
57 |
|
if(dbg) pa("Getting content: "+node+" "+c); |
58 |
|
if(c == null) return empty; |
59 |
|
|
60 |
|
if(!(c instanceof Literal)) { |
61 |
|
if(dbg) pa("Was not literal: "+c); |
62 |
|
throw new Error("Content not literal"); |
63 |
|
} |
64 |
|
|
65 |
try { |
try { |
66 |
if(!((Resource)node).hasProperty(FF.content)) return null; |
saxParser.parse(new StringBufferInputStream( |
67 |
// XXX Ambiguity!! |
((Literal)c).getRawXMLString()), spanReader); |
|
Statement s = ((Resource)node).getProperty(FF.content); |
|
|
Literal lit = s.getLiteral(); |
|
|
saxParser.parse(new StringBufferInputStream(lit.getString()), spanReader); |
|
68 |
|
|
|
|
|
69 |
} catch (Exception e) { |
} catch (Exception e) { |
70 |
pa("Exception!: "+e); |
pa("Exception!: "+e); |
71 |
throw new Error("getspan has an Exception!"); |
throw new Error("Get enfilade: parse Exception!"); |
72 |
} |
} |
73 |
|
|
74 |
Enfilade1D enf = enfMaker.makeEnfilade(spanReader.getSpans()); |
Enfilade1D enf = enfMaker.makeEnfilade(spanReader.getSpans()); |
76 |
return enf; |
return enf; |
77 |
} |
} |
78 |
|
|
79 |
public void set(RDFNode node, org.nongnu.alph.Enfilade1D vstream) { |
public void set(Object node, org.nongnu.alph.Enfilade1D vstream) { |
80 |
String ser = SpanSerializer.serialize(vstream); |
String ser = SpanSerializer.serialize(vstream); |
81 |
ShortRDF.rmObj(fen.model, node, FF.content); |
fen.graph.set1_11X(node, FF.content, Nodes.getRawXMLLiteral(ser)); |
|
try { |
|
|
fen.model.add((Resource)node, FF.content, ser, true); |
|
|
} catch(Exception e) { |
|
|
throw new Error("E"); |
|
|
} |
|
82 |
} |
} |
83 |
} |
} |