summaryrefslogtreecommitdiffstats
path: root/data/mnet/Common/Java/com/jetcell/MibWM/AlarmMessageMap.java
blob: 939f006e26f8ab702c282a2bc178fb4f2519940e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//////////////////////////////////////////////////////////////////////////////
//
//  Class  : AlarmMessageMap
//  Desc   : 
//  Author : George Zhao
//  Hist   : 06/17/1999 Initial Creation.
//
//////////////////////////////////////////////////////////////////////////////

package com.jetcell.MibWM;

import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.io.*;
import java.net.URL;
import Java.AlarmApplet;

abstract class AlarmMessageMap 
{
    static String file          = "Text/AlarmCode.English";
    static String Comments      = "//";
    static String delim         = "|";
    static Hashtable alarmTable = null;
    static final int SUBJECT    = 0;
    static final int MESSAGE    = 1;
    static final int VECTOR_SIZE= 2;
    static final int LENGTH     = 3;
    static boolean  readfile = false;
    
    static String[] ErrorCode = {
        "0|subect for alarm code 0| detail message for alarm code 0 wdsdsa fdsafdsafs adfdsa fdsafsad fsaf sadfdsaf sadfdsfsa fds dfsa asfa sfasf asdf sadfasfadf  sa fasf asfa dsaf asasfdsafa a afasdfdsaf dsafds afitsdfsfdsafsdfsafjksa;lkfjsalkfjsaf;lksajfsaklfsa;lkfasjfa;lksjfsadlkfjas;lkfjsfalksfjsa;lkfjsafkljdsfkldsafjdskfjflksajflksfj;safjas;lfjsafjsaklfsajflkdsafjsalkfah optional field %1",
        "1|subect for alarm code 1| detail message for alarm code 1 ddsfsdfsafsfaskf;lsjflsfskdl fjsalkfsaflksafwith optional field %1", 
        "2|subect for alarm code 2| detail message for alarm code 2 with optional field %1"
    };
    
    
    static Vector Get(long errorNo)
    {
        if (alarmTable == null)
        {
            Init();
        }
        
        Vector object = (Vector) alarmTable.get(new Long(errorNo));
        if (object == null)
        {
            object = new Vector();
            object.addElement(new String("No entry for data file for error code " +errorNo));
            object.addElement(new String("No entry for data file for error code " +errorNo));
        }
        return object;
    }
    
    static void Init()
    {        
        alarmTable = new Hashtable();
        URL cfg_url;
        
        try {
            if(Util.applet != null) {
							System.out.println("Running applet");            	
                    System.out.println("codebase : " + Util.applet.getCodeBase());
                    System.out.println("documentbase : " + Util.applet.getDocumentBase());
                    System.out.println("file : " + Util.applet.getCodeBase().getFile());    
                //BufferedReader in = new BufferedReader(new FileReader(new File(Util.applet.getDocumentBase().getFile(), file)));
                cfg_url = new URL(Util.applet.getCodeBase()+file);
                //cfg_url = new URL("http://"+ ((AlarmApplet)Util.applet).ip+"/"+file);
            }
            else {
            	System.out.println("Running application");
            	String sep = System.getProperty("file.separator");
            	String pwd = "file:"+".."+sep+"Text"+sep+"AlarmCode.English";
            	cfg_url = new URL(pwd);
				  }
            System.out.println("Open File: " +cfg_url);
            BufferedReader in = new BufferedReader(new InputStreamReader(cfg_url.openStream()));
            String line = null;
            while( (line = in.readLine()) != null)
	        {	
		        ProcessErrorCode(line);
		        readfile = true;
	        }
	    }
	    catch(FileNotFoundException e)
	    {
	        System.out.println(e.toString());
	        System.out.println("Cannot open alarm code file " + file);
	    }
	    catch(IOException ex)
	    {
	        System.out.println("IO Exception: " + ex.toString());
	    }
	    
	    if(!readfile)
	    {
	        for(int i=0; i< ErrorCode.length; i++)
	        {
	            ProcessErrorCode(ErrorCode[i]);
	        }
	    }
	}     
	
	static void ProcessErrorCode(String line)
	{
	    if(line.startsWith(Comments)) return;
    		    
		StringTokenizer token = new StringTokenizer(line, delim);
		if(token.countTokens() != LENGTH)
		{
		    return;
		}
		            		    
		Long errorNo = new Long(Util.trimSpaces(token.nextToken(delim)));
		Vector  alarmMsg = new Vector(VECTOR_SIZE);
		alarmMsg.insertElementAt(token.nextToken(delim), SUBJECT);
		alarmMsg.insertElementAt(token.nextToken(delim), MESSAGE);
		        
		alarmTable.put(errorNo, alarmMsg);
	}
		   
    static void dump()
    {
        if(Util.debug)
            for (Enumeration e = alarmTable.elements() ; e.hasMoreElements() ;) {
            System.out.println(e.nextElement()); 
            }
    } 
    
}
//$History:$