View Javadoc

1   package zeus.concepts;
2   
3   import java.util.*;
4   
5   import zeus.util.*;
6   import zeus.concepts.fn.*;
7   
8   public class FactDescription {
9     protected String name = null;
10    protected OrderedHashtable attributes = null;
11  
12    public FactDescription(String name) {
13      this.name = name;
14      this.attributes = new OrderedHashtable();
15    }
16  
17    public FactDescription(FactDescription desc) {
18      this.name = desc.getName();
19      this.attributes = new OrderedHashtable();
20      String[][] attributes = desc.getAttributes();
21      for(int i = 0; i < attributes.length; i++ )
22         setAttributeEntry(attributes[i]);
23    }
24  
25    public String getName()       { return name; }
26    public int    numAttributes() { return attributes.size(); }
27  
28    public void setName(String name) {
29       Assert.notNull(name);
30       this.name = name;
31    }
32  
33    public String[][] getAttributes() {
34       String[][] data = new String[attributes.size()][4];
35       String[] entry;
36       Enumeration elements = attributes.elements();
37       for(int i = 0; elements.hasMoreElements(); i++ ) {
38          entry = (String[])elements.nextElement();
39          data[i][0] = entry[0];
40          data[i][1] = entry[1];
41          data[i][2] = entry[2];
42          data[i][3] = entry[3];
43       }
44       return data;
45    }
46    public void add(String aName, String type,
47                    String restriction, String defaultValue) {
48  
49       Assert.notFalse( !attributes.containsKey(aName) );
50       String[] entry = new String[4];
51       entry[0] = aName;
52       entry[1] = type;
53       entry[2] = type;
54       entry[3] = type;
55       attributes.put(aName,entry);
56    }
57  
58    public String[] getAttributeEntry(String aName) {
59       String[] data = new String[4];
60       String[] entry = (String[])attributes.get(aName);
61       for(int i = 0; i < entry.length; i++ )
62          data[i] = entry[i];
63       return data;
64    }
65  
66    public String[] removeAttributeEntry(String aName) {
67       return (String[])attributes.remove(aName);
68    }
69  
70    public void setAttributeEntry(String[] entry) {
71       attributes.put(entry[0],entry);
72    }
73  
74    public boolean containsAttribute(String aName) {
75      return attributes.containsKey(aName);
76    }
77    public String toString() {
78       return name;
79    }
80  }