ObjectParser { @Deprecated public List<Annotation> parse(String content, URL documentURL, RDFFormat format, boolean clear) { if (clear) { try { clear(); } catch (RepositoryException | UpdateExecutionException e) { e.printStackTrace(); } } try { readRDF(content, documentURL, format); } catch (RDFParseException | RepositoryException e) { e.printStackTrace(); return new LinkedList<>(); } List<Annotation> annotations = new LinkedList<>(); try { annotations = anno4j.getObjectRepository().getConnection().getObjects(Annotation.class).asList(); } catch (QueryEvaluationException | RepositoryException e) { e.printStackTrace(); } return annotations; } ObjectParser(); void shutdown(); @Deprecated List<Annotation> parse(String content, URL documentURL, RDFFormat format, boolean clear); List<T> parse(Class<? extends T> type, String content, URL documentURL, RDFFormat format, boolean clear);  }
@Test public void testClearing() throws Exception { Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); ObjectParser parser = new ObjectParser(); List<Annotation> annotations = parser.parse(Annotation.class, TURTLE, new URL("http: assertEquals(1, annotations.size()); for(Annotation annotation : annotations) { anno4j.persist(annotation); } Body body1 = anno4j.findByID(Body.class,"http: Annotation anno1 = anno4j.findByID(Annotation.class,"http: assertEquals(Sets.newHashSet(body1), anno1.getBodies()); annotations = parser.parse(Annotation.class, TURTLE2, new URL("http: assertEquals(1, annotations.size()); for(Annotation annotation : annotations) { anno4j.persist(annotation); } Body body2 = anno4j.findByID(Body.class,"http: Annotation anno2 = anno4j.findByID(Annotation.class,"http: assertEquals(Sets.newHashSet(body2), anno2.getBodies()); }
@Test public void testGenericParsing() throws Exception { URL url = new URL("http: ObjectParser parser = new ObjectParser(); List<Sound> sounds = parser.parse(Sound.class, TURTLE_MULTIPLE, url, RDFFormat.TURTLE, true); assertEquals(3, sounds.size()); Collection<String> uris = getResourcesAsStrings(sounds); assertTrue(uris.contains("http: assertTrue(uris.contains("http: assertTrue(uris.contains("http: List<ResourceObject> resources = parser.parse(ResourceObject.class, TURTLE_MULTIPLE, url, RDFFormat.TURTLE, true); assertEquals(15, resources.size()); uris = getResourcesAsStrings(resources); assertTrue(uris.contains("http: assertTrue(uris.contains("http: assertTrue(uris.contains("http: assertTrue(uris.contains("http: assertTrue(uris.contains("http: assertTrue(uris.contains("http: assertTrue(uris.contains("http: assertTrue(uris.contains("http: assertTrue(uris.contains("http: }