短信上传
/* 联系人对象*/
public class ContactPerson {
private String personName;
private String mobileNumber;
private String email;
public void setMobileNumber(String mobileNumber) {
this.mobileNumber = mobileNumber;
}
public String getMobileNumber() {
return mobileNumber;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
}
/*联系人*/
public class Recipient {
private List<ContactPerson> contactPersonList=new ArrayList();
public void addContactPerson(ContactPerson contactPerson){
this.contactPersonList.add(contactPerson);
}
public Iterator<ContactPerson> iterator(){
return contactPersonList.iterator();
}
}
/*邮件发送接口*/
public interface SMTransport {
public abstract void sendMessage(ShortMessage shortmessage);
}
/*使用手机短信的方式发送消息*/
public class CellPhoneTransport implements SMTransport {
public void sendMessage(ShortMessage shortmessage)
{
Recipient recipient = shortmessage.getRecipient();
Iterator it = recipient.iterator();
while(it.hasNext())
{
ContactPerson cp = it.next();
System.out.println("向手机号为"+cp.getMobileNumber()+"的联系人发送信息,内容:"+shortmessage.getContent());
}
}
}
/*使用邮件的方式发送消息*/
public class MailTransport implements SMTransport {
public void sendEmail(ShortMessage shortmessage)
{
Recipient recipient = shortmessage.getRecipient ();
Iterator it = recipient.iterator();
while(it.next())
{
ContactPerson cp = (ContactPerson)it.next();
System.out.println("向邮件地址为"+cp.getEmail()+"的联系人发送信息,内容:"+shortmessage.getContent());
}
}
}
/* 短消息核心类*/
public class ShortMessage {
private String content;
private Recipient recipient;
private SMTransport smTransport;
public void setRecipient(Recipient recipient){
this.recipient = recipient;
}
public Recipient getRecipient(){
return this.recipient;
}
public void setContent(String content){
this.content = content;
}
public String getContent(){
return this.content;
}
public void addTransport(SMTransport smTransport){
this.smTransport = smTransport;
}
public void send(){
smTransport.sendMessage(this);
}
}