1 6 7 package com.quikj.application.web.talk.plugin; 8 9 import java.net.*; 10 import java.sql.*; 11 12 16 public class SessionTransferCDR implements CDRInterface 17 { 18 private static final String SESSION_TRANSFER_CDR_TABLE_NAME = "cdr_session_transfer_tbl"; 20 21 private static final String SESSION = "session"; 23 private static final String TRANSFER_TO = "transferto"; 24 private static final String IDENTIFIER = "identifier"; 25 private static final String TIMESTAMP = "time_stamp"; 26 27 private String session; 28 private String to; 29 private java.util.Date timestamp; 30 31 private String identifier; 32 private static String hostName = null; 33 private static int counter = 0; 34 private static Object counterLock = new Object (); 35 36 37 public SessionTransferCDR(String session, String to) 38 { 39 timestamp = new java.util.Date (); 40 this.session = session; 41 this.to = to; 42 43 if (hostName == null) 44 { 45 try 46 { 47 hostName = InetAddress.getLocalHost().getHostName(); 48 } 49 catch (UnknownHostException ex) 50 { 51 hostName = "unknown"; 52 } 53 } 54 55 synchronized(counterLock) 56 { 57 identifier = hostName + ":transfer:" + timestamp.getTime() + 58 ":" + counter++ ; 59 } 60 } 61 62 public PreparedStatement generateSQLCDR() 63 throws SQLException 64 { 65 String sql = "insert into " 66 + SESSION_TRANSFER_CDR_TABLE_NAME 67 + " values (?, ?, ?, ?)"; 68 69 PreparedStatement ps = CDRHandler.getInstance().getConnection().prepareStatement(sql); 70 ps.setString(1, session); 71 ps.setString(2, to); 72 ps.setString(3, identifier); 73 ps.setTimestamp(4, new java.sql.Timestamp (timestamp.getTime())); 74 return ps; 75 } 76 77 public String generateXMLCDR() 78 { 79 return "<CDR type=\"session-transfer\" session=\"" + session 80 + "\" to=\"" + to 81 + "\" transfer-id=\"" + identifier 82 + "\" time-stamp=\"" + timestamp.getTime() + "\"/>\n"; 83 } 84 85 public String getIdentifier() 86 { 87 return identifier; 88 } 89 } 90 | Popular Tags |