1 | package com.nailabs.abac.process; |
---|
2 | |
---|
3 | import edu.stanford.peer.rbtm.credential.*; |
---|
4 | import com.nailabs.abac.trust.*; |
---|
5 | import java.util.*; |
---|
6 | |
---|
7 | public abstract class EdgeOperation implements Operation { |
---|
8 | /** the parent node of the edge (beginning point) */ |
---|
9 | private Goal parent; |
---|
10 | |
---|
11 | /** the child node of the edge (end point) */ |
---|
12 | private Goal child; |
---|
13 | |
---|
14 | private transient HashSet evidence; |
---|
15 | |
---|
16 | protected String type; |
---|
17 | |
---|
18 | protected ProcessingState state; |
---|
19 | |
---|
20 | public EdgeOperation(Goal p, Goal c, ProcessingState s, HashSet list) { |
---|
21 | parent = p; |
---|
22 | child = c; |
---|
23 | evidence = list; |
---|
24 | state = s; |
---|
25 | } |
---|
26 | |
---|
27 | |
---|
28 | /** Constructor method to make XML processing easier */ |
---|
29 | public EdgeOperation() { |
---|
30 | parent = null; |
---|
31 | child = null; |
---|
32 | evidence = null; |
---|
33 | state = null; |
---|
34 | } |
---|
35 | |
---|
36 | /** |
---|
37 | * Modifier method for the setting the parent node of an edge. |
---|
38 | * Added this method to make XML processing easier |
---|
39 | */ |
---|
40 | public void setParent(Goal p) { parent = p; } |
---|
41 | |
---|
42 | /** |
---|
43 | * Modifier method for setting the child node of an edge. |
---|
44 | * Added this method to make XML processing easier |
---|
45 | */ |
---|
46 | public void setChild(Goal c) { child = c; } |
---|
47 | |
---|
48 | /** |
---|
49 | * Modifier method for setting the processing state of the child node. |
---|
50 | * Added this method to make XML processing easier |
---|
51 | */ |
---|
52 | public void setProcessingState(ProcessingState s) { state = s; } |
---|
53 | |
---|
54 | public final boolean hasNewChild() { return (state != null); } |
---|
55 | |
---|
56 | public final void perform(TTG graph) { |
---|
57 | if(hasNewChild()) |
---|
58 | performNewAdditional(graph); |
---|
59 | else |
---|
60 | performAdditional(graph); |
---|
61 | } |
---|
62 | |
---|
63 | public Goal getParent() { return parent; } |
---|
64 | |
---|
65 | public Goal getChild() { return child; } |
---|
66 | |
---|
67 | public String getType() { return type; } |
---|
68 | |
---|
69 | public ProcessingState getProcessingState() { return state; } |
---|
70 | |
---|
71 | public HashSet getEvidence() { return evidence; } |
---|
72 | |
---|
73 | public void setEvidence(HashSet set) { evidence = set; } |
---|
74 | |
---|
75 | public abstract void performAdditional(TTG graph); |
---|
76 | |
---|
77 | public abstract void performNewAdditional(TTG graph); |
---|
78 | |
---|
79 | protected String performNewInfo() { |
---|
80 | StringBuffer buff = new StringBuffer("adding new child for "); |
---|
81 | buff.append(getChild().toString()); |
---|
82 | return buff.toString(); |
---|
83 | } |
---|
84 | |
---|
85 | public String toXML() { |
---|
86 | return toXML(""); |
---|
87 | } |
---|
88 | |
---|
89 | protected String toXML(String args) { |
---|
90 | StringBuffer buff = new StringBuffer("<EdgeOperation type=\""); |
---|
91 | buff.append(type).append("\" newChild=\""); |
---|
92 | buff.append(hasNewChild()).append("\""); |
---|
93 | buff.append(args); |
---|
94 | buff.append(">\n"); |
---|
95 | if(getParent() != null) { |
---|
96 | buff.append("<Parent>\n"); |
---|
97 | buff.append(getParent().toXML()); |
---|
98 | buff.append("</Parent>\n"); |
---|
99 | } |
---|
100 | if(getChild() != null) { |
---|
101 | buff.append("<Child>\n"); |
---|
102 | buff.append(getChild().toXML()); |
---|
103 | buff.append("</Child>\n"); |
---|
104 | } |
---|
105 | if(state != null) |
---|
106 | buff.append(state.toXML()); |
---|
107 | //if(evidence != null) { |
---|
108 | if(false) { |
---|
109 | int count = 0; |
---|
110 | Iterator i = evidence.iterator(); |
---|
111 | StringBuffer creds = new StringBuffer(); |
---|
112 | for(count = 0;i.hasNext();count++) { |
---|
113 | try { |
---|
114 | StaticCredential cred = (StaticCredential)i.next(); |
---|
115 | //creds.append("<Credential>"); |
---|
116 | //creds.append(cred.toXML()); |
---|
117 | //creds.append("</Credential>\n"); |
---|
118 | } |
---|
119 | catch(Exception ex) { |
---|
120 | //ex.printStackTrace(); |
---|
121 | } |
---|
122 | if(count > 0) { |
---|
123 | //buff.append("<Evidence count=\"").append(++count); |
---|
124 | //buff.append("\">\n"); |
---|
125 | //buff.append(creds.toString()); |
---|
126 | //buff.append("</Evidence>\n"); |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | buff.append("</EdgeOperation>\n"); |
---|
131 | return buff.toString(); |
---|
132 | } |
---|
133 | |
---|
134 | /** convert this edge into a human-readable formatted String */ |
---|
135 | public String toString() { |
---|
136 | StringBuffer buff = new StringBuffer("["); |
---|
137 | buff.append(type).append("Edge"); |
---|
138 | buff.append(getParent()).append(" <<=== "); |
---|
139 | buff.append(getChild()).append(", state = "); |
---|
140 | buff.append(state).append("]"); |
---|
141 | return buff.toString(); |
---|
142 | } |
---|
143 | |
---|
144 | } |
---|