8043821844c89f0085292dae231058a6a5bce847
[cfb.git] / prod / net / jaekl / cfb / xml / LocalVariable.java
1 package net.jaekl.cfb.xml;
2
3 import java.io.PrintWriter;
4
5 import org.xml.sax.Attributes;
6
7 import net.jaekl.cfb.util.Util;
8 import net.jaekl.qd.xml.MissingAttributeException;
9 import net.jaekl.qd.xml.ParseResult;
10 import net.jaekl.qd.xml.XmlParseException;
11
12 public class LocalVariable extends ParseResult {
13
14         static final String TAG = "LocalVariable";
15         static final String[] INTERNAL = { };
16         static final Object[][] EXTERNAL = { };
17
18         static final String NAME = "name";
19         static final String ROLE = "role";
20         
21         Long m_id;
22         String m_name;
23         String m_role;
24         
25         public LocalVariable() {
26                 super(TAG, INTERNAL, EXTERNAL);
27                 
28                 m_id = null;
29                 m_name = m_role = null;
30         }
31         
32         public LocalVariable(Long id, String name, String role) {
33                 super(TAG, INTERNAL, EXTERNAL);
34
35                 m_id = id;
36                 m_name = name;
37                 m_role = role;
38         }
39         
40         public Long getId() { return m_id; }
41         public String getName() { return m_name; }
42         public String getRole() { return m_role; }
43         
44         @Override
45         public void handleMainAttributes(Attributes attr)
46                 throws MissingAttributeException
47         {
48                 m_name = getRequiredAttr(TAG, attr, NAME);
49                 m_role = getRequiredAttr(TAG, attr, ROLE);
50         }
51         
52         @Override
53         public void endContents(String uri, String localName, String qName, String chars) 
54                 throws XmlParseException 
55         {
56         }
57
58         @Override
59         public void endExternal(String uri, String localName, String qName)
60                 throws XmlParseException 
61         {
62                 // no-op
63         }
64         
65         @Override
66         public void dump(PrintWriter pw, int indent) 
67         {
68                 super.dump(pw, indent);
69                 String tab = String.format("%" + (indent + 2) + "s", "");
70                 
71                 pw.println(tab + NAME + "=" + m_name);
72                 pw.println(tab + ROLE + "=" + m_role);
73         }
74         
75         @Override
76         public boolean equals(Object obj) 
77         {
78                 if (null == obj) {
79                         return false;
80                 }
81                 if (obj instanceof LocalVariable) {
82                         LocalVariable that = (LocalVariable)obj;
83                         return (   Util.objsAreEqual(this.m_name, that.m_name) 
84                                     && Util.objsAreEqual(this.m_role, that.m_role) );
85                 }
86                 return false;
87         }
88         
89         @Override
90         public int hashCode()
91         {
92                 return ( (Util.objHashCode(m_name)) ^ (Util.objHashCode(m_role)) );
93         }
94 }