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