|
20 | 20 | */ |
21 | 21 | package com.inrupt.client.acp; |
22 | 22 |
|
23 | | -import static com.inrupt.client.vocabulary.RDF.type; |
| 23 | +import static com.inrupt.client.acp.AccessControlResource.asIRI; |
24 | 24 |
|
25 | | -import com.inrupt.client.spi.RDFFactory; |
26 | 25 | import com.inrupt.client.vocabulary.ACP; |
| 26 | +import com.inrupt.client.vocabulary.RDF; |
27 | 27 | import com.inrupt.rdf.wrapping.commons.TermMappings; |
28 | 28 | import com.inrupt.rdf.wrapping.commons.ValueMappings; |
29 | 29 | import com.inrupt.rdf.wrapping.commons.WrapperIRI; |
|
33 | 33 |
|
34 | 34 | import org.apache.commons.rdf.api.Graph; |
35 | 35 | import org.apache.commons.rdf.api.IRI; |
36 | | -import org.apache.commons.rdf.api.RDF; |
37 | 36 | import org.apache.commons.rdf.api.RDFTerm; |
38 | 37 |
|
| 38 | +/** |
| 39 | + * A Matcher type for use with Access Control Policies. |
| 40 | + * |
| 41 | + * <p>A matcher is associated with {@link Policy} objects, defining |
| 42 | + * agents, clients, issuers or verifiable credential (vc) types. |
| 43 | + */ |
39 | 44 | public class Matcher extends WrapperIRI { |
40 | 45 |
|
41 | | - static final RDF rdf = RDFFactory.getInstance(); |
42 | | - |
43 | | - public Matcher(final RDFTerm original, final Graph graph) { |
44 | | - super(original, graph); |
45 | | - graph.add((IRI) original, rdf.createIRI(type.toString()), rdf.createIRI(ACP.Matcher.toString())); |
| 46 | + /** |
| 47 | + * Create a new Matcher. |
| 48 | + * |
| 49 | + * @param identifier the matcher identifier |
| 50 | + * @param graph the underlying graph |
| 51 | + */ |
| 52 | + public Matcher(final RDFTerm identifier, final Graph graph) { |
| 53 | + super(identifier, graph); |
| 54 | + graph.add((IRI) identifier, asIRI(RDF.type), asIRI(ACP.Matcher)); |
46 | 55 | } |
47 | 56 |
|
| 57 | + |
| 58 | + /** |
| 59 | + * Retrieve the acp:vc values. |
| 60 | + * |
| 61 | + * @return a collection of verifiable credential types |
| 62 | + */ |
48 | 63 | public Set<URI> vc() { |
49 | | - return objects(rdf.createIRI(ACP.vc.toString()), |
50 | | - TermMappings::asIri, ValueMappings::iriAsUri); |
| 64 | + return objects(asIRI(ACP.vc), TermMappings::asIri, ValueMappings::iriAsUri); |
51 | 65 | } |
52 | 66 |
|
| 67 | + /** |
| 68 | + * Retrieve the acp:agent values. |
| 69 | + * |
| 70 | + * @return a collection of agent identifiers |
| 71 | + */ |
53 | 72 | public Set<URI> agent() { |
54 | | - return objects(rdf.createIRI(ACP.agent.toString()), |
55 | | - TermMappings::asIri, ValueMappings::iriAsUri); |
| 73 | + return objects(asIRI(ACP.agent), TermMappings::asIri, ValueMappings::iriAsUri); |
56 | 74 | } |
57 | 75 |
|
| 76 | + /** |
| 77 | + * Retrieve the acp:client values. |
| 78 | + * |
| 79 | + * @return a collection of client identifiers |
| 80 | + */ |
58 | 81 | public Set<URI> client() { |
59 | | - return objects(rdf.createIRI(ACP.client.toString()), |
60 | | - TermMappings::asIri, ValueMappings::iriAsUri); |
| 82 | + return objects(asIRI(ACP.client), TermMappings::asIri, ValueMappings::iriAsUri); |
61 | 83 | } |
62 | 84 |
|
| 85 | + /** |
| 86 | + * Retrieve the acp:issuer values. |
| 87 | + * |
| 88 | + * @return a collection of issuer identifiers |
| 89 | + */ |
63 | 90 | public Set<URI> issuer() { |
64 | | - return objects(rdf.createIRI(ACP.issuer.toString()), |
65 | | - TermMappings::asIri, ValueMappings::iriAsUri); |
| 91 | + return objects(asIRI(ACP.issuer), TermMappings::asIri, ValueMappings::iriAsUri); |
66 | 92 | } |
67 | 93 |
|
68 | 94 | static RDFTerm asResource(final Matcher matcher, final Graph graph) { |
69 | | - graph.add(matcher, rdf.createIRI(type.toString()), rdf.createIRI(ACP.Matcher.toString())); |
| 95 | + graph.add(matcher, asIRI(RDF.type), asIRI(ACP.Matcher)); |
70 | 96 | matcher.vc().forEach(vc -> |
71 | | - graph.add(matcher, rdf.createIRI(ACP.vc.toString()), rdf.createIRI(vc.toString()))); |
| 97 | + graph.add(matcher, asIRI(ACP.vc), asIRI(vc))); |
72 | 98 | matcher.agent().forEach(agent -> |
73 | | - graph.add(matcher, rdf.createIRI(ACP.agent.toString()), rdf.createIRI(agent.toString()))); |
| 99 | + graph.add(matcher, asIRI(ACP.agent), asIRI(agent))); |
74 | 100 | matcher.client().forEach(client -> |
75 | | - graph.add(matcher, rdf.createIRI(ACP.client.toString()), rdf.createIRI(client.toString()))); |
| 101 | + graph.add(matcher, asIRI(ACP.client), asIRI(client))); |
76 | 102 | matcher.issuer().forEach(issuer -> |
77 | | - graph.add(matcher, rdf.createIRI(ACP.issuer.toString()), rdf.createIRI(issuer.toString()))); |
| 103 | + graph.add(matcher, asIRI(ACP.issuer), asIRI(issuer))); |
78 | 104 | return matcher; |
79 | 105 | } |
80 | 106 | } |
|
0 commit comments