1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.schema.registries;
21
22
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.Map;
26
27 import javax.naming.NamingException;
28
29 import org.apache.directory.shared.ldap.schema.MatchingRuleUse;
30
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37
38
39
40
41 public class DefaultMatchingRuleUseRegistry implements MatchingRuleUseRegistry
42 {
43
44 private static final Logger LOG = LoggerFactory.getLogger( DefaultMatchingRuleUseRegistry.class );
45
46 private final Map<String,MatchingRuleUse> byName;
47
48
49
50
51
52
53
54
55
56
57 public DefaultMatchingRuleUseRegistry()
58 {
59 this.byName = new HashMap<String,MatchingRuleUse>();
60 }
61
62
63
64
65
66
67
68 public void register( MatchingRuleUse matchingRuleUse ) throws NamingException
69 {
70 if ( byName.containsKey( matchingRuleUse.getName() ) )
71 {
72 throw new NamingException( "matchingRuleUse w/ name " + matchingRuleUse.getName()
73 + " has already been registered!" );
74 }
75
76 byName.put( matchingRuleUse.getName(), matchingRuleUse );
77 if ( LOG.isDebugEnabled() )
78 {
79 LOG.debug( "registed matchingRuleUse: " + matchingRuleUse );
80 }
81 }
82
83
84 public MatchingRuleUse lookup( String name ) throws NamingException
85 {
86 if ( !byName.containsKey( name ) )
87 {
88 throw new NamingException( "matchingRuleUse w/ name " + name + " not registered!" );
89 }
90
91 MatchingRuleUse matchingRuleUse = byName.get( name );
92 if ( LOG.isDebugEnabled() )
93 {
94 LOG.debug( "lookup with name '"+ name + "' of matchingRuleUse: " + matchingRuleUse );
95 }
96 return matchingRuleUse;
97 }
98
99
100 public boolean hasMatchingRuleUse( String name )
101 {
102 return byName.containsKey( name );
103 }
104
105
106 public String getSchemaName( String id ) throws NamingException
107 {
108 MatchingRuleUse mru = byName.get( id );
109 if ( mru != null )
110 {
111 return mru.getSchema();
112 }
113
114 throw new NamingException( "Name " + id + " not found in name to " + "MatchingRuleUse map!" );
115 }
116
117
118 public Iterator<MatchingRuleUse> iterator()
119 {
120 return byName.values().iterator();
121 }
122
123
124 public void unregister( String name ) throws NamingException
125 {
126 byName.remove( name );
127 }
128 }