/** * creates and returns an <code>RdfList</code> for the node and * Graph represented by this object. * * @return a List to easy access the rdf:List represented by this node */ public List<RDFTerm> asList() { if (resource instanceof BlankNodeOrIRI) { return new RdfList((BlankNodeOrIRI) resource, graph); } else { throw new RuntimeException("Literals cannot be the subject of a List"); } }
@Override public RDFTerm get(int index) { expandTill(index + 1); return valueList.get(index); }
/** * Returns the rdf lists of which the specified <code>GraphNode</code> is * an element of. Sublists of other lists are not returned. * * @param element * @return */ public static Set<RdfList> findContainingLists(GraphNode element) { Set<GraphNode> listNodes = findContainingListNodes(element); if (listNodes.isEmpty()) { return null; } Set<RdfList> rdfLists = new HashSet<RdfList>(); for (Iterator<GraphNode> it = listNodes.iterator(); it.hasNext();) { GraphNode listNode = it.next(); rdfLists.add(new RdfList(listNode)); } return rdfLists; }
private void instantiateConceptProviders() { conceptProviderList.clear(); MGraph contentGraph = cgProvider.getContentGraph(); NonLiteral cplNode = getConceptProviderListNode(contentGraph); RdfList cpl = new RdfList(cplNode, contentGraph); for (int i = 0; i < cpl.size(); i++) { NonLiteral conceptProvider = (NonLiteral) cpl.get(i); Iterator<Triple> conceptProviderTypes = contentGraph.filter( conceptProvider, RDF.type, null); if (conceptProviderTypes.hasNext()) { UriRef conceptProviderType = (UriRef) conceptProviderTypes.next().getObject(); if (conceptProviderType.equals(CONCEPTS.LocalConceptProvider)) { instantiateLocalConceptProvider(contentGraph, conceptProvider); } else { instantiateRemoteConceptProvider(contentGraph, conceptProvider); } } } }
private GraphNode getScriptList( @QueryParam(value = "resource") NonLiteral resource) { AccessController.checkPermission(new ScriptManagerAppPermission()); if(resource == null) { resource = new BNode(); } BNode resultResource = new BNode(); MGraph contentGraph = cgProvider.getContentGraph(); MGraph additionGraph = new SimpleMGraph(); UnionMGraph resultGraph = new UnionMGraph(additionGraph, contentGraph); RdfList list = RdfList.createEmptyList(resultResource, additionGraph); resultGraph.add(new TripleImpl(resource, SCRIPTMANAGER.scriptList, resultResource)); resultGraph.add(new TripleImpl(resultResource, RDF.type, SCRIPTMANAGER.ScriptList)); Iterator<Triple> it = contentGraph.filter(null, RDF.type, SCRIPT.Script); while (it.hasNext()) { list.add(it.next().getSubject()); } return new GraphNode(resultResource, new UnionMGraph(resultGraph, contentGraph)); }
@Override public void add(int index, RDFTerm element) { expandTill(index); if (index == 0) { //special casing to make sure the first list remains the same resource if (listList.size() == 0) { tc.remove(new TripleImpl(firstList, OWL.sameAs, RDF_NIL)); tc.add(new TripleImpl(firstList, RDF.rest, RDF_NIL)); tc.add(new TripleImpl(firstList, RDF.first, element)); listList.add(firstList); } else { tc.remove(new TripleImpl(listList.get(0), RDF.first, valueList.get(0))); tc.add(new TripleImpl(listList.get(0), RDF.first, element)); addInRdfList(1, valueList.get(0)); } } else { addInRdfList(index, element); } valueList.add(index, element); }
private GraphNode addLanguages(GraphNode node, NonLiteral platformInstance, List<LanguageDescription> languages, boolean copyToNode) { TripleCollection graph = node.getGraph(); BNode listNode = new BNode(); RdfList list = new RdfList(listNode, graph); LockableMGraph configGraph = getConfigGraph(); Lock readLock = configGraph.getLock().readLock(); for (LanguageDescription languageDescription : languages) { NonLiteral languageUri = (NonLiteral) languageDescription.getResource().getNode(); list.add(languageUri); if (copyToNode) { readLock.lock(); try { graph.addAll(new GraphNode(languageUri, configGraph).getNodeContext()); } finally { readLock.unlock(); } } } node.addProperty(PLATFORM.instance, platformInstance); graph.add(new TripleImpl(platformInstance, RDF.type, PLATFORM.Instance)); graph.add(new TripleImpl(platformInstance, PLATFORM.languages, listNode)); graph.add(new TripleImpl(listNode, RDF.type, LANGUAGE.LanguageList)); if (!copyToNode) { node = new GraphNode(node.getNode(), new UnionMGraph(graph, configGraph)); } return node; }
/** * Returns the rdf lists of which the specified <code>GraphNode</code> is * an element of. Sublists of other lists are not returned. * * @param element * @return */ public static Set<RdfList> findContainingLists(GraphNode element) { Set<GraphNode> listNodes = findContainingListNodes(element); if (listNodes.isEmpty()) { return null; } Set<RdfList> rdfLists = new HashSet<RdfList>(); for (Iterator<GraphNode> it = listNodes.iterator(); it.hasNext();) { GraphNode listNode = it.next(); rdfLists.add(new RdfList(listNode)); } return rdfLists; }
@Override public void add(int index, RDFTerm element) { expandTill(index); if (index == 0) { //special casing to make sure the first list remains the same resource if (listList.size() == 0) { tc.remove(new TripleImpl(firstList, OWL.sameAs, RDF_NIL)); tc.add(new TripleImpl(firstList, RDF.rest, RDF_NIL)); tc.add(new TripleImpl(firstList, RDF.first, element)); listList.add(firstList); } else { tc.remove(new TripleImpl(listList.get(0), RDF.first, valueList.get(0))); tc.add(new TripleImpl(listList.get(0), RDF.first, element)); addInRdfList(1, valueList.get(0)); } } else { addInRdfList(index, element); } valueList.add(index, element); }
/** * creates and returns an <code>RdfList</code> for the node and * Graph represented by this object. * * @return a List to easy access the rdf:List represented by this node */ public List<RDFTerm> asList() { if (resource instanceof BlankNodeOrIRI) { return new RdfList((BlankNodeOrIRI) resource, graph); } else { throw new RuntimeException("Literals cannot be the subject of a List"); } }
private NonLiteral itemsAsRdfList(SortedSet<GlobalMenuItem> menus, TripleCollection mGraph) { NonLiteral result = new BNode(); RdfList list = new RdfList(result, mGraph); for (GlobalMenuItem item : menus) { BNode node = new BNode(); final String label = item.getLabel(); Literal labelLiteral = new PlainLiteralImpl(label); mGraph.add(new TripleImpl(node, RDFS.label,labelLiteral)); final String description = item.getDescription(); if (description != null) { Literal descLiteral = new PlainLiteralImpl(description); mGraph.add(new TripleImpl(node, DCTERMS.description, descLiteral)); } final String path = item.getPath(); if (path != null) { Literal pathLiteral = LiteralFactory.getInstance(). createTypedLiteral(path); mGraph.add(new TripleImpl(node, GLOBALMENU.path, pathLiteral)); } mGraph.add(new TripleImpl(node, RDF.type, GLOBALMENU.MenuItem)); list.add(node); } return result; } }
@Override public int size() { expandTill(Integer.MAX_VALUE); return valueList.size(); }
private List<Resource> getPropertyList(GraphNode r) { Iterator<GraphNode> propertyLists = r.getObjectNodes(CRIS.propertyList); if (propertyLists.hasNext()) { List<Resource> rdfList = new RdfList(propertyLists.next()); return rdfList; } throw new RuntimeException("There is no propertyList on this definition."); }
@Override public int size() { expandTill(Integer.MAX_VALUE); return valueList.size(); }
/** if value id an rdf:list in tc, initialize list * @param tc */ private void doListInitialization(Graph tc) { if (value instanceof BlankNodeOrIRI) { if ((tc.filter((BlankNodeOrIRI) value, RDF.rest, null).hasNext()) || (tc.filter((BlankNodeOrIRI) value, OWL.sameAs, RDF_NIL).hasNext())) { list = new RdfList((BlankNodeOrIRI) value, tc); } } }
@Override public RDFTerm get(int index) { expandTill(index + 1); return valueList.get(index); }
/** * Creates an empty RdfList by writing a triple * "{@code listRDFTerm} owl:sameAs rdf.nil ." to {@code tc}. * * @param listRDFTerm * @param tc * @return an empty rdf:List. * @throws IllegalArgumentException * if the provided {@code listRDFTerm} is a non-empty rdf:List. */ public static RdfList createEmptyList(BlankNodeOrIRI listRDFTerm, Graph tc) throws IllegalArgumentException { if (!tc.filter(listRDFTerm, RDF.first, null).hasNext()) { RdfList list = new RdfList(listRDFTerm, tc); list.tc.add(new TripleImpl(listRDFTerm, OWL.sameAs, RDF_NIL)); return list; } else { throw new IllegalArgumentException(listRDFTerm + "is a non-empty rdf:List."); } }
/** * * @param index is > 0 * @param element */ private void addInRdfList(int index, RDFTerm element) { expandTill(index+1); BlankNodeOrIRI newList = new BlankNode() { }; tc.add(new TripleImpl(newList, RDF.first, element)); if (index < listList.size()) { tc.add(new TripleImpl(newList, RDF.rest, listList.get(index))); tc.remove(new TripleImpl(listList.get(index - 1), RDF.rest, listList.get(index))); } else { tc.remove(new TripleImpl(listList.get(index - 1), RDF.rest, RDF_NIL)); tc.add(new TripleImpl(newList, RDF.rest, RDF_NIL)); } tc.add(new TripleImpl(listList.get(index - 1), RDF.rest, newList)); listList.add(index, newList); }