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 */ 020package org.apache.directory.api.ldap.model.subtree; 021 022 023import java.util.Collections; 024import java.util.Set; 025 026import org.apache.directory.api.i18n.I18n; 027import org.apache.directory.api.ldap.model.filter.ExprNode; 028import org.apache.directory.api.ldap.model.name.Dn; 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 */ 038public class SubtreeSpecificationModifier 039{ 040 /** the subtree base relative to the administration point */ 041 private Dn base = new Dn(); 042 043 /** the set of subordinates entries and their subordinates to exclude */ 044 private Set<Dn> chopBefore = Collections.emptySet(); 045 046 /** the set of subordinates entries whose subordinates are to be excluded */ 047 private Set<Dn> chopAfter = Collections.emptySet(); 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 filter; 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.filter ); 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( Dn 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 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}