001: /*
002: * OrgContainerParser.java
003: *
004: * Created on March 30, 2003, 12:06 AM
005: */
006:
007: package migration.modules.srap.ldap;
008:
009: import java.util.*;
010: import java.io.*;
011:
012: /**
013: *
014: * @author Mridul Murlaidharan
015: * @version
016: */
017: public class OrgContainerParser {
018:
019: public static List parse(List orgList, String rootsuffix) {
020: Iterator iter = orgList.iterator();
021: List orgContainerList = new LinkedList();
022: boolean wasRootAdded = false;
023:
024: while (iter.hasNext()) {
025: OrgContainer org = new OrgContainer(iter.next().toString());
026: if (!orgContainerList.contains(org)) {
027: orgContainerList.add(org);
028: }
029: }
030:
031: OrgContainer rootOrg = new OrgContainer(rootsuffix);
032: int tmpIndx = orgContainerList.indexOf(rootOrg);
033: if (tmpIndx == -1) {
034: // Add this as a dummy entry.
035: rootOrg.setThisAsRootNode();
036: orgContainerList.add(rootOrg);
037: rootOrg.setDummyOrg();
038: wasRootAdded = true;
039: } else {
040: // Set this as the root entry - no parent.
041: ((OrgContainer) orgContainerList.get(tmpIndx))
042: .setThisAsRootNode();
043: wasRootAdded = false;
044: }
045:
046: iter = orgContainerList.iterator();
047: while (iter.hasNext()) {
048: OrgContainer org = (OrgContainer) iter.next();
049: int indx = orgContainerList.indexOf(org
050: .getParentOrgContainer());
051: if (indx != -1) {
052: // Add this org to its parents list.
053: OrgContainer parentOrg = (OrgContainer) orgContainerList
054: .get(indx);
055: parentOrg.addSubOrganisations(org);
056: }
057: }
058:
059: // Now every OrgContainer has its list of childreb added.
060: // Now just sort this list and return to the caller - we are done :)
061: Collections.sort(orgContainerList);
062: return orgContainerList;
063: }
064:
065: public static void writeReferalPolicy(FileWriter outFile,
066: OrgContainer org, String registeredServiceName,
067: String service) throws IOException {
068:
069: Iterator iter = org.getSubOrganisations().iterator();
070:
071: if (!iter.hasNext()) {
072: // No sub-orgs.
073: return;
074: }
075:
076: outFile.write("\n <OrganizationRequests DN=\""
077: + org.getOrgName() + "\">\n");
078: outFile.write("<CreatePolicy createDN=\"" + org.getOrgName()
079: + "\">\n");
080: outFile.write(" <Policy name=\"" + service
081: + "ReferalPolicy\" referralPolicy=\"true\">\n");
082: outFile.write(" <Rule name=\"" + service
083: + "ReferalRule\">\n");
084: outFile.write(" <ServiceName name=\""
085: + registeredServiceName + "\" />\n");
086: outFile
087: .write(" <ResourceName name=\"http://dummy_host/dummy"
088: + service + "ReferalPolicyPath\" />\n");
089: outFile.write(" </Rule>\n");
090: outFile.write(" <Referrals name=\"" + service
091: + "Referal\" description=\"\">\n");
092:
093: while (iter.hasNext()) {
094: OrgContainer subOrg = (OrgContainer) iter.next();
095: outFile.write(" <Referral name=\"" + service
096: + "SubOrgReferalFor" + subOrg.getOrgName()
097: + "\" type=\"SubOrgReferral\">\n");
098: outFile.write(" <AttributeValuePair>\n");
099: outFile
100: .write(" <Attribute name=\"Values\"/>\n");
101: outFile.write(" <Value>");
102: outFile.write(subOrg.getOrgName());
103: outFile.write("</Value>\n");
104: outFile.write(" </AttributeValuePair>\n");
105: outFile.write(" </Referral>\n");
106: }
107: outFile.write(" </Referrals>\n");
108: outFile.write(" </Policy>\n");
109: outFile.write("</CreatePolicy>\n");
110: outFile.write("</OrganizationRequests>\n");
111: }
112: }
|