source: fedd/abac-src/ttg/process/NodeOperation.java @ df783c1

axis_examplecompt_changesinfo-opsversion-2.00version-3.01version-3.02
Last change on this file since df783c1 was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 3.4 KB
Line 
1package com.nailabs.abac.process;
2
3import com.nailabs.abac.trust.*;
4import com.nailabs.abac.test.*;
5
6/**
7 * This is a specialized operation for transmitting a root node between
8 * negotiators.
9 */
10public class NodeOperation implements Operation {
11    /** The new node to construct */
12    Goal goal;
13
14    /** An optional processing state */
15    ProcessingState state;
16
17    /** a flag to denote whether this is a new (i.e. root) node or not */
18    boolean isRoot = false;
19
20    /** root node operation constructor */
21    public NodeOperation(Goal g, ProcessingState ps, boolean isRoot) {
22        goal = g;
23        state = ps;
24        this.isRoot = isRoot;
25    }
26
27    /** non-root, node state change operation */
28    public NodeOperation(Goal g, ProcessingState ps) {
29        goal = g;
30        state = ps;
31        isRoot = false;
32    }
33   
34    /** Jared: Added this method to make XML processing easier */
35    public NodeOperation() {
36        goal = null;
37        state = null;
38    }
39   
40    /** Jared: Added this method to make XML processing easier */
41    public void setGoal(Goal g) { goal = g; }
42   
43    /** Jared: Added this method to make XML processing easier */
44    public void setProcessingState(ProcessingState ps) { state = ps; }
45   
46    /** Jared: Added this method to make XML processing easier */
47    public void setRoot(boolean isRoot) { this.isRoot = isRoot; }
48
49    /** public accessor method used for logging this node's goal */
50    public Goal getGoal() { return goal; }
51
52    /** public accessor method for determinig whether this is a root node */
53    public boolean isRoot() { return isRoot; }
54
55    /** public accessor method for finding the updated processing state */
56    public ProcessingState getProcessingState() { return state; }
57
58    /**
59     * Either add a new node to the root of the trust target graph or
60     * update the processing state of an existing node.
61     */
62    public void perform(TTG graph) {
63        StringBuffer buff;
64        if(isRoot) {
65            buff = new StringBuffer("adding root node ");
66            buff.append(goal).append(" to ").append(graph);
67            debug("root", buff.toString());
68            graph.putRoot((TargetNode)graph.getNode((TrustTarget)goal));
69        }
70        buff = new StringBuffer("updating node ");
71        buff.append(goal).append(" with ").append(state);
72        debug("node", buff.toString());
73        TTGNode node = graph.getNodeByHash(goal);
74        //node.getProcessingState().update(state);
75    node.updateProcessingState(state);
76    }
77
78    /** Friendly debugging convenience method */
79    protected void debug(String level, String message) {
80        StringBuffer buff = new StringBuffer("NodeOperation:");
81        buff.append(message);
82        Debug.debug(level, buff.toString());
83    }
84
85    public String toXML() {
86        StringBuffer buff =  new StringBuffer("<NodeOperation");
87        if(isRoot) {
88            buff.append(" type=\"root\">\n");
89        } else {
90            buff.append(">\n");
91        }
92        buff.append("<TrustTarget>");
93        buff.append(goal.toXML());
94        buff.append("</TrustTarget>\n");
95        buff.append(state.toXML());
96        buff.append("</NodeOperation>\n");
97        return buff.toString();
98    }
99
100
101    /** Converts this operation into a string */
102    public String toString() {
103        StringBuffer buff = new StringBuffer("[NodeOperation ");
104        if(isRoot){
105            buff.append("root = ").append(goal);
106            if(state != null) {
107                buff.append(", processing state = ").append(state);
108            }
109        }
110        else {
111            buff.append("node = ").append(goal);
112            buff.append(", processing state = ").append(state);
113        }
114        buff.append("]");
115        return buff.toString();
116    }
117
118}
119
Note: See TracBrowser for help on using the repository browser.