Author: mir
Date: Tue Mar 2 15:56:00 2010
New Revision: 918086
URL: http://svn.apache.org/viewvc?rev=918086&view=rev
Log:
CLEREZZA-20: added "supportedFormat" service property to JenaSerializerProvider
so it is possible to bind this service depending on its supported formats
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.serializer/src/main/java/org/apache/clerezza/rdf/jena/serializer/JenaSerializerProvider.java
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.serializer/src/main/java/org/apache/clerezza/rdf/jena/serializer/JenaSerializerProvider.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.serializer/src/main/java/org/apache/clerezza/rdf/jena/serializer/JenaSerializerProvider.java?rev=918086&r1=918085&r2=918086&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.serializer/src/main/java/org/apache/clerezza/rdf/jena/serializer/JenaSerializerProvider.java
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.serializer/src/main/java/org/apache/clerezza/rdf/jena/serializer/JenaSerializerProvider.java
Tue Mar 2 15:56:00 2010
@@ -16,68 +16,73 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.clerezza.rdf.jena.serializer;
-
-import java.io.OutputStream;
-
-import org.apache.clerezza.rdf.core.serializedform.SerializingProvider;
-import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
-import org.apache.clerezza.rdf.jena.facade.JenaGraph;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.RDFWriter;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import
org.apache.clerezza.rdf.core.serializedform.UnsupportedSerializationFormatException;
-/**
- * A {...@link
org.apache.clerezza.rdf.core.serializedform.SerializingProvider} based on Jena
- *
- * @author mir
- *
- * @scr.component immediate="true"
- * @scr.service
interface="org.apache.clerezza.rdf.core.serializedform.SerializingProvider"
- */
-/*
- * see http://jena.sourceforge.net/IO/iohowto.html
- */
-...@supportedformat({SupportedFormat.RDF_XML,
- SupportedFormat.TURTLE, SupportedFormat.X_TURTLE,
- SupportedFormat.N_TRIPLE, SupportedFormat.N3})
-public class JenaSerializerProvider implements SerializingProvider {
-
- @Override
- public void serialize(OutputStream serializedGraph, TripleCollection tc,
- String formatIdentifier) {
- String jenaFormat = getJenaFormat(formatIdentifier);
- com.hp.hpl.jena.graph.Graph graph = new JenaGraph(tc);
- Model model = ModelFactory.createModelForGraph(graph);
- RDFWriter writer = model.getWriter(jenaFormat);
- if ("RDF/XML".equals(jenaFormat)) {
- //jena complains about some URIs that aren't truely bad
- //see:
http://tech.groups.yahoo.com/group/jena-dev/message/38313
- writer.setProperty("allowBadURIs", Boolean.TRUE);
- }
- writer.write(model, serializedGraph, "");
- }
-
- private String getJenaFormat(String formatIdentifier) {
- int semicolonPos = formatIdentifier.indexOf(';');
- if (semicolonPos > -1) {
- formatIdentifier = formatIdentifier.substring(0,
semicolonPos);
- }
- if (formatIdentifier.equals(SupportedFormat.RDF_XML)) {
- return "RDF/XML";
- }
- if (formatIdentifier.equals(SupportedFormat.TURTLE) ||
-
formatIdentifier.equals(SupportedFormat.X_TURTLE)) {
- return "TURTLE";
- }
- if (formatIdentifier.equals(SupportedFormat.N3)) {
- return "N3";
- }
- if (formatIdentifier.equals(SupportedFormat.N_TRIPLE)) {
- return "N-TRIPLE";
- }
- throw new
UnsupportedSerializationFormatException(formatIdentifier);
- }
-}
+package org.apache.clerezza.rdf.jena.serializer;
+
+import java.io.OutputStream;
+
+import org.apache.clerezza.rdf.core.serializedform.SerializingProvider;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.clerezza.rdf.jena.facade.JenaGraph;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.RDFWriter;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import
org.apache.clerezza.rdf.core.serializedform.UnsupportedSerializationFormatException;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+/**
+ * A {...@link
org.apache.clerezza.rdf.core.serializedform.SerializingProvider} based on Jena
+ *
+ * @author mir
+ */
+/*
+ * see http://jena.sourceforge.net/IO/iohowto.html
+ */
+...@component
+...@service(SerializingProvider.class)
+...@property(name="supportedFormat", value={SupportedFormat.RDF_XML,
+ SupportedFormat.TURTLE, SupportedFormat.X_TURTLE,
+ SupportedFormat.N_TRIPLE, SupportedFormat.N3})
+...@supportedformat({SupportedFormat.RDF_XML,
+ SupportedFormat.TURTLE, SupportedFormat.X_TURTLE,
+ SupportedFormat.N_TRIPLE, SupportedFormat.N3})
+public class JenaSerializerProvider implements SerializingProvider {
+
+ @Override
+ public void serialize(OutputStream serializedGraph, TripleCollection tc,
+ String formatIdentifier) {
+ String jenaFormat = getJenaFormat(formatIdentifier);
+ com.hp.hpl.jena.graph.Graph graph = new JenaGraph(tc);
+ Model model = ModelFactory.createModelForGraph(graph);
+ RDFWriter writer = model.getWriter(jenaFormat);
+ if ("RDF/XML".equals(jenaFormat)) {
+ //jena complains about some URIs that aren't truely bad
+ //see:
http://tech.groups.yahoo.com/group/jena-dev/message/38313
+ writer.setProperty("allowBadURIs", Boolean.TRUE);
+ }
+ writer.write(model, serializedGraph, "");
+ }
+
+ private String getJenaFormat(String formatIdentifier) {
+ int semicolonPos = formatIdentifier.indexOf(';');
+ if (semicolonPos > -1) {
+ formatIdentifier = formatIdentifier.substring(0,
semicolonPos);
+ }
+ if (formatIdentifier.equals(SupportedFormat.RDF_XML)) {
+ return "RDF/XML";
+ }
+ if (formatIdentifier.equals(SupportedFormat.TURTLE) ||
+
formatIdentifier.equals(SupportedFormat.X_TURTLE)) {
+ return "TURTLE";
+ }
+ if (formatIdentifier.equals(SupportedFormat.N3)) {
+ return "N3";
+ }
+ if (formatIdentifier.equals(SupportedFormat.N_TRIPLE)) {
+ return "N-TRIPLE";
+ }
+ throw new
UnsupportedSerializationFormatException(formatIdentifier);
+ }
+}