KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > serialization > rdf > RDFTypeLabelSerializer


1 package org.snipsnap.serialization.rdf;
2
3 import java.util.List JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import com.hp.hpl.mesa.rdf.jena.model.*;
6 import com.hp.hpl.mesa.rdf.jena.vocabulary.RDF;
7 import com.hp.hpl.mesa.rdf.jena.common.ResourceImpl;
8
9 import org.snipsnap.snip.Snip;
10 import org.snipsnap.snip.label.Label;
11 import org.snipsnap.serialization.LabelContext;
12 import org.snipsnap.serialization.LabelSerializer;
13 import org.snipsnap.serialization.SerializerFactory;
14 import org.snipsnap.serialization.rdf.vocabulary.LABEL;
15 import org.snipsnap.serialization.rdf.vocabulary.SNIP;
16
17 /**
18  * Implements the serialization of SnipLabels to RDF.
19  * @author gis
20  */

21 public class RDFTypeLabelSerializer implements LabelSerializer {
22
23     public void serialize(LabelContext labelContext) {
24         if (!(labelContext instanceof RDFLabelContext))
25             throw new RuntimeException JavaDoc("RDFTypeLabelSerializer expects an RDFLabelContext!");
26         RDFLabelContext rdfLabelContext = (RDFLabelContext) labelContext;
27         Label label = rdfLabelContext.label;
28         Resource snipResource = rdfLabelContext.snipResource;
29         try {
30             snipResource.addProperty(RDF.type, label.getValue());
31         } catch (RDFException re) {
32             re.printStackTrace();
33         }
34     }
35
36     public List JavaDoc getSupportedLabelTypes() {
37         return s_supportedTypes;
38     }
39
40     public int getOutputFormat() {
41         return SerializerFactory.RDF_10;
42     }
43
44     private static List JavaDoc s_supportedTypes;
45
46     static {
47         s_supportedTypes = new ArrayList JavaDoc();
48         s_supportedTypes.add("TypeLabel");
49     }
50 }
51
Popular Tags