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.SchemaManager;
28 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
29 import org.apache.directory.api.ldap.model.subtree.SubtreeSpecificationChecker;
30 import org.apache.directory.api.util.Strings;
31
32
33
34
35
36
37
38
39
40 @SuppressWarnings("serial")
41 public final class SubtreeSpecificationSyntaxChecker extends SyntaxChecker
42 {
43
44 private transient SubtreeSpecificationChecker subtreeSpecificationChecker;
45
46
47
48
49 public static final SubtreeSpecificationSyntaxChecker INSTANCE =
50 new SubtreeSpecificationSyntaxChecker( SchemaConstants.SUBTREE_SPECIFICATION_SYNTAX, null );
51
52
53
54
55 public static final class Builder extends SCBuilder<SubtreeSpecificationSyntaxChecker>
56 {
57
58 private SchemaManager schemaManager;
59
60
61
62
63 private Builder()
64 {
65 super( SchemaConstants.SUBTREE_SPECIFICATION_SYNTAX );
66 }
67
68
69 public Builder setSchemaManager( SchemaManager schemaManager )
70 {
71 this.schemaManager = schemaManager;
72
73 return this;
74 }
75
76
77
78
79
80
81 @Override
82 public SubtreeSpecificationSyntaxChecker build()
83 {
84 return new SubtreeSpecificationSyntaxChecker( oid, schemaManager );
85 }
86 }
87
88
89
90
91
92
93 private SubtreeSpecificationSyntaxChecker( String oid, SchemaManager schemaManager )
94 {
95 super( oid );
96 subtreeSpecificationChecker = new SubtreeSpecificationChecker( schemaManager );
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 if ( strValue.length() == 0 )
141 {
142 if ( LOG.isDebugEnabled() )
143 {
144 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
145 }
146
147 return false;
148 }
149
150 try
151 {
152 synchronized ( subtreeSpecificationChecker )
153 {
154 subtreeSpecificationChecker.parse( strValue );
155 }
156
157 if ( LOG.isDebugEnabled() )
158 {
159 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
160 }
161
162 return true;
163 }
164 catch ( ParseException pe )
165 {
166 if ( LOG.isDebugEnabled() )
167 {
168 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
169 }
170
171 return false;
172 }
173 }
174 }