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.ldap.model.constants.SchemaConstants;
26 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
27 import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleDescriptionSchemaParser;
28 import org.apache.directory.api.util.Strings;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 @SuppressWarnings("serial")
54 public class MatchingRuleDescriptionSyntaxChecker extends SyntaxChecker
55 {
56
57 private static final Logger LOG = LoggerFactory.getLogger( MatchingRuleDescriptionSyntaxChecker.class );
58
59
60 private MatchingRuleDescriptionSchemaParser schemaParser = new MatchingRuleDescriptionSchemaParser();
61
62
63
64
65
66
67
68 public MatchingRuleDescriptionSyntaxChecker()
69 {
70 super( SchemaConstants.MATCHING_RULE_DESCRIPTION_SYNTAX );
71 }
72
73
74
75
76
77 public boolean isValidSyntax( Object value )
78 {
79 String strValue = null;
80
81 if ( value == null )
82 {
83 LOG.debug( "Syntax invalid for 'null'" );
84 return false;
85 }
86
87 if ( value instanceof String )
88 {
89 strValue = ( String ) value;
90 }
91 else if ( value instanceof byte[] )
92 {
93 strValue = Strings.utf8ToString( ( byte[] ) value );
94 }
95 else
96 {
97 strValue = value.toString();
98 }
99
100 try
101 {
102 schemaParser.parseMatchingRuleDescription( strValue );
103 LOG.debug( "Syntax valid for '{}'", value );
104
105 return true;
106 }
107 catch ( ParseException pe )
108 {
109 LOG.debug( "Syntax invalid for '{}'", value );
110 return false;
111 }
112 }
113
114 }