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.i18n.I18n; 024 import org.apache.directory.shared.ldap.filter.ExprNode; 025 import org.apache.directory.shared.ldap.name.DN; 026 027 import java.util.Set; 028 import java.util.Collections; 029 030 031 /** 032 * SubtreeSpecification contains no setters so they must be built by a 033 * modifiable object containing all the necessary parameters to build the base 034 * object. 035 * 036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 037 * @version $Rev: 919765 $ 038 */ 039 public class SubtreeSpecificationModifier 040 { 041 /** the subtree base relative to the administration point */ 042 private DN base = new DN(); 043 044 /** the set of subordinates entries and their subordinates to exclude */ 045 private Set<DN> chopBefore = Collections.EMPTY_SET; 046 047 /** the set of subordinates entries whose subordinates are to be excluded */ 048 private Set<DN> chopAfter = Collections.EMPTY_SET; 049 050 /** the minimum distance below base to start including entries */ 051 private int minBaseDistance = 0; 052 053 /** the maximum distance from base past which entries are excluded */ 054 private int maxBaseDistance = SubtreeSpecification.UNBOUNDED_MAX; 055 056 /** 057 * a filter using only assertions on objectClass attributes for subtree 058 * refinement 059 */ 060 private ExprNode refinement = null; 061 062 063 // ----------------------------------------------------------------------- 064 // F A C T O R Y M E T H O D 065 // ----------------------------------------------------------------------- 066 067 /** 068 * Creates a SubtreeSpecification using any of the default paramters that 069 * may have been modified from their defaults. 070 * 071 * @return the newly created subtree specification 072 */ 073 public SubtreeSpecification getSubtreeSpecification() 074 { 075 076 return new BaseSubtreeSpecification( this.base, this.minBaseDistance, this.maxBaseDistance, this.chopAfter, 077 this.chopBefore, this.refinement ); 078 } 079 080 081 // ----------------------------------------------------------------------- 082 // M U T A T O R S 083 // ----------------------------------------------------------------------- 084 085 /** 086 * Sets the subtree base relative to the administration point. 087 * 088 * @param base 089 * subtree base relative to the administration point 090 */ 091 public void setBase( DN base ) 092 { 093 this.base = base; 094 } 095 096 097 /** 098 * Sets the set of subordinates entries and their subordinates to exclude. 099 * 100 * @param chopBefore 101 * the set of subordinates entries and their subordinates to 102 * exclude 103 */ 104 public void setChopBeforeExclusions( Set<DN> chopBefore ) 105 { 106 this.chopBefore = chopBefore; 107 } 108 109 110 /** 111 * Sets the set of subordinates entries whose subordinates are to be 112 * excluded. 113 * 114 * @param chopAfter 115 * the set of subordinates entries whose subordinates are to be 116 * excluded 117 */ 118 public void setChopAfterExclusions( Set<DN> chopAfter ) 119 { 120 this.chopAfter = chopAfter; 121 } 122 123 124 /** 125 * Sets the minimum distance below base to start including entries. 126 * 127 * @param minBaseDistance 128 * the minimum distance below base to start including entries 129 */ 130 public void setMinBaseDistance( int minBaseDistance ) 131 { 132 if ( minBaseDistance < 0 ) 133 { 134 throw new IllegalArgumentException( I18n.err( I18n.ERR_04330 ) ); 135 } 136 137 this.minBaseDistance = minBaseDistance; 138 } 139 140 141 /** 142 * Sets the maximum distance from base past which entries are excluded. 143 * 144 * @param maxBaseDistance 145 * the maximum distance from base past which entries are excluded 146 */ 147 public void setMaxBaseDistance( int maxBaseDistance ) 148 { 149 if ( maxBaseDistance < 0 ) 150 { 151 this.maxBaseDistance = SubtreeSpecification.UNBOUNDED_MAX; 152 } 153 else 154 { 155 this.maxBaseDistance = maxBaseDistance; 156 } 157 } 158 159 160 /** 161 * Sets a filter using only assertions on objectClass attributes for subtree 162 * refinement. 163 * 164 * @param refinement 165 * a filter using only assertions on objectClass attributes for 166 * subtree refinement 167 */ 168 public void setRefinement( ExprNode refinement ) 169 { 170 this.refinement = refinement; 171 } 172 }