adds support for fields as well as local variables.
[cfb.git] / prod / net / jaekl / cfb / xml / Field.java
diff --git a/prod/net/jaekl/cfb/xml/Field.java b/prod/net/jaekl/cfb/xml/Field.java
new file mode 100644 (file)
index 0000000..0beedbc
--- /dev/null
@@ -0,0 +1,122 @@
+package net.jaekl.cfb.xml;
+
+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 Field extends ParseResult implements Variable {
+       static final String TAG = "Field";
+       static final String[] INTERNAL = { };
+       static final Object[][] EXTERNAL = { };
+
+       static final String CLASSNAME = "classname";
+       static final String FIELD = "FIELD";
+       static final String IS_STATIC = "isStatic";
+       static final String NAME = "name";
+       static final String SIGNATURE = "signature";
+       
+       String m_className;
+       String m_name;
+       String m_signature;
+       boolean m_isStatic;
+       
+       public Field() {
+               super(TAG, INTERNAL, EXTERNAL);
+               
+               m_className = m_name = m_signature = null;
+               m_isStatic = false;
+       }
+       
+       public String getClassName() { return m_className; }
+       public String getSignature() { return m_signature; }
+       public boolean isStatic() { return m_isStatic; }
+       
+       @Override
+       public String getDescription() 
+       {
+               String result = "";
+               if (isStatic()) {
+                       result += "static ";
+               }
+               if (null != getClassName()) {
+                       result += getClassName() + ".";
+               }
+               result += getName();
+               return result;
+       }
+       
+       @Override
+       public String getName() { return m_name; }
+       
+       @Override
+       public String getRole() { return FIELD; }
+
+       @Override
+       public void handleMainAttributes(Attributes attr)
+               throws MissingAttributeException
+       {
+               m_className = getRequiredAttr(TAG, attr, CLASSNAME);
+               
+               String isStaticStr = getRequiredAttr(TAG, attr, CLASSNAME);
+               m_isStatic = "true".equals(isStaticStr);
+               
+               m_name = getRequiredAttr(TAG, attr, NAME);
+               
+               m_signature = getRequiredAttr(TAG, attr, SIGNATURE);
+       }
+       
+       @Override
+       public void endContents(String uri, String localName, String qName, String chars) 
+               throws XmlParseException 
+       {
+       }
+
+       @Override
+       public void endExternal(String uri, String localName, String qName)
+               throws XmlParseException 
+       {
+               // no-op
+       }
+       
+       @Override
+       public void dump(PrintWriter pw, int indent) 
+       {
+               super.dump(pw, indent);
+               String tab = String.format("%" + (indent + 2) + "s", "");
+
+               pw.println(tab + CLASSNAME + "=" + m_className);
+               pw.println(tab + IS_STATIC + "=" + (m_isStatic ? "true" : "false"));
+               pw.println(tab + NAME + "=" + m_name);
+               pw.println(tab + SIGNATURE + "=" + m_signature);
+       }
+       
+       @Override
+       public boolean equals(Object obj) 
+       {
+               if (null == obj) {
+                       return false;
+               }
+               if (obj instanceof Field) {
+                       Field that = (Field)obj;
+                       return (   Util.objsAreEqual(this.m_className, that.m_className)
+                                       && (this.m_isStatic == that.m_isStatic)
+                                   && Util.objsAreEqual(this.m_name, that.m_name)
+                                   && Util.objsAreEqual(this.m_signature, that.m_signature) );
+               }
+               return false;
+       }
+       
+       @Override
+       public int hashCode()
+       {
+               return (  (Util.objHashCode(m_className))
+                               ^ (Boolean.valueOf(m_isStatic).hashCode())
+                               ^ (Util.objHashCode(m_name)) 
+                               ^ (Util.objHashCode(m_signature)) );
+       }
+}