KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > pluggable > impl > DefaultActiveAssistance


1 /*
2  * DefaultActiveAssistance.java
3  *
4  * Created on December 25, 2003, 12:51 PM
5  */

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 JavaDoc;
15 import java.io.InputStream JavaDoc;
16
17 /**
18  *
19  * @author sridatta
20  */

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