KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > ddl > revoke > RoleDependencyGraph


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.revoke;
2
3 /**
4  *
5  * @author pardeep
6  */

7 import java.util.*;
8
9 import com.daffodilwoods.daffodildb.server.serversystem.*;
10 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*;
11 import com.daffodilwoods.database.resource.*;
12
13 public class RoleDependencyGraph {
14
15    ArrayList unfinishedList;
16    HashMap graph;
17    CalculateDD calculateDD;
18    public RoleDependencyGraph(_ServerSession serverSession) throws DException {
19       graph = new HashMap();
20       unfinishedList = new ArrayList();
21       calculateDD = new CalculateDD(serverSession);
22    }
23
24    public void addVertex(RoleAuthorizationDescriptor rad) {
25       if (notInGraph(rad)) {
26          graph.put(rad, null);
27       } else {
28          doOtherThings();
29       }
30    }
31
32    public void addVertex(RoleAuthorizationDescriptor rad, RADCharacterstics charac) {
33       if (notInGraph(rad)) {
34          graph.put(rad, charac);
35       } else {
36          doOtherThings();
37       }
38    }
39
40    public void initialiseGraph(_ServerSession serverSession, ArrayList identifiedRole) throws DException {
41       ArrayList roleList = calculateDD.getRoleNames(serverSession);
42       unfinishedList.addAll(identifiedRole);
43
44       for (int i = 0; i < unfinishedList.size(); i++) {
45          RoleAuthorizationDescriptor rad = (RoleAuthorizationDescriptor) unfinishedList.get(i);
46          RADCharacterstics charac = new RADCharacterstics();
47          Object JavaDoc[] obj = calculateDD.getDependentAndAncestor(serverSession, rad, roleList);
48          HashMap dep = (HashMap) obj[0];
49          HashMap anc = (HashMap) obj[1];
50
51          if (anc != null) {
52             Iterator iter = anc.keySet().iterator();
53             while (iter.hasNext()) {
54                RoleAuthorizationDescriptor temprad = (RoleAuthorizationDescriptor) iter.next();
55                if (!graph.containsKey(temprad)) {
56                   unfinishedList.add(temprad);
57                }
58             }
59             charac.setAncestors(anc);
60          } else {
61             charac.setAncestors( (HashMap)null);
62          }
63
64          if (dep != null) {
65             Iterator iter = dep.keySet().iterator();
66             while (iter.hasNext()) {
67                RoleAuthorizationDescriptor temprad = (RoleAuthorizationDescriptor) iter.next();
68                if (!graph.containsKey(temprad)) {
69                   unfinishedList.add(temprad);
70                }
71             }
72             charac.setDependents(dep);
73          } else {
74             charac.setDependents( (HashMap)null);
75          }
76          addVertex(rad, charac);
77       }
78       markIdentifiedRADescriptor(identifiedRole);
79       markIndependentNode();
80       markAbandonedRADescriptor(serverSession);
81    }
82
83    private void markIdentifiedRADescriptor(ArrayList identifiedList) {
84       for (int i = 0, size = identifiedList.size(); i < size; i++) {
85          RoleAuthorizationDescriptor pd = (RoleAuthorizationDescriptor) identifiedList.get(i);
86          RADCharacterstics characterstic = (RADCharacterstics) graph.get(pd);
87          characterstic.setStatus(_RADCharacterstics.indentified);
88
89       }
90    }
91
92
93    private void markAbandonedRADescriptor(_ServerSession serverSession) throws DException {
94       if (graph != null) {
95          Iterator iter = graph.keySet().iterator();
96          while (iter.hasNext()) {
97             RoleAuthorizationDescriptor rad = (RoleAuthorizationDescriptor) iter.next();
98             RADCharacterstics charac = (RADCharacterstics) graph.get(rad);
99             HashMap pathElement = new HashMap();
100             if (!charac.isIndependentNode() && charac.getStatus() != _RADCharacterstics.indentified && isPathFromIndependentConidtionSatisfying(rad, false, pathElement)) {
101                charac.setStatus(_RADCharacterstics.abandoned);
102             }
103          }
104       }
105    }
106
107    private void markIndependentNode() throws DException {
108       if (graph != null) {
109          Iterator iter = graph.keySet().iterator();
110          while (iter.hasNext()) {
111             RoleAuthorizationDescriptor rad = (RoleAuthorizationDescriptor) iter.next();
112             if (getAncestors(rad) == null) {
113                RADCharacterstics charac = (RADCharacterstics) graph.get(rad);
114                charac.setIndependentNode(true);
115             }
116          }
117       }
118    }
119
120    public boolean isPathFromIndependentConidtionSatisfying(RoleAuthorizationDescriptor rad, boolean condition, HashMap pathElement) throws DException {
121       pathElement.put(rad, null);
122       HashMap anc = getAncestors(rad);
123       boolean flag = false;
124       if (anc != null) {
125          Iterator iter = anc.keySet().iterator();
126          while (iter.hasNext()) {
127             RoleAuthorizationDescriptor temprad = (RoleAuthorizationDescriptor) iter.next();
128             if (pathElement.containsKey(temprad)) {
129                return false;
130             }
131             RADCharacterstics charac = (RADCharacterstics) graph.get(temprad);
132             if (charac.getStatus() == _PDCharacterstics.indentified) {
133                if (charac.isIndependentNode()) {
134                   return true;
135                }
136                return isPathFromIndependentConidtionSatisfying(temprad, true, pathElement);
137             } else {
138                if (charac.isIndependentNode() && !condition) {
139                   return false;
140                }
141                return isPathFromIndependentConidtionSatisfying(temprad, false, pathElement);
142             }
143          }
144       }
145       return true;
146    }
147
148    public HashMap getDependents(RoleAuthorizationDescriptor rad) throws DException {
149       if (graph == null) {
150          return null;
151       }
152       RADCharacterstics temp = (RADCharacterstics) graph.get(rad);
153       if (temp == null) {
154          return null;
155       }
156       return temp.getDependents();
157    }
158
159    public HashMap getAncestors(RoleAuthorizationDescriptor rad) throws DException {
160       if (graph == null) {
161          return null;
162       }
163       RADCharacterstics temp = (RADCharacterstics) graph.get(rad);
164       if (temp == null) {
165          return null;
166       }
167       return temp.getAncestors();
168    }
169
170    public boolean isIndenpendentNode(RoleAuthorizationDescriptor rad) throws DException {
171       RADCharacterstics temp = (RADCharacterstics) graph.get(rad);
172       if (temp == null) {
173          throw new DException("DSE5046", null);
174       }
175       return temp.isIndependentNode();
176    }
177
178    public int getStatus(RoleAuthorizationDescriptor rad) throws DException {
179       RADCharacterstics temp = (RADCharacterstics) graph.get(rad);
180       if (temp == null) {
181          throw new DException("DSE5046", null);
182       }
183       return temp.getStatus();
184    }
185
186    private boolean notInGraph(RoleAuthorizationDescriptor rad) {
187       return!graph.containsKey(rad);
188    }
189
190    private void doOtherThings() {
191    }
192
193    public ArrayList getAllAbandonedRADescriptor() throws DException {
194       if (graph != null) {
195          ArrayList temp = new ArrayList();
196          Iterator iter = graph.keySet().iterator();
197          while (iter.hasNext()) {
198             RoleAuthorizationDescriptor rad = (RoleAuthorizationDescriptor) iter.next();
199             if (getStatus(rad) == _RADCharacterstics.abandoned) {
200                temp.add(rad);
201             }
202          }
203          return temp;
204       }
205       return null;
206    }
207
208    public void printGraph() throws DException {
209       if (graph != null) {
210          Iterator iter = graph.keySet().iterator();
211          int i = 0;
212          while (iter.hasNext()) {
213             RoleAuthorizationDescriptor rad = (RoleAuthorizationDescriptor) iter.next();
214             print_RA_descriptor(rad, "[" + i + "] Entry ");
215             RADCharacterstics ch = (RADCharacterstics) graph.get(rad);
216             HashMap anc = ch.getAncestors();
217             if (anc == null) {
218          ;//// Removed By Program ** System.out.println("\tNo Ancestor");
219
} else {
220                Iterator t = anc.keySet().iterator();
221                int j = 0;
222                while (t.hasNext()) {
223                   RoleAuthorizationDescriptor temprad = (RoleAuthorizationDescriptor) t.next();
224                   print_RA_descriptor(temprad, "\tAncestor [" + j + "] ");
225                   j++;
226                }
227             }
228             HashMap dep = ch.getDependents();
229             if (dep == null) {
230          ;//// Removed By Program ** System.out.println("\tNo Dependent");
231
} else {
232                Iterator t = dep.keySet().iterator();
233                int j = 0;
234                while (t.hasNext()) {
235                   RoleAuthorizationDescriptor temprad = (RoleAuthorizationDescriptor) t.next();
236                   print_RA_descriptor(temprad, "\tDependent [" + j + "] ");
237                   j++;
238                }
239             }
240             i++;
241          }
242       } else {
243          ;//// Removed By Program ** System.out.println("Graph is null");
244
}
245    }
246
247
248    public void print_identified_RA_descriptor() throws DException {
249       int i = 0;
250       if (graph != null) {
251          Iterator iter = graph.keySet().iterator();
252          while (iter.hasNext()) {
253             RoleAuthorizationDescriptor rad = (RoleAuthorizationDescriptor) iter.next();
254             if (getStatus(rad) == _RADCharacterstics.indentified) {
255                print_RA_descriptor(rad, "\t[" + ++i + "] ");
256             }
257          }
258       }
259       if (i == 0) {
260          ;//// Removed By Program ** System.out.println("\t NONE");
261
}
262    }
263
264    public void print_abandoned_RA_descriptor() throws DException {
265       int i = 0;
266       if (graph != null) {
267          Iterator iter = graph.keySet().iterator();
268          while (iter.hasNext()) {
269             RoleAuthorizationDescriptor rad = (RoleAuthorizationDescriptor) iter.next();
270             if (getStatus(rad) == _RADCharacterstics.abandoned) {
271                print_RA_descriptor(rad, "\t[" + ++i + "] ");
272             }
273          }
274       }
275       if (i == 0) {
276          ;//// Removed By Program ** System.out.println("\t NONE");
277
}
278    }
279
280    public void print_independent_nodes() throws DException {
281       int i = 0;
282       if (graph != null) {
283          Iterator iter = graph.keySet().iterator();
284          while (iter.hasNext()) {
285             RoleAuthorizationDescriptor rad = (RoleAuthorizationDescriptor) iter.next();
286             if (isIndenpendentNode(rad)) {
287                print_RA_descriptor(rad, "\t[" + ++i + "] ");
288             }
289          }
290       }
291       if (i == 0) {
292          ;//// Removed By Program ** System.out.println("\t NONE");
293
}
294    }
295
296    public static void print_RA_descriptor(RoleAuthorizationDescriptor rad, String JavaDoc extra) {
297    }
298 }
299
Popular Tags