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.comparators;
21
22
23 import java.io.IOException;
24 import java.text.ParseException;
25
26 import org.apache.directory.api.i18n.I18n;
27 import org.apache.directory.api.ldap.model.schema.LdapComparator;
28 import org.apache.directory.api.ldap.model.schema.PrepareString;
29 import org.apache.directory.api.util.GeneralizedTime;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38
39 public class GeneralizedTimeComparator extends LdapComparator<String>
40 {
41
42 private static final long serialVersionUID = 2L;
43
44
45 private static final Logger LOG = LoggerFactory.getLogger( GeneralizedTimeComparator.class );
46
47
48
49
50
51
52
53
54 public GeneralizedTimeComparator( String oid )
55 {
56 super( oid );
57 }
58
59
60
61
62
63 public int compare( String backendValue, String assertValue )
64 {
65 LOG.debug( "comparing generalizedTimeOrdering objects '{}' with '{}'", backendValue, assertValue );
66
67
68
69
70 if ( backendValue == assertValue )
71 {
72 return 0;
73 }
74
75
76
77
78 if ( ( backendValue == null ) || ( assertValue == null ) )
79 {
80 return backendValue == null ? -1 : 1;
81 }
82
83
84
85 GeneralizedTime backendTime;
86 try
87 {
88 String prepared = PrepareString.normalize( backendValue, PrepareString.StringType.DIRECTORY_STRING );
89 backendTime = new GeneralizedTime( prepared );
90 }
91 catch ( IOException ioe )
92 {
93 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, backendValue ), ioe );
94 }
95 catch ( ParseException pe )
96 {
97 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, backendValue ), pe );
98 }
99
100 GeneralizedTime assertTime;
101
102 try
103 {
104 String prepared = PrepareString.normalize( assertValue, PrepareString.StringType.DIRECTORY_STRING );
105 assertTime = new GeneralizedTime( prepared );
106 }
107 catch ( IOException ioe )
108 {
109 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, assertValue ), ioe );
110 }
111 catch ( ParseException pe )
112 {
113 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, assertValue ), pe );
114 }
115
116 return backendTime.compareTo( assertTime );
117 }
118 }