Skip to content

Commit

Permalink
[#274] Add StreamResourceHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Sep 25, 2024
1 parent 3a85d2a commit 6717114
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.cvut.spipes.modules.handlers;

import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.registry.StreamResource;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.topbraid.spin.model.Select;
Expand Down Expand Up @@ -59,6 +60,7 @@ private void initHandlers() {
registerHandler(Path.class, PathHandler.class);
registerHandler(Resource.class, ResourceHandler.class);
registerHandler(List.class, ListHandler.class);
registerHandler(StreamResource.class, StreamResourceHandler.class);
}

public synchronized Handler getHandler(Class clazz, Resource resource, ExecutionContext context, Setter setter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cz.cvut.spipes.modules.handlers;

import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.exception.ResourceNotFoundException;
import cz.cvut.spipes.registry.StreamResource;
import cz.cvut.spipes.registry.StreamResourceRegistry;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;

public class StreamResourceHandler extends BaseRDFNodeHandler<StreamResource> {

public StreamResourceHandler(Resource resource, ExecutionContext executionContext, Setter<? super StreamResource> setter) {
super(resource, executionContext, setter);
}

@Override
StreamResource getRDFNodeValue(RDFNode node) throws Exception {
StreamResource res = StreamResourceRegistry.getInstance().getResourceByUrl(node.asLiteral().toString());

if (res == null) {
throw new ResourceNotFoundException("Stream resource " + node.asLiteral().toString() + " not found. ");
}

return res;
}
}

0 comments on commit 6717114

Please sign in to comment.