001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.shared.ldap.subtree;
021    
022    
023    import org.apache.directory.shared.ldap.filter.ExprNode;
024    import org.apache.directory.shared.ldap.name.LdapDN;
025    
026    import java.util.Set;
027    import java.util.Collections;
028    
029    
030    /**
031     * SubtreeSpecification contains no setters so they must be built by a
032     * modifiable object containing all the necessary parameters to build the base
033     * object.
034     * 
035     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036     * @version $Rev: 596222 $
037     */
038    public class SubtreeSpecificationModifier
039    {
040        /** the subtree base relative to the administration point */
041        private LdapDN base = new LdapDN();
042    
043        /** the set of subordinates entries and their subordinates to exclude */
044        private Set<LdapDN> chopBefore = Collections.EMPTY_SET;
045    
046        /** the set of subordinates entries whose subordinates are to be excluded */
047        private Set<LdapDN> chopAfter = Collections.EMPTY_SET;
048    
049        /** the minimum distance below base to start including entries */
050        private int minBaseDistance = 0;
051    
052        /** the maximum distance from base past which entries are excluded */
053        private int maxBaseDistance = SubtreeSpecification.UNBOUNDED_MAX;
054    
055        /**
056         * a filter using only assertions on objectClass attributes for subtree
057         * refinement
058         */
059        private ExprNode refinement = null;
060    
061    
062        // -----------------------------------------------------------------------
063        // F A C T O R Y M E T H O D
064        // -----------------------------------------------------------------------
065    
066        /**
067         * Creates a SubtreeSpecification using any of the default paramters that
068         * may have been modified from their defaults.
069         * 
070         * @return the newly created subtree specification
071         */
072        public SubtreeSpecification getSubtreeSpecification()
073        {
074    
075            return new BaseSubtreeSpecification( this.base, this.minBaseDistance, this.maxBaseDistance, this.chopAfter,
076                this.chopBefore, this.refinement );
077        }
078    
079    
080        // -----------------------------------------------------------------------
081        // M U T A T O R S
082        // -----------------------------------------------------------------------
083    
084        /**
085         * Sets the subtree base relative to the administration point.
086         * 
087         * @param base
088         *            subtree base relative to the administration point
089         */
090        public void setBase( LdapDN base )
091        {
092            this.base = base;
093        }
094    
095    
096        /**
097         * Sets the set of subordinates entries and their subordinates to exclude.
098         * 
099         * @param chopBefore
100         *            the set of subordinates entries and their subordinates to
101         *            exclude
102         */
103        public void setChopBeforeExclusions( Set<LdapDN> chopBefore )
104        {
105            this.chopBefore = chopBefore;
106        }
107    
108    
109        /**
110         * Sets the set of subordinates entries whose subordinates are to be
111         * excluded.
112         * 
113         * @param chopAfter
114         *            the set of subordinates entries whose subordinates are to be
115         *            excluded
116         */
117        public void setChopAfterExclusions( Set<LdapDN> chopAfter )
118        {
119            this.chopAfter = chopAfter;
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( "A negative minimum base distance is undefined!" );
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
164         *            a filter using only assertions on objectClass attributes for
165         *            subtree refinement
166         */
167        public void setRefinement( ExprNode refinement )
168        {
169            this.refinement = refinement;
170        }
171    }