// ** This file was generated with DemFGen (vers:12/15/2010)

package scg;

import edu.neu.ccs.demeterf.lib.*;
import java.lang.reflect.*;





/** Representation of Instance */
public class Instance{
    protected FullyQualifiedClassName instanceClassName;
    protected InstanceI instance;
    protected verbatim instanceSpec;

    /** Construct a(n) Instance Instance */
    public Instance(FullyQualifiedClassName instanceClassName, InstanceI instance, verbatim instanceSpec){
        this.instanceClassName = instanceClassName;
        this.instance = instance;
        this.instanceSpec = instanceSpec;
    }
    /** Is the given object Equal to this Instance? */
    public boolean equals(Object o){
        if(!(o instanceof Instance))return false;
        if(o == this)return true;
        Instance oo = (Instance)o;
        return (((Object)instanceClassName).equals(oo.instanceClassName))&&(((Object)instance).equals(oo.instance))&&(((Object)instanceSpec).equals(oo.instanceSpec));
    }
    /** Parse an instance of Instance from the given String */
    public static Instance parse(String inpt) throws scg.ParseException{
        return new scg.TheParser(new java.io.StringReader(inpt)).parse_Instance();
    }
    /** Parse an instance of Instance from the given Stream */
    public static Instance parse(java.io.InputStream inpt) throws scg.ParseException{
        return new scg.TheParser(inpt).parse_Instance();
    }
    /** Parse an instance of Instance from the given Reader */
    public static Instance parse(java.io.Reader inpt) throws scg.ParseException{
        return new scg.TheParser(inpt).parse_Instance();
    }

    /** Field Class for Instance.instanceClassName */
    public static class instanceClassName extends edu.neu.ccs.demeterf.Fields.any{}
    /** Field Class for Instance.instance */
    public static class instance extends edu.neu.ccs.demeterf.Fields.any{}
    /** Field Class for Instance.instanceSpec */
    public static class instanceSpec extends edu.neu.ccs.demeterf.Fields.any{}

	public void finishParse(){
		try{
			String className = getInstanceClassName().print().trim();
			Class<?> pgInstanceClass = Class.forName(className);
			Method parseMethod = pgInstanceClass.getMethod("parse", String.class);
			InstanceI instance = (InstanceI) parseMethod.invoke(null, getInstanceSpec().getText());
			setInstance(instance);
		} catch(Exception ex){
			ex.printStackTrace();
		}
	}

    /** DGP method from Class Print */
    public String print(){ return scg.Print.PrintM(this); }
    /** Setter for field Instance.instanceClassName */
    public void setInstanceClassName(FullyQualifiedClassName _instanceClassName){ instanceClassName = _instanceClassName; }
    /** Setter for field Instance.instance */
    public void setInstance(InstanceI _instance){ instance = _instance; }
    /** Setter for field Instance.instanceSpec */
    public void setInstanceSpec(verbatim _instanceSpec){ instanceSpec = _instanceSpec; }
    /** Getter for field Instance.instanceClassName */
    public FullyQualifiedClassName getInstanceClassName(){ return instanceClassName; }
    /** Getter for field Instance.instance */
    public InstanceI getInstance(){ return instance; }
    /** Getter for field Instance.instanceSpec */
    public verbatim getInstanceSpec(){ return instanceSpec; }

}


