Commit 7b56aabe authored by Steve Sonntag's avatar Steve Sonntag

Take vector out of LDAPSchema, DN, and RDN

parent 83390695
......@@ -17,6 +17,8 @@ package com.novell.ldap;
import java.util.Enumeration;
import java.util.Hashtable;
import com.novell.ldap.client.ArrayList;
import com.novell.ldap.client.ArrayEnumeration;
/**
* The schema of a particular directory server.
......@@ -500,14 +502,14 @@ public class LDAPSchema {
* @return An enumeration of attribute names.
*/
public Enumeration getAttributeNames() {
java.util.Vector names = new java.util.Vector(attributeHashtable.size());
ArrayList names = new ArrayList(attributeHashtable.size());
Enumeration elements = attributeHashtable.elements();
LDAPSchemaElement el;
while (elements.hasMoreElements()){
LDAPSchemaElement el = (LDAPSchemaElement)elements.nextElement();
names.add(el.getName());
el = (LDAPSchemaElement)elements.nextElement();
names.add(el.getName());
}
return names.elements();
return new ArrayEnumeration(names.toArray());
}
/**
......@@ -516,14 +518,14 @@ public class LDAPSchema {
* @return An enumeration of object class names.
*/
public Enumeration getObjectClassNames() {
java.util.Vector names = new java.util.Vector(objectClassHashtable.size());
ArrayList names = new ArrayList(objectClassHashtable.size());
Enumeration elements = objectClassHashtable.elements();
while (elements.hasMoreElements()){
LDAPSchemaElement el = (LDAPSchemaElement)elements.nextElement();
LDAPSchemaElement el;
while (elements.hasMoreElements()) {
el = (LDAPSchemaElement)elements.nextElement();
names.add(el.getName());
}
return names.elements();
return new ArrayEnumeration(names.toArray());
}
/**
......@@ -532,14 +534,14 @@ public class LDAPSchema {
* @return An enumeration of matching rule names.
*/
public Enumeration getMatchingRuleNames() {
java.util.Vector names = new java.util.Vector(matchingRuleHashtable.size());
ArrayList names = new ArrayList(matchingRuleHashtable.size());
Enumeration elements = matchingRuleHashtable.elements();
LDAPSchemaElement el;
while (elements.hasMoreElements()){
LDAPSchemaElement el = (LDAPSchemaElement)elements.nextElement();
el = (LDAPSchemaElement)elements.nextElement();
names.add(el.getName());
}
return names.elements();
return new ArrayEnumeration(names.toArray());
}
/**
......@@ -548,14 +550,14 @@ public class LDAPSchema {
* @return An enumeration of matching rule use names.
*/
public Enumeration getMatchingRuleUseNames() {
java.util.Vector names = new java.util.Vector(matchingRuleUseHashtable.size());
ArrayList names = new ArrayList(matchingRuleUseHashtable.size());
Enumeration elements = matchingRuleUseHashtable.elements();
LDAPSchemaElement el;
while (elements.hasMoreElements()){
LDAPSchemaElement el = (LDAPSchemaElement)elements.nextElement();
el = (LDAPSchemaElement)elements.nextElement();
names.add(el.getName());
}
return names.elements();
return new ArrayEnumeration(names.toArray());
}
/**
......@@ -564,14 +566,14 @@ public class LDAPSchema {
* @return An enumeration of DIT structure rule names.
*/
public Enumeration getDITStructureRuleNames() {
java.util.Vector names = new java.util.Vector(dITStructureRuleHashtable.size());
ArrayList names = new ArrayList(dITStructureRuleHashtable.size());
Enumeration elements = dITStructureRuleHashtable.elements();
LDAPSchemaElement el;
while (elements.hasMoreElements()){
LDAPSchemaElement el = (LDAPSchemaElement)elements.nextElement();
el = (LDAPSchemaElement)elements.nextElement();
names.add(el.getName());
}
return names.elements();
return new ArrayEnumeration(names.toArray());
}
/**
......@@ -580,14 +582,14 @@ public class LDAPSchema {
* @return An enumeration of DIT content rule names.
*/
public Enumeration getDITContentRuleNames() {
java.util.Vector names = new java.util.Vector(dITContentRuleHashtable.size());
ArrayList names = new ArrayList(dITContentRuleHashtable.size());
Enumeration elements = dITContentRuleHashtable.elements();
LDAPSchemaElement el;
while (elements.hasMoreElements()){
LDAPSchemaElement el = (LDAPSchemaElement)elements.nextElement();
el = (LDAPSchemaElement)elements.nextElement();
names.add(el.getName());
}
return names.elements();
return new ArrayEnumeration(names.toArray());
}
/**
......@@ -596,13 +598,13 @@ public class LDAPSchema {
* @return An enumeration of name form names.
*/
public Enumeration getNameFormNames() {
java.util.Vector names = new java.util.Vector(nameFormHashtable.size());
ArrayList names = new ArrayList(nameFormHashtable.size());
Enumeration elements = nameFormHashtable.elements();
LDAPSchemaElement el;
while (elements.hasMoreElements()){
LDAPSchemaElement el = (LDAPSchemaElement)elements.nextElement();
el = (LDAPSchemaElement)elements.nextElement();
names.add(el.getName());
}
return names.elements();
return new ArrayEnumeration(names.toArray());
}
}
......@@ -25,7 +25,7 @@ import java.lang.reflect.Array;
* <strong>Note that this implementation is not synchronized.</strong>
*/
public class ArrayList
public class ArrayList implements Cloneable
{
/**
* The array buffer which holds ArrayList items. Its capacity
......@@ -86,6 +86,18 @@ public class ArrayList
return size == 0;
}
/**
* Returns a shallow copy of this object.
* It does not make copies of the elements in the ArrayList.
*
* @return a clone of this object.
*/
public Object clone() {
ArrayList newAList = new ArrayList(size);
System.arraycopy(this.items, 0, newAList.items, 0, size);
return newAList;
}
/**
* Increases the size of this <tt>ArrayList</tt>, if necessary,
* to be sure it can hold the number of items specified by
......
......@@ -14,6 +14,7 @@
******************************************************************************/
package com.novell.ldap.util;
import com.novell.ldap.util.RDN;
import com.novell.ldap.client.ArrayList;
import java.util.Vector;
/**
......@@ -49,7 +50,7 @@ public class DN extends Object
private static final int HEX_RDN_VALUE = 6;
private static final int UNQUOTED_RDN_VALUE = 7;
private Vector rdnList = new Vector();
private ArrayList rdnList = new ArrayList();
public DN (){}
/**
......@@ -234,7 +235,7 @@ public class DN extends Object
//added by cameron
currRDN.add(attrType, attrValue, rawValue);
if (currChar != '+'){
rdnList.addElement(currRDN);
rdnList.add(currRDN);
currRDN = new RDN();
}
......@@ -271,7 +272,7 @@ public class DN extends Object
currRDN.add(attrType, attrValue, rawValue);
if (currChar != '+'){
rdnList.addElement(currRDN);
rdnList.add(currRDN);
currRDN = new RDN();
}
trailingSpaceCount = 0;
......@@ -329,7 +330,7 @@ public class DN extends Object
//added by cameron
currRDN.add(attrType, attrValue, rawValue);
if (currChar != '+'){
rdnList.addElement(currRDN);
rdnList.add(currRDN);
currRDN = new RDN();
}
tokenIndex = 0;
......@@ -359,7 +360,7 @@ public class DN extends Object
rawValue =
dnString.substring(valueStart, currIndex - trailingSpaceCount);
currRDN.add(attrType,attrValue,rawValue);
rdnList.addElement(currRDN);
rdnList.add(currRDN);
}
else if (state != LOOK_FOR_RDN_ATTR_TYPE)
{
......@@ -551,7 +552,12 @@ public class DN extends Object
* @return list of RDNs
*/
public Vector getRDNs(){
return (Vector)rdnList.clone();
int size = rdnList.size();
Vector v = new Vector( size);
for( int i = 0; i < size; i++) {
v.addElement( rdnList.get(i));
}
return v;
}
/** Determines if this DN is <I>contained</I> by the DN passed in. For
......@@ -568,8 +574,8 @@ public class DN extends Object
int j = this.rdnList.size() -1; //index to an RDN of the ContainedDN
//Search from the end of the DN for an RDN that matches the end RDN of
//containerDN.
while ( !((RDN)this.rdnList.elementAt(j--)).equals(
(RDN)containerDN.rdnList.elementAt(i))){
while ( !((RDN)this.rdnList.get(j--)).equals(
(RDN)containerDN.rdnList.get(i))){
if (j <= 0)
return false;
//if the end RDN of containerDN does not have any equal
......@@ -579,8 +585,8 @@ public class DN extends Object
j--;
//step backwards to verify that all RDNs in containerDN exist in this DN
for (/* i, j */ ; i>=0 && j >=0; i--, j--){
if (!((RDN)this.rdnList.elementAt(j)).equals(
(RDN)containerDN.rdnList.elementAt(i)))
if (!((RDN)this.rdnList.get(j)).equals(
(RDN)containerDN.rdnList.get(i)))
return false;
}
if (j == 0 && i == 0) //the DNs are identical and thus not contained
......@@ -595,7 +601,7 @@ public class DN extends Object
*/
public DN getParent(){
DN parent = new DN();
parent.rdnList = (Vector)this.rdnList.clone();
parent.rdnList = (ArrayList)this.rdnList.clone();
if (parent.rdnList.size() >= 1)
parent.rdnList.remove(0); //remove first object
return parent;
......@@ -606,7 +612,7 @@ public class DN extends Object
* @param an RDN to be added
*/
public void addRDN(RDN rdn){
rdnList.insertElementAt(rdn, 0);
rdnList.add(0, rdn);
}
/**
......@@ -614,7 +620,7 @@ public class DN extends Object
* @param an RDN to be added
*/
public void addRDNToFront(RDN rdn){
rdnList.insertElementAt(rdn, 0);
rdnList.add(0, rdn);
}
/**
......@@ -622,6 +628,6 @@ public class DN extends Object
* @param an RDN to be added
*/
public void addRDNToBack(RDN rdn){
rdnList.addElement(rdn);
rdnList.add(rdn);
}
} //end class DN
......@@ -14,6 +14,7 @@
******************************************************************************/
package com.novell.ldap.util;
import com.novell.ldap.client.ArrayList;
import java.util.Vector;
/**
......@@ -35,9 +36,9 @@ import java.util.Vector;
public class RDN extends Object
{
private Vector types; //list of Type strings
private Vector values; //list of Value strings
private String rawValue; //the unnormalized value
private ArrayList types; //list of Type strings
private ArrayList values; //list of Value strings
private String rawValue; //the unnormalized value
/**
* Creates an RDN object from the DN component specified in the string RDN
......@@ -56,12 +57,14 @@ public class RDN extends Object
this.types = thisRDN.types;
this.values = thisRDN.values;
this.rawValue = thisRDN.rawValue;
return;
}
public RDN(){
types = new Vector();
values = new Vector();
types = new ArrayList();
values = new ArrayList();
rawValue = "";
return;
}
/**
......@@ -69,6 +72,9 @@ public class RDN extends Object
* mulivalues in one RDN they must all be present in the other.
*
* @param the RDN to compare to
*
* @throws IllegalArgumentException if the application compares a name
* with an OID.
*/
public boolean equals(RDN rdn){
if (this.values.size() != rdn.values.size()){
......@@ -80,10 +86,10 @@ public class RDN extends Object
j=0;
//May need a more intellegent compare
while ( j<values.size() && (
!((String)this.values.elementAt(i)).equalsIgnoreCase(
(String) rdn.values.elementAt(j)) ||
!equalAttrType((String)this.types.elementAt(i),
(String) rdn.types.elementAt(j)))){
!((String)this.values.get(i)).equalsIgnoreCase(
(String) rdn.values.get(j)) ||
!equalAttrType((String)this.types.get(i),
(String) rdn.types.get(j)))){
j++;
}
if (j >= rdn.values.size()) //couldn't find first value
......@@ -107,8 +113,8 @@ public class RDN extends Object
if (java.lang.Character.isDigit(attr1.charAt(0)) ^ //XOR
java.lang.Character.isDigit(attr2.charAt(0)) )
//isDigit tests if it is an OID
throw new UnsupportedOperationException("OID numbers are not " +
"currently compared to attribute types");
throw new IllegalArgumentException("OID numbers are not " +
"currently compared to attribute names");
return attr1.equalsIgnoreCase(attr2);
}
......@@ -131,8 +137,8 @@ public class RDN extends Object
* @param rawValue or text before normalization, can be Null
*/
public void add(String attrType, String attrValue, String rawValue){
types.addElement(attrType);
values.addElement(attrValue);
types.add(attrType);
values.add(attrValue);
this.rawValue += rawValue;
}
......@@ -201,7 +207,7 @@ public class RDN extends Object
* @return Type of attribute
*/
public String getType(){
return (String)types.elementAt(0);
return (String)types.get(0);
}
/**
......@@ -211,7 +217,7 @@ public class RDN extends Object
public String[] getTypes(){
String[] toReturn = new String[types.size()];
for(int i=0; i<types.size(); i++)
toReturn[i] = (String)types.elementAt(i);
toReturn[i] = (String)types.get(i);
return toReturn;
}
......@@ -222,7 +228,7 @@ public class RDN extends Object
* @return Type of attribute
*/
public String getValue(){
return (String)values.elementAt(0);
return (String)values.get(0);
}
/**
......@@ -232,7 +238,7 @@ public class RDN extends Object
public String[] getValues(){
String[] toReturn = new String[values.size()];
for(int i=0; i<values.size(); i++)
toReturn[i] = (String)values.elementAt(i);
toReturn[i] = (String)values.get(i);
return toReturn;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment