home *** CD-ROM | disk | FTP | other *** search
- package asp.wizard.def;
-
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class DefCollection extends DefAbstract {
- private Vector _elements = new Vector();
-
- public void addElement(DefAbstract element) {
- if (element != null) {
- element.setParent(this);
- this._elements.addElement(element);
- }
-
- }
-
- public int getElementCount() {
- return this._elements.size();
- }
-
- public Enumeration getElements() {
- return this._elements.elements();
- }
-
- public Vector getElements(Class theClass) {
- Vector v = new Vector();
- Enumeration e = this.getElements();
-
- while(e.hasMoreElements()) {
- Object el = e.nextElement();
- if (theClass.isInstance(el)) {
- v.addElement(el);
- }
- }
-
- return v;
- }
-
- public DefAbstract getElement(String name) {
- DefAbstract el = null;
- boolean found = false;
- Enumeration e = this.getElements();
-
- while(e.hasMoreElements() && !found) {
- el = (DefAbstract)e.nextElement();
- if (el.getName().equals(name)) {
- found = true;
- }
- }
-
- return found ? el : null;
- }
-
- public void removeAllElements() {
- DefAbstract el = null;
- Enumeration e = this._elements.elements();
-
- while(e.hasMoreElements()) {
- el = (DefAbstract)e.nextElement();
- el.setParent((DefCollection)null);
- }
-
- this._elements.removeAllElements();
- }
-
- public void removeElement(String name, Class elclass) {
- DefAbstract el = this.getElement(name);
- if (el != null) {
- el.setParent((DefCollection)null);
- this._elements.removeElement(el);
- }
-
- }
-
- public void removeElement(DefAbstract theElement) {
- boolean found = false;
- Enumeration e = this.getElements();
-
- while(e.hasMoreElements() && !found) {
- DefAbstract el = (DefAbstract)e.nextElement();
- if (el == theElement) {
- el.setParent((DefCollection)null);
- this._elements.removeElement(el);
- found = true;
- }
- }
-
- }
-
- public void removeElement(Class theClass) {
- Enumeration e = this.getElements();
-
- while(e.hasMoreElements()) {
- Object el = e.nextElement();
- String className = el.getClass().getName();
- if (className == theClass.getName()) {
- ((DefAbstract)el).setParent((DefCollection)null);
- this._elements.removeElement(el);
- }
- }
-
- }
-
- public boolean hasElement(DefAbstract anElement) {
- return this._elements.indexOf(anElement) != -1;
- }
-
- public String getUniqueNameFor(DefAbstract anElement) {
- if (anElement == null) {
- return null;
- } else {
- int index = 1;
- String baseName = anElement.getBaseName();
- Enumeration e = this._elements.elements();
-
- while(e.hasMoreElements()) {
- String uniqueName = baseName + Integer.toString(index);
- DefAbstract currElement = (DefAbstract)e.nextElement();
- if (currElement.getName().equals(uniqueName) && currElement != anElement) {
- ++index;
- }
- }
-
- String uniqueName = baseName + Integer.toString(index);
- return uniqueName;
- }
- }
-
- public String getBaseName() {
- return "AbstractType";
- }
- }
-