View Javadoc
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.api.ldap.trigger;
22  
23  
24  import org.apache.directory.api.ldap.model.message.SearchScope;
25  import org.apache.directory.api.ldap.model.name.Dn;
26  
27  
28  /**
29   * The search context option of the triggered stored procedure.
30   * 
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public class StoredProcedureSearchContextOption implements StoredProcedureOption
34  {
35  
36      private final Dn baseObject;
37      private SearchScope searchScope;
38  
39  
40      /**
41       * Instantiates a new stored procedure search context option.
42       *
43       * @param baseObject the base object
44       */
45      public StoredProcedureSearchContextOption( Dn baseObject )
46      {
47          // the default search scope is "base"
48          this( baseObject, SearchScope.OBJECT );
49      }
50  
51  
52      /**
53       * Instantiates a new stored procedure search context option.
54       *
55       * @param baseObject the base object
56       * @param searchScope the search scope
57       */
58      public StoredProcedureSearchContextOption( Dn baseObject, SearchScope searchScope )
59      {
60          this.baseObject = baseObject;
61          this.searchScope = searchScope;
62      }
63  
64  
65      /**
66       * Gets the base object.
67       *
68       * @return the base object
69       */
70      public Dn getBaseObject()
71      {
72          return baseObject;
73      }
74  
75  
76      /**
77       * Gets the search scope.
78       *
79       * @return the search scope
80       */
81      public SearchScope getSearchScope()
82      {
83          return searchScope;
84      }
85  
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public String toString()
92      {
93          return "searchContext { scope " + searchScope + " } \"" + baseObject + "\"";
94      }
95  
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public int hashCode()
102     {
103         int h = 37;
104 
105         h = h * 17 + ( ( baseObject == null ) ? 0 : baseObject.hashCode() );
106         h = h * 17 + ( ( searchScope == null ) ? 0 : searchScope.hashCode() );
107 
108         return h;
109     }
110 
111 
112     /**
113      * {@inheritDoc}
114      */
115     @Override
116     public boolean equals( Object obj )
117     {
118         if ( this == obj )
119         {
120             return true;
121         }
122         if ( obj == null )
123         {
124             return false;
125         }
126         if ( getClass() != obj.getClass() )
127         {
128             return false;
129         }
130         final StoredProcedureSearchContextOption other = ( StoredProcedureSearchContextOption ) obj;
131         if ( baseObject == null )
132         {
133             if ( other.baseObject != null )
134             {
135                 return false;
136             }
137         }
138         else if ( !baseObject.equals( other.baseObject ) )
139         {
140             return false;
141         }
142         if ( searchScope == null )
143         {
144             if ( other.searchScope != null )
145             {
146                 return false;
147             }
148         }
149         else if ( !searchScope.equals( other.searchScope ) )
150         {
151             return false;
152         }
153         return true;
154     }
155 
156 }