1 6 7 package com.quikj.application.web.talk.plugin; 8 9 import java.net.*; 10 import java.sql.*; 11 12 16 public class SessionSetupCDR implements CDRInterface 17 { 18 private static final String SESSION_SETUP_CDR_TABLE_NAME = "cdr_session_setup_tbl"; 20 21 private static final String SESSION = "session"; 23 private static final String CALLING = "calling"; 24 private static final String CALLED = "called"; 25 private static final String TRANSFER_ID = "transferid"; 26 private static final String TIMESTAMP = "time_stamp"; 27 28 private String identifier; 29 private static String hostName = null; 30 private static int counter = 0; 31 private static Object counterLock = new Object (); 32 33 private java.util.Date timestamp; 34 private String calling; 35 private String called; 36 private String transferId; 37 38 39 public SessionSetupCDR(String calling_id, 40 String called_id, 41 String transfer_id) 42 { 43 timestamp = new java.util.Date (); 44 calling = calling_id; 45 called = called_id; 46 transferId = transfer_id; 47 48 if (hostName == null) 49 { 50 try 51 { 52 hostName = InetAddress.getLocalHost().getHostName(); 53 } 54 catch (UnknownHostException ex) 55 { 56 hostName = "unknown"; 57 } 58 } 59 60 synchronized(counterLock) 61 { 62 identifier = hostName + ":session:" + timestamp.getTime() + 63 ":" + counter++ ; 64 } 65 } 66 67 public PreparedStatement generateSQLCDR() 68 throws SQLException 69 { 70 String sql = "insert into " 71 + SESSION_SETUP_CDR_TABLE_NAME 72 + " values (?, ?, ?, ?, ?)"; 73 74 PreparedStatement ps = CDRHandler.getInstance().getConnection().prepareStatement(sql); 75 ps.setString(1, identifier); 76 ps.setString(2, calling); 77 ps.setString(3, called); 78 ps.setString(4, transferId == null ? "" : transferId); 79 ps.setTimestamp(5, new java.sql.Timestamp (timestamp.getTime())); 80 return ps; 81 } 82 83 public String generateXMLCDR() 84 { 85 StringBuffer buffer = new StringBuffer ("<CDR type=\"session-setup\" session=\"" 86 + identifier 87 + "\" calling=\"" + calling 88 + "\" called=\"" + called + "\""); 89 90 if (transferId != null) 91 { 92 buffer.append(" transfer=\"" + transferId + "\""); 93 } 94 95 buffer.append(" time-stamp=\"" + timestamp.getTime() + "\"/>\n"); 96 97 return buffer.toString(); 98 } 99 100 public String getIdentifier() 101 { 102 return identifier; 103 } 104 } 105 | Popular Tags |