KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > filter > LdapNotFilterComponent


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.core.model.filter;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
25
26
27 public class LdapNotFilterComponent extends LdapFilterComponent
28 {
29
30     public LdapNotFilterComponent( LdapFilter parent )
31     {
32         super( parent );
33     }
34
35
36     public boolean setStartToken( LdapFilterToken notToken )
37     {
38         if ( notToken != null && notToken.getType() == LdapFilterToken.NOT )
39         {
40             return super.setStartToken( notToken );
41         }
42         else
43         {
44             return false;
45         }
46     }
47
48
49     /**
50      * Checks additionally if the the filter wasn't set before.
51      *
52      * @see LdapFilterComponent#addFilter(LdapFilter)
53      */

54     public boolean addFilter( LdapFilter filter )
55     {
56         if ( this.filterList.isEmpty() )
57         {
58             return super.addFilter( filter );
59         }
60         else
61         {
62             // There is already a filter in the list. A NOT filter
63
// can only contain one filter.
64
return false;
65         }
66     }
67
68
69     public String JavaDoc getInvalidCause()
70     {
71         if ( this.startToken == null )
72         {
73             return "Missing NOT character '!'";
74         }
75         else if ( this.filterList == null || this.filterList.isEmpty() )
76         {
77             return "Missing filter expression";
78         }
79         else
80         {
81             return "Invalid NOT filter";
82         }
83     }
84
85
86     public String JavaDoc toString()
87     {
88         return ( this.startToken != null ? "!" : "" )
89             + ( !this.filterList.isEmpty() ? this.filterList.get( 0 ).toString() : "" );
90     }
91
92 }
93
Popular Tags