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
94 private SubtreeSpecificationSyntaxChecker( String oid, SchemaManager schemaManager )
95 {
96 super( oid );
97 subtreeSpecificationChecker = new SubtreeSpecificationChecker( schemaManager );
98 }
99
100
101
102
103
104 public static Builder builder()
105 {
106 return new Builder();
107 }
108
109
110
111
112
113 @Override
114 public boolean isValidSyntax( Object value )
115 {
116 String strValue;
117
118 if ( value == null )
119 {
120 if ( LOG.isDebugEnabled() )
121 {
122 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, "null" ) );
123 }
124
125 return false;
126 }
127
128 if ( value instanceof String )
129 {
130 strValue = ( String ) value;
131 }
132 else if ( value instanceof byte[] )
133 {
134 strValue = Strings.utf8ToString( ( byte[] ) value );
135 }
136 else
137 {
138 strValue = value.toString();
139 }
140
141 if ( strValue.length() == 0 )
142 {
143 if ( LOG.isDebugEnabled() )
144 {
145 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
146 }
147
148 return false;
149 }
150
151 try
152 {
153 synchronized ( subtreeSpecificationChecker )
154 {
155 subtreeSpecificationChecker.parse( strValue );
156 }
157
158 if ( LOG.isDebugEnabled() )
159 {
160 LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) );
161 }
162
163 return true;
164 }
165 catch ( ParseException pe )
166 {
167 if ( LOG.isDebugEnabled() )
168 {
169 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
170 }
171
172 return false;
173 }
174 }
175 }