public void setDigest1(MessageDigest digest1) {
this.digest1 = digest1;
}
public void setDigest2(MessageDigest digest2) {
this.digest2 = digest2;
}
public void digest(String msg) {
System.out.println("Using digest1");
digest(msg, digest1);
System.out.println("Using digest2");
digest(msg, digest2);
}
private void digest(String msg, MessageDigest digest) {
System.out.println("Using alogrithm: " + digest.getAlgorithm());
digest.reset();
byte[] bytes = msg.getBytes();
byte[] out = digest.digest(bytes);
System.out.println(out);
}
}
Listing 5-21 shows a simple BeanFactory configuration that configures two
MessageDigestFactoryBeans, one for the SHA1 algorithm and the other using the default (MD5)
algorithm (factory/factory.xml).
Listing 5-21. Configuring FactoryBeans
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="shaDigest" class="com.apress.prospring3.ch5.factory.MessageDigestFactoryBean">
<property name="algorithmName">
<value>SHA1</value>
</property>
</bean>
<bean id="defaultDigest"
class="com.apress.prospring3.ch5.factory.MessageDigestFactoryBean"/>
<bean id="digester"
class="com.apress.prospring3.ch5.factory.MessageDigester">
<property name="digest1">
<ref local="shaDigest"/>
</property>
<property name="digest2">
<ref local="defaultDigest"/>
</property>
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home