001: /*
002: * OrgContainer.java
003: *
004: * Created on March 28, 2003, 8:34 PM
005: */
006:
007: package migration.modules.srap.ldap;
008:
009: import java.util.*;
010:
011: /**
012: *
013: * @author Mridul Muralidharan
014: * @version
015: */
016: public class OrgContainer implements Comparable {
017:
018: private Vector subOrganisations;
019: private String orgName;
020: private String parentOrg;
021: private OrgContainer parentOrgContainer;
022: private int orgLevel;
023: private static final char ORG_DELIMITER = ',';
024: private boolean isParentOrg;
025: private boolean isDummyOrg = false;
026:
027: public OrgContainer(String orgName) {
028: this (orgName, true);
029: }
030:
031: public OrgContainer(String orgName, boolean doParse) {
032:
033: this .orgName = orgName.trim();
034: orgLevel = 1;
035:
036: if (doParse) {
037: subOrganisations = new Vector();
038: int indx = -1;
039:
040: while ((indx = orgName.indexOf(ORG_DELIMITER, indx + 1)) != -1) {
041: orgLevel++;
042: }
043: if (orgLevel <= 1) {
044: this .parentOrg = "";
045: isParentOrg = true;
046: parentOrgContainer = null;
047: } else {
048: this .parentOrg = orgName.substring(
049: orgName.indexOf(ORG_DELIMITER) + 1).trim();
050: isParentOrg = false;
051: parentOrgContainer = new OrgContainer(parentOrg, false);
052: }
053: }
054: }
055:
056: public OrgContainer getParentOrgContainer() {
057: return parentOrgContainer;
058: }
059:
060: public void setThisAsRootNode() {
061: this .parentOrg = "";
062: this .isParentOrg = true;
063: }
064:
065: public String getOrgName() {
066: return orgName;
067: }
068:
069: public boolean equals(Object obj) {
070: if (obj instanceof OrgContainer) {
071: if (((OrgContainer) obj).getOrgName().equalsIgnoreCase(
072: this .orgName)) {
073: return true;
074: }
075: }
076: return false;
077: }
078:
079: public void addSubOrganisations(OrgContainer subOrg) {
080: if (subOrg != null) {
081: if (!subOrganisations.contains(subOrg)) {
082: subOrganisations.add(subOrg);
083: }
084: }
085: }
086:
087: public Vector getSubOrganisations() {
088: return subOrganisations;
089: }
090:
091: public String toString() {
092: return this .orgName;
093: }
094:
095: public int getOrgLevel() {
096: return this .orgLevel;
097: }
098:
099: public String getParentOrg() {
100: return parentOrg;
101: }
102:
103: public int compareTo(Object obj) {
104: // All classes here must be of type OrgContainer
105: OrgContainer other = (OrgContainer) obj;
106: int orgLevelDiff = getOrgLevel() - other.getOrgLevel();
107: if (orgLevelDiff == 0) {
108: return getOrgName().compareTo(other.getOrgName());
109: }
110: return orgLevelDiff;
111: }
112:
113: public void setDummyOrg() {
114: isDummyOrg = true;
115: }
116:
117: public boolean isDummyOrg() {
118: return isDummyOrg;
119: }
120: }
|