Added: 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/IndexedGraphDeserializerProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/IndexedGraphDeserializerProvider.java?rev=1345253&view=auto
==============================================================================
--- 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/IndexedGraphDeserializerProvider.java
 (added)
+++ 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/IndexedGraphDeserializerProvider.java
 Fri Jun  1 15:48:24 2012
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.contenthub.store.file.serializer;
+
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.indexedgraph.IndexedGraph;
+import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
+
+/**
+ * This {@link ContentPartDeserializerProvider} implementation supports {@link 
IndexedGraph}, {@link Graph}
+ * and {@link TripleCollection} parts. In each case, as a result an {@link 
IndexedGraph} is returned as a
+ * specific implementation.
+ * 
+ * @author suat
+ * 
+ */
+@Component
+@Service
+public class IndexedGraphDeserializerProvider implements 
ContentPartDeserializerProvider {
+
+    @Reference
+    Parser parser;
+
+    @Override
+    public Set<Class<?>> getSupportedContentPartTypes() {
+        Set<Class<?>> supportedClasses = new HashSet<Class<?>>();
+        supportedClasses.add(IndexedGraph.class);
+        supportedClasses.add(Graph.class);
+        supportedClasses.add(TripleCollection.class);
+        return supportedClasses;
+    }
+
+    @Override
+    public <T> T deserialize(InputStream inputStream) throws StoreException {
+        return deserialize(inputStream, null);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> T deserialize(InputStream inputStream, String mediaType) throws 
StoreException {
+        mediaType = (mediaType == null || mediaType.trim().equals("")) ? 
SupportedFormat.RDF_XML : mediaType;
+        return (T) new IndexedGraph(parser.parse(inputStream, mediaType));
+    }
+
+    @Override
+    public <T> T deserialize(InputStream inputStream, String mediaType, 
Map<String,List<String>> headers) throws StoreException {
+        throw new UnsupportedOperationException(
+                "This deserializer does not support specifiying header 
values");
+    }
+}

Added: 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/IndexedMGraphDeserializerProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/IndexedMGraphDeserializerProvider.java?rev=1345253&view=auto
==============================================================================
--- 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/IndexedMGraphDeserializerProvider.java
 (added)
+++ 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/IndexedMGraphDeserializerProvider.java
 Fri Jun  1 15:48:24 2012
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.contenthub.store.file.serializer;
+
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
+import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
+
+/**
+ * This {@link ContentPartDeserializerProvider} implementation supports {@link 
IndexedMGraph}, {@link MGraph}
+ * and {@link TripleCollection} parts. In each case, as a result an {@link 
IndexedMGraph} is returned as a
+ * specific implementation.
+ * 
+ * @author suat
+ * 
+ */
+@Component
+@Service
+public class IndexedMGraphDeserializerProvider implements 
ContentPartDeserializerProvider {
+
+    @Reference
+    private Parser parser;
+
+    @Override
+    public Set<Class<?>> getSupportedContentPartTypes() {
+        Set<Class<?>> supportedClasses = new HashSet<Class<?>>();
+        supportedClasses.add(IndexedMGraph.class);
+        supportedClasses.add(MGraph.class);
+        supportedClasses.add(TripleCollection.class);
+        return supportedClasses;
+    }
+
+    @Override
+    public <T> T deserialize(InputStream inputStream) throws StoreException {
+        return deserialize(inputStream, null);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> T deserialize(InputStream inputStream, String mediaType) throws 
StoreException {
+        mediaType = (mediaType == null || mediaType.trim().equals("")) ? 
SupportedFormat.RDF_XML : mediaType;
+        return (T) new IndexedMGraph(parser.parse(inputStream, mediaType));
+    }
+
+    @Override
+    public <T> T deserialize(InputStream inputStream, String mediaType, 
Map<String,List<String>> headers) throws StoreException {
+        throw new UnsupportedOperationException(
+                "This deserializer does not support specifiying header 
values");
+    }
+
+}

Added: 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/TripleCollectionSerializerProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/TripleCollectionSerializerProvider.java?rev=1345253&view=auto
==============================================================================
--- 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/TripleCollectionSerializerProvider.java
 (added)
+++ 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/serializer/TripleCollectionSerializerProvider.java
 Fri Jun  1 15:48:24 2012
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.contenthub.store.file.serializer;
+
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
+
+/**
+ * {@link ContentPartSerializerProvider} for {@link TripleCollection} objects. 
It serializes
+ * {@link TripleCollection} using the {@link Serializer} in {@link 
SupportedFormat#RDF_XML} format.
+ * 
+ * @author suat
+ * 
+ */
+@Component(immediate = true)
+@Service
+public class TripleCollectionSerializerProvider implements 
ContentPartSerializerProvider {
+
+    @Reference
+    private Serializer serializer;
+
+    @Override
+    public List<Class<?>> getSupportedContentPartTypes() {
+        return Arrays.asList(new Class<?>[] {TripleCollection.class});
+    }
+
+    @Override
+    public <T> void serialize(OutputStream outputStream, T contentPart) throws 
StoreException {
+        try {
+            serializer.serialize(outputStream, (TripleCollection) contentPart, 
SupportedFormat.RDF_XML);
+        } catch (UnsupportedFormatException e) {
+            throw new StoreException("Failed to serialized the content part", 
e);
+        }
+    }
+}


Reply via email to