package lava.net.psyc.packages; import java.util.Hashtable; import lava.net.common.UNL; import lava.net.common.Value; import lava.net.psyc.PSYCDeliveryException; import lava.net.psyc.PSYCMessageCenter; import lava.net.psyc.PSYCPackage; /** * **/ public class Biff extends Skeleton { /** * **/ public final static String PackageName = "Biff"; /** * **/ public final static String locationTag = "_mail_location"; /** * **/ private final static String[] locationAliases = {"mail_location"}; /** * **/ public final static String fromTag = "_origin"; /** * **/ private final static String[] fromAliases = {"origin"}; /** * **/ public final static String toTag = "_mail_to"; /** * **/ private final static String[] toAliases = {"mail_to"}; /** * **/ public final static String dateTag = "_mail_date"; /** * **/ private final static String[] dateAliases = {"mail_date"}; /** * **/ public final static String subjectTag = "_subject"; /** * **/ private final static String[] subjectAliases = {"subject"}; /** * **/ public final static String gotTag = "_notice_email_received"; /** * **/ private final static String[] gotAliases = {"notice_email_received"}; /** * **/ public final static String resetTag = "_notice_email_reset"; /** * **/ private final static String[] resetAliases = {"notice_email_reset"}; class DummyListener implements BiffListener { /** * **/ public void gotMail(UNL source, String location, String from, // String to, String date, String subject, String body) { } /** * **/ public void clearMail(UNL source, String body) { } } /** * **/ private BiffListener listener = new DummyListener(); /** * **/ private Hashtable tempVars = new Hashtable(); /** * **/ public String location = null; /** * **/ public Biff(BiffListener listener) { super(); setPackageName(PackageName); addPackageMethod(gotTag,gotAliases,true); addPackageMethod(resetTag,resetAliases,true); addPackageVariable(locationTag,locationAliases,false); addPackageVariable(fromTag,fromAliases,false); addPackageVariable(toTag,toAliases,false); addPackageVariable(dateTag,dateAliases,false); addPackageVariable(subjectTag,subjectAliases,false); if(listener != null) this.listener = listener; } /** * **/ public boolean understands() { return !(listener instanceof DummyListener); } /** * **/ public void received(UNL source, String method, String body) { // We'll ever get the method name we've registered, // even if a submethod were called if(gotTag.equals(method)) { Value v = center.getValue(source,locationTag); String location = v == null ? null : v.toString(); v = center.getValue(source,fromTag); String from = v == null ? null : v.toString(); v = center.getValue(source,toTag); String to = v == null ? null : v.toString(); v = center.getValue(source,dateTag); String date = v == null ? null : v.toString(); v = center.getValue(source,subjectTag); String subject = v == null ? null : v.toString(); listener.gotMail(source,location,from,to,date,subject,body); } else if(resetTag.equals(method)) listener.clearMail(source,body); } /** * **/ public void inform(UNL target, String location, String from, String to, // String date, String subject, String body) throws PSYCDeliveryException { tempVars.clear(); if(location != null) tempVars.put(locationTag,new Value(location)); if(from != null) tempVars.put(fromTag,new Value(from)); if(to != null) tempVars.put(toTag,new Value(to)); if(date != null) tempVars.put(dateTag,new Value(date)); if(subject != null) tempVars.put(subjectTag,new Value(subject)); center.sendChecked(target,PackageName,gotTag,body,tempVars); } /** * **/ public void inform(UNL target, String from, String to, String date, // String subject, String body) throws PSYCDeliveryException { inform(target,location,from,to,date,subject,body); } /** * **/ public void clear(UNL target, String body) throws PSYCDeliveryException { center.sendChecked(target,PackageName,resetTag,body); } /** * **/ public void clear(UNL target) throws PSYCDeliveryException { clear(target,null); } }