1 6 7 package com.sun.enterprise.config.backup.pluggable.impl; 8 9 import com.sun.enterprise.config.backup.pluggable.ActiveAssistance; 10 import com.sun.enterprise.config.backup.status.Status; 11 import com.sun.enterprise.config.backup.BackupAbortException; 12 import com.sun.enterprise.config.backup.BackupException; 13 14 import java.util.Properties ; 15 import java.io.InputStream ; 16 17 21 public class DefaultActiveAssistance implements ActiveAssistance { 22 23 private static final String DID_YOU_KNOW_PATH = 24 "/com/sun/enterprise/config/backup/pluggable/impl/didyouknow.properties"; 25 private static final String DIAGNOSABILITY_INFO_PATH = 26 "/com/sun/enterprise/config/backup/pluggable/impl/diagnosability.properties"; 27 28 29 public DefaultActiveAssistance() { 30 } 31 32 public String getDiagnosabilityInfo(Status s) { 33 if(s == null || s.isSuccess()) { 34 return null; 35 } 36 37 Exception e = s.getException(); 38 if (e == null) { 39 return null; 40 } else if (e instanceof BackupException) { 41 String code = ((BackupException)e).getCode(); 42 Properties p = getAllCodes(); 43 if(p == null) return null; 44 return (String )p.get(code); 45 } else if (e instanceof BackupAbortException) { 46 String code = ((BackupAbortException)e).getCode(); 47 Properties p = getAllCodes(); 48 if(p == null) return null; 49 return (String )p.get(code); 50 } else { 51 return null; 52 } 53 } 54 55 public String getDidYouKnow(Status status) { 56 Properties p = getAllDidYouKnow(); 57 if(p == null) return null; 58 long num = Math.round(Math.random() * p.size()); 59 return (String ) p.get("DYK" + num); 60 } 61 62 private Properties getAllDidYouKnow() { 63 try { 64 InputStream i = DefaultActiveAssistance.class. 65 getResourceAsStream(DID_YOU_KNOW_PATH ); 66 Properties p = new Properties (); 67 p.load(i); 68 return p; 69 } catch (Exception io) { 70 return null; 72 } 73 } 74 75 private Properties getAllCodes() { 76 try { 77 InputStream i = DefaultActiveAssistance.class. 78 getResourceAsStream(DIAGNOSABILITY_INFO_PATH ); 79 Properties p = new Properties (); 80 p.load(i); 81 return p; 82 } catch (Exception io) { 83 return null; 85 } 86 } 87 88 } 89 | Popular Tags |