1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.model.schema.syntaxCheckers;
21
22
23 import java.text.ParseException;
24
25 import org.apache.directory.api.i18n.I18n;
26 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
27 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
28 import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleDescriptionSchemaParser;
29 import org.apache.directory.api.util.Strings;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 @SuppressWarnings("serial")
52 public final class MatchingRuleDescriptionSyntaxChecker extends SyntaxChecker
53 {
54
55 private transient MatchingRuleDescriptionSchemaParser schemaParser = new MatchingRuleDescriptionSchemaParser();
56
57
58
59
60 public static final MatchingRuleDescriptionSyntaxChecker INSTANCE =
61 new MatchingRuleDescriptionSyntaxChecker( SchemaConstants.MATCHING_RULE_DESCRIPTION_SYNTAX );
62
63
64
65
66 public static final class Builder extends SCBuilder<MatchingRuleDescriptionSyntaxChecker>
67 {
68
69
70
71 private Builder()
72 {
73 super( SchemaConstants.MATCHING_RULE_DESCRIPTION_SYNTAX );
74 }
75
76
77
78
79
80
81 @Override
82 public MatchingRuleDescriptionSyntaxChecker build()
83 {
84 return new MatchingRuleDescriptionSyntaxChecker( oid );
85 }
86 }
87
88
89
90
91
92
93
94 private MatchingRuleDescriptionSyntaxChecker( String oid )
95 {
96 super( oid );
97 }
98
99
100
101
102
103 public static Builder builder()
104 {
105 return new Builder();
106 }
107
108
109
110
111
112 @Override
113 public boolean isValidSyntax( Object value )
114 {
115 String strValue;
116
117 if ( value == null )
118 {
119 if ( LOG.isDebugEnabled() )
120 {
121 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
122 }
123
124 return false;
125 }
126
127 if ( value instanceof String )
128 {
129 strValue = ( String ) value;
130 }
131 else if ( value instanceof byte[] )
132 {
133 strValue = Strings.utf8ToString( ( byte[] ) value );
134 }
135 else
136 {
137 strValue = value.toString();
138 }
139
140 try
141 {
142 schemaParser.parseMatchingRuleDescription( strValue );
143
144 if ( LOG.isDebugEnabled() )
145 {
146 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
147 }
148
149 return true;
150 }
151 catch ( ParseException pe )
152 {
153 if ( LOG.isDebugEnabled() )
154 {
155 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
156 }
157
158 return false;
159 }
160 }
161 }