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  package org.apache.directory.api.ldap.model.subtree;
21  
22  
23  import java.util.Collections;
24  import java.util.Set;
25  
26  import org.apache.directory.api.i18n.I18n;
27  import org.apache.directory.api.ldap.model.filter.ExprNode;
28  import org.apache.directory.api.ldap.model.name.Dn;
29  
30  
31  /**
32   * SubtreeSpecification contains no setters so they must be built by a
33   * modifiable object containing all the necessary parameters to build the base
34   * object.
35   * 
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   */
38  public class SubtreeSpecificationModifier
39  {
40      /** the subtree base relative to the administration point */
41      private Dn base = new Dn();
42  
43      /** the set of subordinates entries and their subordinates to exclude */
44      private Set<Dn> chopBefore = Collections.emptySet();
45  
46      /** the set of subordinates entries whose subordinates are to be excluded */
47      private Set<Dn> chopAfter = Collections.emptySet();
48  
49      /** the minimum distance below base to start including entries */
50      private int minBaseDistance = 0;
51  
52      /** the maximum distance from base past which entries are excluded */
53      private int maxBaseDistance = SubtreeSpecification.UNBOUNDED_MAX;
54  
55      /**
56       * a filter using only assertions on objectClass attributes for subtree
57       * refinement
58       */
59      private ExprNode filter;
60  
61  
62      // -----------------------------------------------------------------------
63      // F A C T O R Y M E T H O D
64      // -----------------------------------------------------------------------
65  
66      /**
67       * Creates a SubtreeSpecification using any of the default paramters that
68       * may have been modified from their defaults.
69       * 
70       * @return the newly created subtree specification
71       */
72      public SubtreeSpecification getSubtreeSpecification()
73      {
74  
75          return new BaseSubtreeSpecification( this.base, this.minBaseDistance, this.maxBaseDistance, this.chopAfter,
76              this.chopBefore, this.filter );
77      }
78  
79  
80      // -----------------------------------------------------------------------
81      // M U T A T O R S
82      // -----------------------------------------------------------------------
83  
84      /**
85       * Sets the subtree base relative to the administration point.
86       * 
87       * @param base
88       *            subtree base relative to the administration point
89       */
90      public void setBase( Dn base )
91      {
92          this.base = base;
93      }
94  
95  
96      /**
97       * Sets the set of subordinates entries and their subordinates to exclude.
98       * 
99       * @param chopBeforeExclusions
100      *            the set of subordinates entries and their subordinates to
101      *            exclude
102      */
103     public void setChopBeforeExclusions( Set<Dn> chopBeforeExclusions )
104     {
105         this.chopBefore = chopBeforeExclusions;
106     }
107 
108 
109     /**
110      * Sets the set of subordinates entries whose subordinates are to be
111      * excluded.
112      * 
113      * @param chopAfterExclusions
114      *            the set of subordinates entries whose subordinates are to be
115      *            excluded
116      */
117     public void setChopAfterExclusions( Set<Dn> chopAfterExclusions )
118     {
119         this.chopAfter = chopAfterExclusions;
120     }
121 
122 
123     /**
124      * Sets the minimum distance below base to start including entries.
125      * 
126      * @param minBaseDistance
127      *            the minimum distance below base to start including entries
128      */
129     public void setMinBaseDistance( int minBaseDistance )
130     {
131         if ( minBaseDistance < 0 )
132         {
133             throw new IllegalArgumentException( I18n.err( I18n.ERR_04330 ) );
134         }
135 
136         this.minBaseDistance = minBaseDistance;
137     }
138 
139 
140     /**
141      * Sets the maximum distance from base past which entries are excluded.
142      * 
143      * @param maxBaseDistance
144      *            the maximum distance from base past which entries are excluded
145      */
146     public void setMaxBaseDistance( int maxBaseDistance )
147     {
148         if ( maxBaseDistance < 0 )
149         {
150             this.maxBaseDistance = SubtreeSpecification.UNBOUNDED_MAX;
151         }
152         else
153         {
154             this.maxBaseDistance = maxBaseDistance;
155         }
156     }
157 
158 
159     /**
160      * Sets a filter using only assertions on objectClass attributes for subtree
161      * refinement.
162      * 
163      * @param refinement a filter using only assertions on objectClass attributes for
164      *            subtree refinement
165      */
166     public void setRefinement( ExprNode refinement )
167     {
168         this.filter = refinement;
169     }
170 
171 
172     /**
173      * Sets a filter
174      * 
175      * @param filter a filter
176      */
177     public void setFilter( ExprNode filter )
178     {
179         this.filter = filter;
180     }
181 }