KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > pages > ConfigInfo


1 package org.ashkelon.pages;
2
3 import java.util.*;
4 import java.io.*;
5 import java.net.*;
6
7 import org.exolab.castor.mapping.*;
8 import org.exolab.castor.xml.*;
9 import org.ashkelon.*;
10
11 /**
12  * @author Eitan Suez
13  */

14 public class ConfigInfo
15 {
16    private Collection commandList;
17    private String JavaDoc defaultCmd;
18    private String JavaDoc defaultPkg;
19    private Map commandMap;
20    private int maxTrailLength;
21    private int traceLevel;
22    private String JavaDoc traceFile;
23    private String JavaDoc inlineTagResolver;
24    
25    public ConfigInfo() {}
26    
27    public ConfigInfo load() throws Exception JavaDoc
28    {
29       ClassLoader JavaDoc loader = this.getClass().getClassLoader();
30
31       URL resource = loader.getResource("org/ashkelon/pages/configmapping.xml");
32       Mapping mapping = new Mapping(loader);
33       mapping.loadMapping(resource);
34
35       InputStream is = loader.getResourceAsStream("org/ashkelon/pages/configinfo.xml");
36       Reader reader = new InputStreamReader(is);
37       Unmarshaller ums = new Unmarshaller(ConfigInfo.class);
38       ums.setMapping(mapping);
39       ConfigInfo info = (ConfigInfo) ums.unmarshal(reader);
40       
41       Map commandMap = new HashMap();
42       Iterator itr = info.getCommandList().iterator();
43       CommandInfo cmdinfo;
44       while (itr.hasNext())
45       {
46          cmdinfo = (CommandInfo) itr.next();
47          commandMap.put(cmdinfo.getCommand(), cmdinfo);
48       }
49       info.setCommandMap(commandMap);
50       return info;
51    }
52    
53    public String JavaDoc getDefaultCmd()
54    {
55       return defaultCmd;
56    }
57    public void setDefaultCmd(String JavaDoc defaultCmd)
58    {
59       this.defaultCmd = defaultCmd;
60    }
61    
62    public String JavaDoc getDefaultPkg()
63    {
64       return defaultPkg;
65    }
66    public void setDefaultPkg(String JavaDoc defaultPkg)
67    {
68       this.defaultPkg = defaultPkg;
69    }
70    
71    public Collection getCommandList()
72    {
73       return commandList;
74    }
75    public void setCommandList(Collection commandList)
76    {
77       this.commandList = commandList;
78    }
79    
80    public Map getCommandMap()
81    {
82       return commandMap;
83    }
84    public void setCommandMap(Map commandMap)
85    {
86       this.commandMap = commandMap;
87    }
88    
89    public int getMaxTrailLength() { return maxTrailLength; }
90    public void setMaxTrailLength(int length) { this.maxTrailLength = length; }
91    
92    public int getTraceLevel() { return traceLevel; }
93    public void setTraceLevel(int traceLevel) { this.traceLevel = traceLevel; }
94
95    public String JavaDoc getTraceFile() { return traceFile; }
96    public void setTraceFile(String JavaDoc traceFile) { this.traceFile = traceFile; }
97
98    public String JavaDoc getInlineTagResolver() { return inlineTagResolver; }
99    public void setInlineTagResolver(String JavaDoc resolver) { inlineTagResolver = resolver; }
100
101    private static InlineTagResolver _resolver = null;
102    private static ConfigInfo _cInfo = null;
103    public static InlineTagResolver getResolver()
104    {
105       if (_resolver == null)
106       {
107          try
108          {
109             _cInfo = new ConfigInfo().load();
110          }
111          catch (Exception JavaDoc ex)
112          {
113             System.err.println("Failed to load config info");
114             System.err.println(ex.getMessage());
115             System.exit(0);
116          }
117          
118          try
119          {
120             Class JavaDoc resolverClass = Class.forName(_cInfo.getInlineTagResolver());
121             _resolver = (InlineTagResolver) resolverClass.newInstance();
122          }
123          catch (ClassNotFoundException JavaDoc ex)
124          {
125             System.err.println("Failed to instantiate inline tag resolver class");
126             System.err.println("ClassNotFoundException: " + ex.getMessage());
127             System.exit(0);
128          }
129          catch (IllegalAccessException JavaDoc ex)
130          {
131             System.err.println("Failed to instantiate inline tag resolver class");
132             System.err.println("IllegalAccessException: " + ex.getMessage());
133             System.exit(0);
134          }
135          catch (InstantiationException JavaDoc ex)
136          {
137             System.err.println("Failed to instantiate inline tag resolver class");
138             System.err.println("InstantiationException: " + ex.getMessage());
139             System.exit(0);
140          }
141       }
142       return _resolver;
143    }
144
145    public static void main(String JavaDoc args[]) throws Exception JavaDoc
146    {
147       (new ConfigInfo()).load();
148    }
149 }
150
151
Popular Tags