source: fedd/abac-src/ttg/trust/TTGNode.java @ 705233b

version-1.30
Last change on this file since 705233b was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 * Copyrighted (C) 2002, Networks Associates Technology, Inc.
3 * All rights reserved
4 */
5package com.nailabs.abac.trust;
6
7import com.nailabs.abac.process.*;
8import com.nailabs.abac.test.*;
9import edu.stanford.peer.rbtm.credential.*;
10import java.util.*;
11import java.io.*;
12
13/**
14 * A generic node type for a trust target graph (TTG). The node encapsulates
15 * a trust target and provides methods for processing a node.
16 */
17public abstract class TTGNode extends Observable
18    implements Observer, Serializable, XMLizable {
19
20    /** A trust target that this node represents on the graph */
21    private Goal goal = null;
22
23    /** A negotiation context which binds graph, strategy, and frontiers */
24    protected NegotiationContext context;
25
26    /** The processing state of this graph node */
27    protected transient ProcessingState processor = new ProcessingState();
28
29    /** Encapsulated set of parents for a TTG node */
30    protected TTGNodeSet parents = new TTGNodeSet();
31
32    /** Encapsulated set of children for a TTG node */
33    protected TTGNodeSet children = new TTGNodeSet();
34   
35    /** Convenience debugging name to be overridden in subclasses */
36    protected String subName = "TTGNode";
37
38    /** Generic node factory method which creates a node based on a goal */
39    public static TTGNode createNode(Goal seed) {
40        if(seed instanceof TrustTarget) {
41            EntityExpression target = ((TrustTarget)seed).getTargetRole();
42            if(target instanceof Entity) {
43                return new TrivialTTNode((TrustTarget)seed);
44            }
45            if(target instanceof Role) {
46                return new SimpleTTNode((TrustTarget)seed);
47            }
48            if(target instanceof LinkedRole) {
49                return new LinkTTNode((TrustTarget)seed);
50            }
51            if(target instanceof Intersection) {
52                return new IntersectionTTNode((TrustTarget)seed);
53            }
54        }
55        if(seed instanceof LinkingGoal) {
56            return new LinkingGoalNode((LinkingGoal)seed);
57        }
58        return null;
59    }
60
61    /** Default constructor. Subclasses should access processing state field */
62    public TTGNode(Goal target) { 
63        goal = target; 
64        processor.addObserver(this);
65    }
66
67
68    /** updates the processing state of this node */
69    public void updateProcessingState(ProcessingState state) {
70        processor.update(state);
71    }
72
73    /**
74     * This method should be polymorphic since children will have customized
75     * fields.
76     */
77    public void update(Observable obs, Object obj) {
78        if(obs == processor) {
79            setChanged();
80            notifyObservers(processor);
81        }
82    }
83
84    /** Polymorphic method for initializing a node based on its context */
85    public void init(NegotiationContext context) {
86        System.out.println("TTGNode: initialize context for " + getGoal());
87        if(context == null) {
88            System.out.println("WARNING NULL CONTEXT ENCOUNTERED!!!");
89        }
90        this.context = context;
91    }
92
93    /**
94     * A generic process method to determine whether to process this node
95     * as a verifier or an opponent.
96     * @param context The context of this trust negotiation
97     */
98    public void process(NegotiationContext context) {
99        Entity verifier = getGoal().getVerifier();
100        if(context.getSelf().equals(verifier)) {
101            // check verifier processed . . .
102            if(getProcessingState().isVerifierProcessed()) {
103                System.out.println("TTGNode: already verifier processed node "
104                                   + getGoal());
105                return;
106            }
107            verifierProcess(context);
108        }
109        // check opponent processed . . .
110        else {
111            if(getProcessingState().isOpponentProcessed()) {
112                System.out.println("TTGNode: already opponent processed node "
113                                   + getGoal());
114                return;
115            }
116            opponentProcess(context);       
117        }
118    }
119
120    /**
121     * Each distinct node type should know how to process itself, so this
122     * method should be overridden in subclasses.
123     * @param context A context w/helper functions required for processing
124     */
125    public abstract void verifierProcess(NegotiationContext context);
126
127    /**
128     * Each distinct node type should know how to process itself, so this
129     * method should be overridden in subclasses.
130     * @param context A context w/helper functions required for processing
131     */
132    public abstract void opponentProcess(NegotiationContext context);
133
134    /** Public accessor method for the negotiation context */
135    public NegotiationContext getContext() { return context; }
136
137    /** Accessor/modifier method for  the verifier of the trust target. */
138    public Entity getVerifier() { return goal.getVerifier(); }
139
140    /** Accessor/modifier method for the subject (RHS) of the trust target. */
141    public EntityExpression getSubject() { return goal.getSubject(); }
142
143    /** Accessor method for the processing state of this node */
144    public ProcessingState getProcessingState() { return processor; }
145
146    /** Accessor method for the goal/trust target  of this graph node */
147    public Goal getGoal() { return goal; }
148
149    /** Accessor method for the type of this TTG node */
150    public String getType() { return subName; }
151
152    /** Accessor/modifier method for the target role of the trust target. */
153    //public EntityExpression getTargetExpression() { return goal.getTargetRole();}
154
155    /** Adds a parent node to this instance */
156    public void addParent(TTGNode node) {
157        parents.add(node);
158    }
159
160    /** Adds a child node to this instance. */
161    public void addChild(TTGNode node) {
162        children.add(node);
163    }
164
165    /** accessor for a set of all the child nodes of the current instance */
166    public TTGNodeSet getChildren() { return children; }
167
168    /** accessor for a set of all the parent nodes of the current instance */
169    public TTGNodeSet getParents() { return parents; }
170
171    /** Print out a node in human readable format */
172    public String toString() {
173        StringBuffer buff = new StringBuffer("[");
174        buff.append(getClass().getName()).append(", ");
175        buff.append(processor).append(", ");
176        buff.append(getGoal().toString()).append("]");
177        return buff.toString();
178    }
179
180    /** Polymorphic method for converting a node into an XML string */
181    public abstract String toXML();
182
183    /** Method for children to use for creating a XML compatible string */
184    protected String toXML(String options, String elements) { 
185        StringBuffer buff = new StringBuffer("<");
186        buff.append(subName).append(options).append(">\n");
187        buff.append(getGoal().toXML());
188        buff.append(processor.toXML());
189        buff.append(elements);
190        buff.append("</").append(subName).append(">\n");
191        return buff.toString();
192    }
193
194    /** Friendly debuggin method to be inherited by all children */
195    protected void debug(String key, String message) {
196        StringBuffer buff = new StringBuffer(subName);
197        if(context != null)
198            buff.append("[").append(context.getSelf()).append("]");
199        buff.append(": ").append(message);
200        Debug.debug(key, buff.toString());
201    }
202
203
204}
205
206
207
208
209
210
211
212
213
214
Note: See TracBrowser for help on using the repository browser.