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.MatchingRuleUseDescriptionSchemaParser;
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 @SuppressWarnings("serial")
51 public class MatchingRuleUseDescriptionSyntaxChecker extends SyntaxChecker
52 {
53
54 private static final Logger LOG = LoggerFactory.getLogger( MatchingRuleUseDescriptionSyntaxChecker.class );
55
56
57 private MatchingRuleUseDescriptionSchemaParser schemaParser = new MatchingRuleUseDescriptionSchemaParser();
58
59
60
61
62
63
64
65 public MatchingRuleUseDescriptionSyntaxChecker()
66 {
67 super( SchemaConstants.MATCHING_RULE_USE_DESCRIPTION_SYNTAX );
68 }
69
70
71
72
73
74 public boolean isValidSyntax( Object value )
75 {
76 String strValue = null;
77
78 if ( value == null )
79 {
80 LOG.debug( "Syntax invalid for 'null'" );
81 return false;
82 }
83
84 if ( value instanceof String )
85 {
86 strValue = ( String ) value;
87 }
88 else if ( value instanceof byte[] )
89 {
90 strValue = Strings.utf8ToString( ( byte[] ) value );
91 }
92 else
93 {
94 strValue = value.toString();
95 }
96
97 try
98 {
99 schemaParser.parseMatchingRuleUseDescription( strValue );
100 LOG.debug( "Syntax valid for '{}'", value );
101
102 return true;
103 }
104 catch ( ParseException pe )
105 {
106 LOG.debug( "Syntax invalid for '{}'", value );
107 return false;
108 }
109 }
110
111 }