PropListsAssembler { public static void open(Assembler assembler, Resource list) { Resource current = list; while (current != null && ! current.equals(RDF.nil)){ Statement firstStmt = current.getProperty(RDF.first); if (firstStmt == null) { throw new TextIndexException("text:propLists list not well formed: " + current); } RDFNode first = firstStmt.getObject(); if (! first.isResource()) { throw new TextIndexException("text:propLists element must be an anon resource : " + first); } Resource adding = (Resource) first; if (adding.hasProperty(TextVocab.pPropListProp)) { Statement propListPropStmt = adding.getProperty(TextVocab.pPropListProp); RDFNode propListPropNode = propListPropStmt.getObject(); if (!propListPropNode.isResource()) { throw new TextIndexException("text:propLists text:propListProp must be a resource: " + propListPropNode); } if (adding.hasProperty(TextVocab.pProps)) { Statement propsStmt = adding.getProperty(TextVocab.pProps); List<Resource> props = getPropsList(propsStmt); Util.addPropsList((Resource) propListPropNode, props); } } else { throw new TextIndexException("text:propLists text:propListProp must be a resource: " + adding.getProperty(TextVocab.pPropListProp)); } Statement restStmt = current.getProperty(RDF.rest); if (restStmt == null) { throw new TextIndexException("text:propLists list not terminated by rdf:nil"); } RDFNode rest = restStmt.getObject(); if (! rest.isResource()) { throw new TextIndexException("text:propLists list rest is not a resource : " + rest); } current = (Resource) rest; } }  static void open(Assembler assembler, Resource list);  }
@Test public void PropsListsNull() { int before = Util.sizePropsList(); PropListsAssembler.open(null, spec0); int after = Util.sizePropsList(); assertEquals(before, after); }
@Test public void PropsListsOneWithNone() { int before = Util.sizePropsList(); PropListsAssembler.open(null, spec1); int after = Util.sizePropsList(); assertEquals(before+1, after); Resource listProp = ResourceFactory.createResource(SKOS.getURI()+"list1"); List<Resource> pList = Util.getPropList(listProp); assertNotNull(pList); assertEquals(pList.size(), 0); }
@Test public void PropsListsOneWithThree() { int before = Util.sizePropsList(); PropListsAssembler.open(null, spec2); int after = Util.sizePropsList(); assertEquals(before+1, after); Resource listProp = ResourceFactory.createResource(SKOS.getURI()+"labels"); List<Resource> pList = Util.getPropList(listProp); assertNotNull(pList); assertEquals(pList.size(), 3); }
@Test public void PropsListsTwoWith3and5() { int before = Util.sizePropsList(); PropListsAssembler.open(null, spec3); int after = Util.sizePropsList(); assertEquals(before+2, after); Resource listProp = ResourceFactory.createResource(SKOS.getURI()+"labels2"); List<Resource> pList = Util.getPropList(listProp); assertNotNull(pList); assertEquals(pList.size(), 3); listProp = ResourceFactory.createResource(SKOS.getURI()+"stmts"); pList = Util.getPropList(listProp); assertNotNull(pList); assertEquals(pList.size(), 5); }