KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > web > talk > plugin > SessionSetupCDR


1 /*
2  * SessionCDR.java
3  *
4  * Created on June 29, 2002, 3:38 PM
5  */

6
7 package com.quikj.application.web.talk.plugin;
8
9 import java.net.*;
10 import java.sql.*;
11
12 /**
13  *
14  * @author amit
15  */

16 public class SessionSetupCDR implements CDRInterface
17 {
18     // database table name constant
19
private static final String JavaDoc SESSION_SETUP_CDR_TABLE_NAME = "cdr_session_setup_tbl";
20     
21     // database table column name constants
22
private static final String JavaDoc SESSION = "session";
23     private static final String JavaDoc CALLING = "calling";
24     private static final String JavaDoc CALLED = "called";
25     private static final String JavaDoc TRANSFER_ID = "transferid";
26     private static final String JavaDoc TIMESTAMP = "time_stamp";
27     
28     private String JavaDoc identifier;
29     private static String JavaDoc hostName = null;
30     private static int counter = 0;
31     private static Object JavaDoc counterLock = new Object JavaDoc();
32     
33     private java.util.Date JavaDoc timestamp;
34     private String JavaDoc calling;
35     private String JavaDoc called;
36     private String JavaDoc transferId;
37     
38     /** Creates a new instance of SessionCDR */
39     public SessionSetupCDR(String JavaDoc calling_id,
40     String JavaDoc called_id,
41     String JavaDoc transfer_id)
42     {
43         timestamp = new java.util.Date JavaDoc();
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 JavaDoc 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 JavaDoc(timestamp.getTime()));
80         return ps;
81     }
82     
83     public String JavaDoc generateXMLCDR()
84     {
85         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("<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 JavaDoc getIdentifier()
101     {
102         return identifier;
103     }
104 }
105
Popular Tags