1 package org.argeo.naming;
2
3 import java.util.EnumSet;
4 import java.util.Set;
5 import java.util.TreeSet;
6
7 import javax.naming.InvalidNameException;
8 import javax.naming.ldap.LdapName;
9
10
11
12
13
14
15 public interface Distinguished {
16
17 String dn();
18
19
20 default LdapName distinguishedName() {
21 try {
22 return new LdapName(dn());
23 } catch (InvalidNameException e) {
24 throw new IllegalArgumentException("Distinguished name " + dn() + " is not properly formatted.", e);
25 }
26 }
27
28
29 static Set<String> enumToDns(EnumSet<? extends Distinguished> enumSet) {
30 Set<String> res = new TreeSet<>();
31 for (Enum<? extends Distinguished> enm : enumSet) {
32 res.add(((Distinguished) enm).dn());
33 }
34 return res;
35 }
36 }