File tree Expand file tree Collapse file tree
core/model/src/main/java/org/eclipse/rdf4j/model/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) 2017 Eclipse RDF4J contributors, and others.
3+ * All rights reserved. This program and the accompanying materials
4+ * are made available under the terms of the Eclipse Distribution License v1.0
5+ * which accompanies this distribution, and is available at
6+ * http://www.eclipse.org/org/documents/edl-v10.php.
7+ */
8+ package org .eclipse .rdf4j .model .util ;
9+
10+ import java .lang .reflect .Field ;
11+ import java .lang .reflect .Modifier ;
12+ import java .util .HashSet ;
13+ import java .util .Set ;
14+
15+ import org .eclipse .rdf4j .model .IRI ;
16+
17+ /**
18+ * Utility functions for working with vocabularies.
19+ *
20+ * @author Bart Hanssens
21+ */
22+ public class VocabUtil {
23+
24+ /**
25+ * Get all the {@link IRI IRIs} of the classes and properties of a vocabulary.
26+ *
27+ * @param vocabulary RDF vocabulary
28+ * @return set of IRIs
29+ */
30+ public static Set <IRI > getVocabularyIRIs (Class vocabulary ) {
31+ Set <IRI > iris = new HashSet <>();
32+
33+ for (Field f : vocabulary .getFields ()) {
34+ if (f .getType ().equals (IRI .class ) && Modifier .isPublic (f .getModifiers ())) {
35+ try {
36+ iris .add ((IRI ) f .get (f ));
37+ } catch (IllegalArgumentException |IllegalAccessException ex ) {
38+ // should not happen
39+ }
40+ }
41+ }
42+ return iris ;
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments