
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class SimpleBean {

    private static final String DEFAULT_NAME = "Girish";
    private String name = null;
    private String address = null;
    private String type = null;
  

    public void setName(String name) {
        this.name = name;
    }
  public void setAddress(String address) {
        this.address = address;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void init() {
        System.out.println("Initializing bean");

        if (name == null) {
            System.out.println("Using default name");
            name = DEFAULT_NAME;
        }
        if (address == null) {
            System.out.println("Using default name");
            address = DEFAULT_NAME;
        }
        if (type == null) {
            System.out.println("Using default name");
            type = DEFAULT_NAME;
        }
       
    }

    public String toString() {
        return "Name: " + name + "\nAddress: " + address + "\nType: " + type ;
    }

    public static void main(String[] args) {
        BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
                "initMethod.xml"));

        SimpleBean simpleBean1 = getBean("simpleBean1", factory);
    }
    private static SimpleBean getBean(String beanName, BeanFactory factory) {
        try {
            SimpleBean bean = (SimpleBean) factory.getBean(beanName);
            System.out.println(bean);
            return bean;
        } catch (BeanCreationException ex) {
            System.out.println("An error occured in bean configuration: " + ex.getMessage());
            return null;
        }
    }
}
   