1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package zeus.concepts;
25
26 import java.util.*;
27 import zeus.util.*;
28 import gnu.regexp.*;
29
30
31
32 /***
33 MessagePattern is used to set attribute value pairs for the MessageRule class:
34 you specify as string array like so {"attribite1","reg_exp expression for a1", "attribute2",
35 "reg_exp expression for a2", ...., "attribute<i>n</i>", "reg_exp expression for a<i>n</i>"}
36 */
37 public class MessagePatternImpl implements MessagePattern {
38 protected Hashtable constraints = new Hashtable();
39
40 public MessagePatternImpl() {
41 }
42
43
44 public MessagePatternImpl(String[] input) {
45 for(int i = 0; i < input.length; i += 2 )
46 setConstraint(input[i],input[i+1]);
47 }
48
49
50 public String[] listAttributes() {
51 String[] out = new String[constraints.size()];
52 Enumeration enum = constraints.keys();
53 for(int i = 0; enum.hasMoreElements(); i++ )
54 out[i] = (String)enum.nextElement();
55 return out;
56 }
57
58
59 public RE[] listValues() {
60 RE[] out = new RE[constraints.size()];
61 Enumeration enum = constraints.elements();
62 for(int i = 0; enum.hasMoreElements(); i++ )
63 out[i] = (RE)enum.nextElement();
64 return out;
65 }
66
67
68 public boolean setConstraint(String attribute, String regular_expr) {
69 try {
70 constraints.put(attribute, new RE(regular_expr,RE.REG_DOT_NEWLINE));
71 return true;
72 }
73 catch(REException rese) {
74 rese.printStackTrace();
75 return false;
76 }
77 }
78
79
80 public RE getConstraint(String attribute) {
81 return (RE)constraints.get(attribute);
82 }
83
84
85 public String toString() {
86 String s = "(";
87 RE regexp;
88 String key;
89 Enumeration enum = constraints.keys();
90 while( enum.hasMoreElements() ) {
91 key = (String)enum.nextElement();
92 regexp = (RE)constraints.get(key);
93 s += "(" + key + " " + regexp + ") ";
94 }
95 return s.trim() + ")";
96 }
97 }