| 1 package com.protomatter.j2ee.ejb; 2 3 52 53 import javax.ejb.*; 54 import javax.naming.*; 55 56 import java.sql.*; 57 import java.util.*; 58 import com.protomatter.util.*; 59 import com.protomatter.syslog.*; 60 61 64 public abstract class ProtoEJB 65 implements EnterpriseBean, SyslogChannelAware 66 { 67 private String [] channelList = null; 68 69 75 public final static String COMP_ENV_CHANNEL_LIST = "Syslog.channelList"; 76 77 80 public ProtoEJB() 81 { 82 super(); 83 } 84 85 90 public Object getSyslogChannel() 91 { 92 return this.channelList; 93 } 94 95 101 protected void setChannelList(String [] channelList) 102 { 103 this.channelList = channelList; 104 } 105 106 112 protected void setChannelList(List channelList) 113 { 114 Object olist[] = channelList.toArray(); 115 String list[] = new String [olist.length]; 116 for (int i=0; i<olist.length; i++) 117 { 118 list[i] = (String )olist[i]; 119 if (list[i].equals("DEFAULT_CHANNEL")) 120 list[i] = Syslog.DEFAULT_CHANNEL; 121 else if (list[i].equals("ALL_CHANNEL")) 122 list[i] = Syslog.ALL_CHANNEL; 123 } 124 setChannelList(list); 125 } 126 127 132 protected Context getComponentContext() 133 throws NamingException 134 { 135 Context ctx = new InitialContext(); 136 return (Context)ctx.lookup("java:comp/env"); 137 } 138 139 188 protected void initSyslogChannelList() 189 { 190 try 191 { 192 Context env = getComponentContext(); 193 String s = (String )env.lookup(COMP_ENV_CHANNEL_LIST); 194 s = (s == null) ? "" : s.trim(); 195 if (s.length() != 0) 196 { 197 StringTokenizer st = new StringTokenizer(s, ", "); 198 Vector list = new Vector(); 199 while (st.hasMoreTokens()) 200 list.add(st.nextToken()); 201 setChannelList(list); 202 } 203 else 204 { 205 setChannelList(new String [] { Syslog.DEFAULT_CHANNEL }); 206 } 207 } 208 catch (NamingException x) 209 { 210 setChannelList(new String [] { Syslog.DEFAULT_CHANNEL }); 211 } 212 } 213 214 220 protected boolean close(Connection c) 221 { 222 return DatabaseUtil.close(c, this); 223 } 224 225 231 protected boolean close(Statement s) 232 { 233 return DatabaseUtil.close(s, this); 234 } 235 236 242 protected boolean close(ResultSet r) 243 { 244 return DatabaseUtil.close(r, this); 245 } 246 } 247 | Popular Tags |