adds support for fields as well as local variables.
[cfb.git] / prod / net / jaekl / cfb / xml / LocalVariable.java
index fb198688068f58353ed80c3dd93bdbb65d4db1a1..1a590ae7df6cbaa9ca2a9eabc81bec4bdda5cbcd 100644 (file)
@@ -4,11 +4,12 @@ import java.io.PrintWriter;
 
 import org.xml.sax.Attributes;
 
+import net.jaekl.cfb.util.Util;
 import net.jaekl.qd.xml.MissingAttributeException;
 import net.jaekl.qd.xml.ParseResult;
 import net.jaekl.qd.xml.XmlParseException;
 
-public class LocalVariable extends ParseResult {
+public class LocalVariable extends ParseResult implements Variable {
 
        static final String TAG = "LocalVariable";
        static final String[] INTERNAL = { };
@@ -17,15 +18,43 @@ public class LocalVariable extends ParseResult {
        static final String NAME = "name";
        static final String ROLE = "role";
        
+       Long m_id;
        String m_name;
        String m_role;
        
        public LocalVariable() {
                super(TAG, INTERNAL, EXTERNAL);
                
+               m_id = null;
                m_name = m_role = null;
        }
        
+       public LocalVariable(Long id, String name, String role) {
+               super(TAG, INTERNAL, EXTERNAL);
+
+               m_id = id;
+               m_name = name;
+               m_role = role;
+       }
+       
+       public Long getId() { return m_id; }
+       
+       @Override
+       public String getDescription()
+       {
+               String result = getName();
+               if (null != getRole()) {
+                       result += " (" + getRole() + ")";
+               }
+               return result;
+       }
+       
+       @Override
+       public String getName() { return m_name; }
+       
+       @Override
+       public String getRole() { return m_role; }
+       
        @Override
        public void handleMainAttributes(Attributes attr)
                throws MissingAttributeException
@@ -56,4 +85,24 @@ public class LocalVariable extends ParseResult {
                pw.println(tab + NAME + "=" + m_name);
                pw.println(tab + ROLE + "=" + m_role);
        }
+       
+       @Override
+       public boolean equals(Object obj) 
+       {
+               if (null == obj) {
+                       return false;
+               }
+               if (obj instanceof LocalVariable) {
+                       LocalVariable that = (LocalVariable)obj;
+                       return (   Util.objsAreEqual(this.m_name, that.m_name) 
+                                   && Util.objsAreEqual(this.m_role, that.m_role) );
+               }
+               return false;
+       }
+       
+       @Override
+       public int hashCode()
+       {
+               return ( (Util.objHashCode(m_name)) ^ (Util.objHashCode(m_role)) );
+       }
 }