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.DitStructureRuleDescriptionSchemaParser;
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
52
53 @SuppressWarnings("serial")
54 public final class DitStructureRuleDescriptionSyntaxChecker extends SyntaxChecker
55 {
56
57 private transient DitStructureRuleDescriptionSchemaParser schemaParser = new DitStructureRuleDescriptionSchemaParser();
58
59
60
61
62 public static final DitStructureRuleDescriptionSyntaxChecker INSTANCE =
63 new DitStructureRuleDescriptionSyntaxChecker( SchemaConstants.DIT_STRUCTURE_RULE_SYNTAX );
64
65
66
67
68 public static final class Builder extends SCBuilder<DitStructureRuleDescriptionSyntaxChecker>
69 {
70
71
72
73 private Builder()
74 {
75 super( SchemaConstants.DIT_STRUCTURE_RULE_SYNTAX );
76 }
77
78
79
80
81
82
83 @Override
84 public DitStructureRuleDescriptionSyntaxChecker build()
85 {
86 return new DitStructureRuleDescriptionSyntaxChecker( oid );
87 }
88 }
89
90
91
92
93
94
95
96 private DitStructureRuleDescriptionSyntaxChecker( String oid )
97 {
98 super( oid );
99 }
100
101
102
103
104
105 public static Builder builder()
106 {
107 return new Builder();
108 }
109
110
111
112
113
114 @Override
115 public boolean isValidSyntax( Object value )
116 {
117 String strValue;
118
119 if ( value == null )
120 {
121 if ( LOG.isDebugEnabled() )
122 {
123 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
124 }
125
126 return false;
127 }
128
129 if ( value instanceof String )
130 {
131 strValue = ( String ) value;
132 }
133 else if ( value instanceof byte[] )
134 {
135 strValue = Strings.utf8ToString( ( byte[] ) value );
136 }
137 else
138 {
139 strValue = value.toString();
140 }
141
142 try
143 {
144 schemaParser.parseDITStructureRuleDescription( strValue );
145
146 if ( LOG.isDebugEnabled() )
147 {
148 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
149 }
150
151 return true;
152 }
153 catch ( ParseException pe )
154 {
155 if ( LOG.isDebugEnabled() )
156 {
157 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
158 }
159
160 return false;
161 }
162 }
163 }