Spring Java

/*
Pro Spring
By Rob Harrop
Jan Machacek
ISBN: 1-59059-461-4
Publisher: Apress
*/
//spring.xml


    
        
            SHA1
        
    

//////////////////////////////////////////////////////////////////////////////
import java.security.MessageDigest;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
public class MessageDigestFactoryBean implements FactoryBean, InitializingBean {
    private String algorithmName = "MD5";
    
    private MessageDigest messageDigest = null;
    public Object getObject() throws Exception {
       return messageDigest;
    }
    public Class getObjectType() {
       return MessageDigest.class;
    }
    public boolean isSingleton() {
       return true;
    }
    public void afterPropertiesSet() throws Exception {
        messageDigest = MessageDigest.getInstance(algorithmName);
    }
    
    public void setAlgorithmName(String algorithmName) {
        this.algorithmName = algorithmName;
    }
}
//////////////////////////////////////////////////////////////////////////////
import java.security.MessageDigest;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class AccessingFactoryBeans {
    public static void main(String[] args) {
        BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
                "build/spring.xml"));
        MessageDigest digest = (MessageDigest) factory
                .getBean("messageDigest");
       
        
        MessageDigestFactoryBean factoryBean = (MessageDigestFactoryBean) factory
                .getBean("&messageDigest");
    }
}
           
       
AccessingFactoryBeans.zip( 1,197 k)