1 package dinamica.hessian; 2 3 import javax.sql.*; 4 import com.caucho.hessian.server.HessianServlet; 5 import dinamica.*; 6 import java.io.*; 7 import javax.servlet.ServletContext ; 8 9 22 public class BasicService extends HessianServlet 23 { 24 25 33 protected String getResource(String path) throws Throwable 34 { 35 36 StringBuffer buf = new StringBuffer (5000); 37 byte[] data = new byte[5000]; 38 39 InputStream in = null; 40 41 in = this.getClass().getResourceAsStream(path); 42 43 try 44 { 45 if (in!=null) 46 { 47 while (true) 48 { 49 int len = in.read(data); 50 if (len!=-1) 51 { 52 buf.append(new String (data,0,len)); 53 } 54 else 55 { 56 break; 57 } 58 } 59 return buf.toString(); 60 } 61 else 62 { 63 throw new Throwable ("Invalid path to resource: " + path); 64 } 65 66 } 67 catch (Throwable e) 68 { 69 throw e; 70 } 71 finally 72 { 73 if (in!=null) 74 { 75 try{ 76 in.close(); 77 } catch (Exception e){} 78 } 79 } 80 81 } 82 83 102 protected DataSource getDataSource(String name) throws Throwable 103 { 104 105 ServletContext ctx = getServletContext(); 107 String jndiPrefix = ctx.getInitParameter("jndi-prefix"); 108 109 if (jndiPrefix==null) 110 jndiPrefix=""; 111 112 DataSource ds = Jndi.getDataSource(jndiPrefix + name); 113 if (ds==null) 114 throw new Throwable ("Can't get datasource: " + name); 115 116 return ds; 117 118 } 119 120 138 protected DataSource getDataSource() throws Throwable 139 { 140 141 String jndiPrefix = null; 143 String name = null; 144 ServletContext ctx = getServletContext(); 145 146 name = ctx.getInitParameter("def-datasource"); 147 jndiPrefix = ctx.getInitParameter("jndi-prefix"); 148 149 if (jndiPrefix==null) 150 jndiPrefix=""; 151 152 DataSource ds = Jndi.getDataSource(jndiPrefix + name); 153 if (ds==null) 154 throw new Throwable ("Can't get datasource: " + name); 155 156 return ds; 157 158 } 159 160 } 161 | Popular Tags |