📄 complexsubtree.java
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Salford nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package issrg.pba.rbac.policies;
import issrg.utils.repository.Entry;
/**
* This class stands for a subtree that has several roots: a union of
* several simple subtrees.
*
* @author A Otenko
* @version 1.0
*/
public class ComplexSubtree implements Subtree {
/**
* This is an array of all roots of this union of subtrees.
*/
protected Subtree [] dits;
/**
* This is an array of additional Object Classes restrictions (in addition to
* those specified within the dits).
*/
protected String [] objectClasses;
/**
* @return the array of Subtrees that this Complex Subtree is a union of
*/
public Subtree[] getSubtrees() {
return dits;
}
/**
* This constructor builds a ComplexSubtree with no components.
*/
public ComplexSubtree(){}
/**
* This constructor builds the union of the array of DIT subtrees, with
* additional object classes restriction, so even if the object class will
* be allowed by a certain subtree, it still can be sieved away by this object
* class specification.
*
* @param dits is the array of subtrees to join together; if null, or an empty
* array, then no entries belong to it; pass it an array of one
* Subtree based on null DN for this subtree to contain the whole world
* @param objectClasses is the array of objectClasses that the entries must be
* of (must match all of the objectClasses); if it is null, entries with
* any object Classes are accepted, if they match the subtree specification
*/
public ComplexSubtree(Subtree [] dits, String [] objectClasses) {
_create_(dits, objectClasses);
}
/**
* Does the same as the ComplexSubtree(Subtree [], String[]) constructor, but
* gets the
* arrays of subtrees and objectClasses as vectors. Note that each of the
* elements should be of type Subtree and String respectively.
*
* @param dits is a Vector of Subtree objects, a union of which will be
* represented by this object; this array can be null
* @param objectClasses is a vector of Strings, each representing the object
* class of acceptable entries; this array can be null
*/
public ComplexSubtree(java.util.Vector dits, java.util.Vector objectClasses){
Subtree [] s = null;
String [] c = null;
if (dits!=null){
s = (Subtree[]) dits.toArray(new Subtree[0]);
}
if (objectClasses!=null){
c = (String[])objectClasses.toArray(new String[0]);
}
_create_(s, c);
}
/**
* This is the method that does the actual construction of the object and is
* called by both constructors.
*/
private void _create_(Subtree [] dits, String [] objClass){
if (dits==null){
dits=new Subtree[0];
}
this.dits = dits;
this.objectClasses = objClass;
}
/**
* This method tells whether or not the given entry belongs to this subtree.
* It is redefined to go through the whole array of Subtree objects that
* has been passed to the constructor, and if the given Entry is contained in
* either of them, and it satisfies the additional object class constraints,
* it returns true. Otherwise, it returns false.
*
* @param what is the Entry that is tested; if ComplexSubtree is built with
* ObjectClasses,
* it will expect only LDAPEntry on input here (returns false otherwise)
*
* @return true, if the given Entry is included in the subtree; false
* otherwise
*/
public boolean contains(Entry what){
if (objectClasses!=null){
if (!(what instanceof LDAPEntry)) return false; // object class cannot match: what is not an LDAPEntry
boolean falseClass=true;
for (int i=0; i<objectClasses.length; i++){
if (falseClass=!((LDAPEntry)what).isObjectClass(objectClasses[i])){
break;
}
}
if (falseClass){
return false;
}
}
for (int i=0; i<dits.length; i++){
if (dits[i]!=null && dits[i].contains(what)){
return true;
}
}
return false;
}
public String toString(){
StringBuffer sb = new StringBuffer("Complex Subtree: {");
for (int i=0; i<dits.length; i++){
if (i!=0){
sb.append(", ");
}
sb.append(dits[i].toString());
}
return sb.toString()+"}";
}
public Object clone() {
Subtree[] a = null;
if (dits != null) {
a = new Subtree[dits.length];
System.arraycopy(dits, 0, a, 0, a.length);
}
String[] b = null;
if (objectClasses != null) {
b = new String[objectClasses.length];
System.arraycopy(objectClasses, 0, b, 0, b.length);
}
return new ComplexSubtree(a, b);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -