View Javadoc

1   /* (c) Copyright 2003 Caleigo AB, All rights reserved. 
2    * 
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2.1 of the License, or (at your option) any later version.
7    * 
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   * Lesser General Public License for more details.
12   * 
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   *  
17   */
18  
19  package org.caleigo.core;
20  
21  import org.caleigo.core.event.*;
22  
23  /*** The NegateQualifier logically negates another single qualifier that may
24   * however be a CompositeQualifier. This would represent adding a "NOT" 
25   * before the contained Qualifier.
26   *
27   * @author  Dennis Zikovic
28   * @version 1.00
29   * 
30   *//* 
31   *
32   * WHEN        WHO               WHY & WHAT
33   * ------------------------------------------------------------------------------
34   * 2001-07-11 Dennis Zikovic    Creation
35   */
36  public class NegateQualifier extends Qualifier 
37  {
38      // Data members ------------------------------------------------------------
39      private Qualifier mNegatedQualifier;
40      
41      private transient RelayListener mRelayListener;
42      
43      // Constructors ------------------------------------------------------------
44      
45      /*** Default constructor for NegateQualifier.
46       */
47      public NegateQualifier(Qualifier entityQualifier) 
48      {
49          mNegatedQualifier = entityQualifier;
50      }
51      
52      // Superclass overrides ----------------------------------------------------
53      
54      /*** This method returns true if the qualifier does select the
55       * provided entity object.
56       */
57      public boolean doesQualify(IEntity entity)
58      {
59          return !mNegatedQualifier.doesQualify(entity);
60      }
61      
62      /*** This method returns true if the qualifier can select entities
63       * of the type defined by the provided entity descriptor.
64       */
65      public boolean canQualify(IEntityDescriptor entityDescriptor)
66      {
67          return mNegatedQualifier.canQualify(entityDescriptor);
68      }
69      
70      /*** This method returns true if the qualifier can uniquely select
71       * entities of the type defined by the provided entity descriptor. 
72       * If that is the case then the qualifier is an identity qualifier and can 
73       * never qualify more then a single entity instance of the specified type.
74       */
75      public boolean canUniquelyQualify(IEntityDescriptor entityDescriptor)
76      {
77          return false; 
78      }
79      
80      /*** This abstract method must return true if the qualifier can select 
81       * entities of the type defined by the provided entity descriptor without
82       * the nead of any complementary data. No other information than can be
83       * accessed through the provided entity descriptor should be neaded if 
84       * this method returns true. This validates that the doesQualify method
85       * can be called for the called qualifier.
86       */
87      public boolean canDirectlyQualify(IEntityDescriptor entityDescriptor) 
88      {
89          return mNegatedQualifier.canDirectlyQualify(entityDescriptor);
90      }    
91  
92      /*** Adds an IQualifierListener to receive notifications of contents and 
93       * structure changes from the Qualifier object. The NegateQualifier 
94       * overrides this method to know when to listen on the negated qualifier.
95       */
96      public void addQualifierListener(IQualifierListener listener)
97      {
98          super.addQualifierListener(listener);
99          if(mRelayListener!=null)
100         {
101             mRelayListener = new RelayListener();
102             mNegatedQualifier.addQualifierListener(mRelayListener);
103         }
104     }
105 
106     /*** The toString method returns an "abstract" expression of what the 
107      * qualifier selects. Note that this expresion is only intended for visual
108      * aid and is not a valid SQL expresion. 
109      */
110     public String toString()
111     {
112         return "NOT "+mNegatedQualifier;
113     }
114     
115     // Access methods ----------------------------------------------------------
116     
117     /*** Access method that returns the wrapped contained qualifier that are
118      * defined as negated by the called Qualifier.
119      */
120     public Qualifier getNegatedQualifier()
121     {
122         return mNegatedQualifier;
123     }
124 }